diff options
| author | Étienne Loks <etienne.loks@proxience.com> | 2015-02-16 02:51:17 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@proxience.com> | 2015-05-06 15:48:16 +0200 | 
| commit | 1b6ea1c1a10b10351351f061b050626a231b128d (patch) | |
| tree | 0d85b96184792c1bacb4170a3e4fceb5f511cf93 | |
| parent | 1f1545be8ef13050094e8240f3bffc7c985a76e7 (diff) | |
| download | Ishtar-1b6ea1c1a10b10351351f061b050626a231b128d.tar.bz2 Ishtar-1b6ea1c1a10b10351351f061b050626a231b128d.zip | |
SRA PdL files: raw field for organization (refs #2279)
| -rw-r--r-- | archaeological_files/models.py | 5 | ||||
| -rw-r--r-- | archaeological_files_pdl/forms.py | 85 | ||||
| -rw-r--r-- | archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html | 38 | ||||
| -rw-r--r-- | archaeological_files_pdl/templates/ishtar/wizard/wizard_person_orga.html | 66 | ||||
| -rw-r--r-- | archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html | 15 | ||||
| -rw-r--r-- | archaeological_files_pdl/wizards.py | 5 | ||||
| -rw-r--r-- | ishtar_common/forms.py | 2 | ||||
| -rw-r--r-- | ishtar_pdl/static/pdl/JQueryCorporation.js | 14 | 
8 files changed, 163 insertions, 67 deletions
| diff --git a/archaeological_files/models.py b/archaeological_files/models.py index a12d48062..5f402b9f1 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -83,11 +83,16 @@ class File(BaseHistorizedItem, OwnPerms, ValueGetter, ShortMenuItem,                 related_name='general_contractor',                 verbose_name=_(u"General contractor"), blank=True, null=True,                 on_delete=models.SET_NULL,) # aménageur +    raw_general_contractor = models.CharField(_(u"General contractor (raw)"), +                                        max_length=200, blank=True, null=True)      responsible_town_planning_service = models.ForeignKey(Person,                 related_name='responsible_town_planning_service',                 blank=True, null=True,                 verbose_name=_(u"Responsible for town planning service"),                 on_delete=models.SET_NULL,) # service instructeur +    raw_town_planning_service = models.CharField( +                        _(u"Town planning service (raw)"), max_length=200, +                        blank=True, null=True)      permit_type = models.ForeignKey(PermitType, verbose_name=_(u"Permit type"),                                                            blank=True, null=True)      permit_reference = models.CharField(_(u"Permit reference"), diff --git a/archaeological_files_pdl/forms.py b/archaeological_files_pdl/forms.py index 824254d37..cd25ff099 100644 --- a/archaeological_files_pdl/forms.py +++ b/archaeological_files_pdl/forms.py @@ -107,9 +107,15 @@ class FileFormResearchAddress(forms.Form):      postal_code = forms.CharField(label=_(u"Postal code"), max_length=10,                                    required=False) -class FileFormGeneralContractor(forms.Form): -    form_label = _(u"General contractor") -    associated_models = {'general_contractor':models.Person} +class PersonOrgaForm(forms.Form): +    PERSON_FIELD = 'TO BE DEFINED' +    ORGA_FIELD = 'TO BE DEFINED' +    PERSON_TYPE = GENERAL_CONTRACTOR + +    def _media(self): +        if self.status == 'corporation': +            return forms.Media(js=('pdl/JQueryCorporation.js',)) +    media = property(_media)      def __init__(self, *args, **kwargs): @@ -118,15 +124,18 @@ class FileFormGeneralContractor(forms.Form):          current_status = ''          if 'data' in kwargs:              current_item_key = ((kwargs['prefix'] + '-') if kwargs.get('prefix')\ -                                                 else '') + 'general_contractor' +                                                 else '') + self.PERSON_FIELD              if kwargs['data'] and kwargs['data'].get(current_item_key): -                model = self.associated_models['general_contractor'] +                model = self.associated_models[self.PERSON_FIELD]                  try:                      item = model.objects.get(pk=kwargs['data'][current_item_key]) -                    current_status = 'natural' if item.is_natural() \ -                                     else 'corporation' +                    current_status = 'natural'                  except (model.DoesNotExist, ValueError):                      pass +            current_item_key = ((kwargs['prefix'] + '-') if kwargs.get('prefix')\ +                                         else '') + self.ORGA_FIELD +            if kwargs['data'] and kwargs['data'].get(current_item_key): +                current_status = 'corporation'          status = ''          if 'status' in kwargs: @@ -140,58 +149,58 @@ class FileFormGeneralContractor(forms.Form):          else:              status = DEFAULT_STATUS +        self.status = status +          if status not in ('natural', 'corporation'):              status = DEFAULT_STATUS -        super(FileFormGeneralContractor, self).__init__(*args, **kwargs) +        super(PersonOrgaForm, self).__init__(*args, **kwargs)          # distinct widget for natural and corporation          if status == 'natural': -            self.fields['general_contractor'] = forms.IntegerField( -             label=_(u"General contractor"), +            self.fields[self.PERSON_FIELD] = forms.IntegerField( +             label=self.fields[self.ORGA_FIELD].label, +             required=False,               widget=widgets.JQueryPersonOrganization(                  reverse_lazy('autocomplete-person', -                             args=[GENERAL_CONTRACTOR.pk]), +                             args=[self.PERSON_TYPE.pk]),                  reverse_lazy('person_create'),                  model=Person, -                limit={'person_types':[GENERAL_CONTRACTOR.pk], +                limit={'person_types':[self.PERSON_TYPE.pk],                         'attached_to__isnull':True},                  js_template='ishtar/blocks/JQueryNaturalPerson.js',                  new=True),               validators=[valid_id(Person)]) -        else: -            self.fields['general_contractor'] = forms.IntegerField( -             label=_(u"General contractor"), -             widget=widgets.JQueryPersonOrganization( -                reverse_lazy('autocomplete-person', -                             args=[GENERAL_CONTRACTOR.pk]), -                reverse_lazy('organization_person_create'), -                model=Person, -                limit={'person_types':[GENERAL_CONTRACTOR.pk]}, -                js_template='ishtar/blocks/JQueryCorporationPerson.js', -                new=True), -             validators=[valid_id(Person)]) -class FileFormPlanningService(forms.Form): +class FileFormGeneralContractor(PersonOrgaForm): +    form_label = _(u"General contractor") +    associated_models = {'general_contractor':models.Person} +    raw_general_contractor = forms.CharField(label=_(u"General contractor"), +                                            required=False, max_length=200) +    PERSON_FIELD = 'general_contractor' +    ORGA_FIELD = 'raw_general_contractor' +    PERSON_TYPE = GENERAL_CONTRACTOR + +class FileFormPlanningService(PersonOrgaForm):      form_label = _(u"Town planning service")      associated_models = {'responsible_town_planning_service':models.Person} +      reference_number = forms.IntegerField(label=_(u"File reference"),                                            required=False) +    raw_town_planning_service = forms.CharField( +            label=_(u"Responsible town planning service"), required=False, +            max_length=200) +    PERSON_FIELD = 'responsible_town_planning_service' +    ORGA_FIELD = 'raw_town_planning_service' +    PERSON_TYPE = RESPONSIBLE_PLANNING_SERVICE      def __init__(self, *args, **kwargs):          super(FileFormPlanningService, self).__init__(*args, **kwargs) -        self.fields['responsible_town_planning_service'] = forms.IntegerField( -            label=_(u"Responsible town planning service"), -            widget=widgets.JQueryPersonOrganization( -                reverse_lazy('autocomplete-person', -                             args=[RESPONSIBLE_PLANNING_SERVICE.pk]), -                reverse_lazy('townplanning_create'), -                model=Person, -                limit={'person_types':[RESPONSIBLE_PLANNING_SERVICE.pk]}, -                js_template='ishtar/blocks/JQueryCorporationPerson.js', -                new=True), -            validators=[valid_id(Person)]) -        self.fields.keyOrder = ['responsible_town_planning_service', -                                'reference_number'] +        self.fields.keyOrder = [] +        if self.ORGA_FIELD in self.fields: +            self.fields.keyOrder.append(self.ORGA_FIELD) +        elif self.PERSON_FIELD in self.fields: +            self.fields.keyOrder.append(self.PERSON_FIELD) +        self.fields.keyOrder.append('reference_number')  class FileFormInstruction(forms.Form):      form_label = u"Instruction SRA" diff --git a/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html index 34dc75b08..e43e336c4 100644 --- a/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html +++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html @@ -1,31 +1,15 @@ -{% extends "ishtar/wizard/default_wizard.html" %} -{% load i18n range table_form %} -{% block wizard_form %} -<form action="." method="post" name='wizard'{% if wizard.form.file_upload %} enctype="multipart/form-data"{% endif %}>{% csrf_token %} -<div class='form'> -{{ wizard.form.media }} -{{ wizard.management_form }} +{% extends "ishtar/wizard/wizard_person_orga.html" %} -<table class='formset'> -  <caption>Statut</caption> -  <tr> -    <th><label>{% trans "Corporation" %}</label></th> -    <td><input type='radio' name='person_type' value='corporation'/></td> +{% block corporation %} +  <tr class='required'> +    <th>{{ wizard.form.raw_general_contractor.label_tag }}</th> +    <td> {{ wizard.form.raw_general_contractor.errors }}{{wizard.form.raw_general_contractor|safe}}</td>    </tr> -  <tr> -    <th><label>{% trans "Natural person" %}</label></th> -    <td><input type='radio' name='person_type' value='natural'/></td> -  </tr> -</table> - -<table> -{% table_form wizard.form %} -</table> -<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" /> -{{ previous_fields|safe }} -{% block "validation_bar" %} -{% include 'ishtar/wizard/validation_bar.html' %}  {% endblock %} -</div> -</form> + +{% block natural %} +  <tr class='required'> +    <th>{{ wizard.form.general_contractor.label_tag }}</th> +    <td> {{ wizard.form.general_contractor.errors }}{{wizard.form.general_contractor|safe}}</td> +  </tr>  {% endblock %} diff --git a/archaeological_files_pdl/templates/ishtar/wizard/wizard_person_orga.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_person_orga.html new file mode 100644 index 000000000..91dd7e042 --- /dev/null +++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_person_orga.html @@ -0,0 +1,66 @@ +{% extends "ishtar/wizard/default_wizard.html" %} +{% load i18n range table_form %} +{% block wizard_form %} +<script type='text/javascript'> +function update_form(){ +    if ($('input[name="person_type"]:radio:checked').val() == 'corporation'){ +        $('#natural_div').hide(); +        $('#corporation_div').show(); +    } else { +        $('#natural_div').show(); +        $('#corporation_div').hide(); +    } +} +$(function() { +    update_form(); +}); +</script> +<form action="." method="post" name='wizard'{% if wizard.form.file_upload %} enctype="multipart/form-data"{% endif %}>{% csrf_token %} +<div class='form'> +{% if wizard.form.media %}{{ wizard.form.media }}{% endif %} +{{ wizard.management_form }} + +<table class='formset'> +  <caption>Statut</caption> +  <tr> +    <th><label>{% trans "Corporation" %}</label></th> +    <td><input type='radio' name='person_type' value='corporation'/></td> +  </tr> +  <tr> +    <th><label>{% trans "Natural person" %}</label></th> +    <td><input type='radio' name='person_type' value='natural'/></td> +  </tr> +</table> + +<table id='corporation_div'> +  {% if wizard.form.non_field_errors %}<tr class='errors'> +    <td colspan='3'>{{wizard.form.non_field_errors}}</td> +  </tr>{%endif%} + +{% block corporation %} +{% endblock %} +</table> + +<div id='natural_div'> +<table> +  {% if wizard.form.non_field_errors %}<tr class='errors'> +    <td colspan='3'>{{wizard.form.non_field_errors}}</td> +  </tr>{%endif%} + +{% block natural %} +{% endblock %} +</table> +</div> + +{% block otherfields %} +{% endblock %} + +<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" /> +{{ previous_fields|safe }} +{% block "validation_bar" %} +{% include 'ishtar/wizard/validation_bar.html' %} +{% endblock %} +</div> +</form> +{% endblock %} + diff --git a/archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html new file mode 100644 index 000000000..29bc2397c --- /dev/null +++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html @@ -0,0 +1,15 @@ +{% extends "ishtar/wizard/wizard_person_orga.html" %} + +{% block corporation %} +  <tr class='required'> +    <th>{{ wizard.form.raw_town_planning_service.label_tag }}</th> +    <td> {{ wizard.form.raw_town_planning_service.errors }}{{wizard.form.raw_town_planning_service|safe}}</td> +  </tr> +{% endblock %} + +{% block natural %} +  <tr class='required'> +    <th>{{ wizard.form.responsible_town_planning_service.label_tag }}</th> +    <td> {{ wizard.form.responsible_town_planning_service.errors }}{{wizard.form.responsible_town_planning_service|safe}}</td> +  </tr> +{% endblock %} diff --git a/archaeological_files_pdl/wizards.py b/archaeological_files_pdl/wizards.py index 0a4ace7c8..3b0eb1635 100644 --- a/archaeological_files_pdl/wizards.py +++ b/archaeological_files_pdl/wizards.py @@ -27,6 +27,8 @@ class FileWizard(BaseFileWizard):      wizard_templates = {          'generalcontractor-%(url_name)s':\                      'ishtar/wizard/wizard_generalcontractor.html', +        'planningservice-%(url_name)s':\ +                    'ishtar/wizard/wizard_planningservice.html',          'instruction-%(url_name)s':\                      'ishtar/wizard/wizard_instruction.html',          'preventiveplanning-%(url_name)s':\ @@ -39,7 +41,8 @@ class FileWizard(BaseFileWizard):      def get_form_kwargs(self, *args, **kwargs):          returned = super(FileWizard, self).get_form_kwargs(*args, **kwargs) -        if args and args[0].startswith('generalcontractor-'): +        if args and (args[0].startswith('generalcontractor-') or  +                     args[0].startswith('planningservice-')):              if 'status' in self.request.GET:                  returned['status'] = self.request.GET['status']          if args and args[0].startswith('instruction-'): diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 88a3306f4..e6f21ae5b 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -*- coding: utf-8 -*- -# Copyright (C) 2010-2014 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2010-2015 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet>  # This program is free software: you can redistribute it and/or modify  # it under the terms of the GNU Affero General Public License as diff --git a/ishtar_pdl/static/pdl/JQueryCorporation.js b/ishtar_pdl/static/pdl/JQueryCorporation.js new file mode 100644 index 000000000..e65001506 --- /dev/null +++ b/ishtar_pdl/static/pdl/JQueryCorporation.js @@ -0,0 +1,14 @@ +var current_status = 'corporation'; + +$(function() { +    var $radios = $('input:radio[name=person_type]'); +    if($radios.is(':checked') === false) { +        $radios.filter('[value='+ current_status +']').prop('checked', true); +    } + +    $radios.change(function(){ +        var loc = window.location; +        window.location = loc.protocol + '//' + loc.host + loc.pathname + "?status=" + $('input:radio[name=person_type]:checked').val(); +    }); +    $("#corporation_div").show(); +}); | 
