diff options
Diffstat (limited to 'archaeological_files_pdl')
5 files changed, 143 insertions, 66 deletions
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-'): |