diff options
Diffstat (limited to 'archaeological_files_pdl')
13 files changed, 818 insertions, 20 deletions
diff --git a/archaeological_files_pdl/forms.py b/archaeological_files_pdl/forms.py index 87221f24c..53d473b96 100644 --- a/archaeological_files_pdl/forms.py +++ b/archaeological_files_pdl/forms.py @@ -21,20 +21,22 @@ import datetime from django import forms from django.core import validators +from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ -from ishtar_common.models import Person +from ishtar_common.models import Person, PersonType, valid_id from archaeological_files import models -from ishtar_common.forms import get_now +from ishtar_common.forms import get_now, reverse_lazy +from ishtar_common.forms_common import get_advanced_town_field +from archaeological_files.forms import GENERAL_CONTRACTOR, \ + RESPONSIBLE_PLANNING_SERVICE from ishtar_common import widgets class FileFormGeneral(forms.Form): form_label = _("General") - associated_models = {'in_charge':Person, - 'related_file':models.File, - 'file_type':models.FileType} + associated_models = {'file_type':models.FileType} file_type = forms.ChoiceField(label=_("File type"), choices=[]) year = forms.IntegerField(label=_("Year"), initial=lambda:datetime.datetime.now().year, @@ -43,9 +45,203 @@ class FileFormGeneral(forms.Form): creation_date = forms.DateField(label=_(u"Creation date"), initial=get_now, widget=widgets.JQueryDate) reception_date = forms.DateField(label=_(u"Reception date"), - initial=get_now, widget=widgets.JQueryDate) + widget=widgets.JQueryDate) def __init__(self, *args, **kwargs): super(FileFormGeneral, self).__init__(*args, **kwargs) self.fields['file_type'].choices = models.FileType.get_types() self.fields['file_type'].help_text = models.FileType.get_help() + +class FileFormPreventiveType(forms.Form): + form_label = u"Saisine" + associated_models = {'saisine_type':models.SaisineType, + 'permit_type':models.PermitType} + permit_type = forms.ChoiceField(label=_(u"Permit type"), required=False, + choices=[]) + saisine_type = forms.ChoiceField(label=_(u"Saisine type"), + choices=[]) + def __init__(self, *args, **kwargs): + super(FileFormPreventiveType, self).__init__(*args, **kwargs) + self.fields['saisine_type'].choices = models.SaisineType.get_types() + self.fields['saisine_type'].help_text = models.SaisineType.get_help() + self.fields['permit_type'].choices = models.PermitType.get_types( + default='NP') + self.fields['permit_type'].help_text = models.PermitType.get_help() + +class FileFormPlanning(forms.Form): + form_label = _(u"Planning") + associated_models = {'main_town':models.Town} + name = forms.CharField(label=_(u"Planning name"), required=False, + max_length=100) + main_town = get_advanced_town_field(required=True) + locality = forms.CharField(label=_(u"Locality"), max_length=100, + required=False) + address = forms.CharField(label=_(u"Address (number/street)"), + widget=forms.Textarea( + attrs={"placeholder":_(u"Number/street")}), + required=False, + ) + postal_code = forms.CharField(label=_(u"Postal code"), max_length=10, + required=False) + total_surface = forms.IntegerField(required=False, + widget=widgets.AreaWidget, + label=_(u"Total surface (m²)"), + validators=[validators.MinValueValidator(0), + validators.MaxValueValidator(999999999)]) + total_developed_surface = forms.IntegerField(widget=widgets.AreaWidget, + label=_(u"Total developed surface (m²)"), + required=False, validators=[validators.MinValueValidator(0), + validators.MaxValueValidator(999999999)]) + +class FileFormResearchAddress(forms.Form): + form_label = _(u"Address") + associated_models = {'main_town':models.Town} + main_town = get_advanced_town_field(required=True) + locality = forms.CharField(label=_(u"Locality"), max_length=100, + required=False) + address = forms.CharField(label=_(u"Address (number/street)"), + widget=forms.Textarea( + attrs={"placeholder":_(u"Number/street")}), + required=False, + ) + postal_code = forms.CharField(label=_(u"Postal code"), max_length=10, + required=False) + +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): + + # get the status: natural person or corporation + DEFAULT_STATUS = 'natural' + current_status = '' + if 'data' in kwargs: + current_item_key = ((kwargs['prefix'] + '-') if kwargs.get('prefix')\ + else '') + self.PERSON_FIELD + if kwargs['data'] and kwargs['data'].get(current_item_key): + model = self.associated_models[self.PERSON_FIELD] + try: + item = model.objects.get(pk=kwargs['data'][current_item_key]) + 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: + status = kwargs.pop('status') + if current_status != status: + if kwargs.get('data'): + # status is different from the existing - clear fields + kwargs.pop('data') + elif current_status: + status = current_status + else: + status = DEFAULT_STATUS + + self.status = status + + if status not in ('natural', 'corporation'): + status = DEFAULT_STATUS + super(PersonOrgaForm, self).__init__(*args, **kwargs) + + # distinct widget for natural and corporation + if status == 'natural': + self.fields[self.PERSON_FIELD] = forms.IntegerField( + label=self.fields[self.ORGA_FIELD].label, + required=False, + widget=widgets.JQueryPersonOrganization( + reverse_lazy('autocomplete-person', + args=[self.PERSON_TYPE.pk]), + reverse_lazy('person_create'), + model=Person, + limit={'person_types':[self.PERSON_TYPE.pk], + 'attached_to__isnull':True}, + js_template='ishtar/blocks/JQueryNaturalPerson.js', + new=True), + validators=[valid_id(Person)]) + +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.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" + associated_models = {'in_charge':models.Person} + in_charge = forms.IntegerField(label=_("Person in charge"), + widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person', + args=[PersonType.objects.get(txt_idx='sra_agent').pk]), + limit={'person_types':[PersonType.objects.get(txt_idx='sra_agent').pk]}, + associated_model=Person, new=True), + validators=[valid_id(Person)]) + related_file = forms.IntegerField(label=_("Related file"), required=False, + widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-file'), + associated_model=models.File), + validators=[valid_id(models.File)]) + comment = forms.CharField(label=_(u"Comment"), widget=forms.Textarea, + required=False) + instruction_deadline = forms.DateField(widget=widgets.JQueryDate, + required=False) + year = forms.IntegerField(label=_("Year"), + validators=[validators.MinValueValidator(1900), + validators.MaxValueValidator(2100)]) + numeric_reference = forms.IntegerField(label=_("Numeric reference"), + required=False) + end_date = forms.DateField(initial=get_now, widget=widgets.JQueryDate, + required=False) + + def __init__(self, *args, **kwargs): + c_year = datetime.date.today().year + if 'year' in kwargs: + c_year = kwargs.pop('year') + super(FileFormInstruction, self).__init__(*args, **kwargs) + self.fields['year'].initial = c_year + self.fields['year'].widget.attrs.update({'readonly':'readonly'}) + c_num, lasts = 0, "" + q = models.File.objects.filter(numeric_reference__isnull=False, + year=c_year).order_by('-numeric_reference') + if q.count(): + num = q.all()[0].numeric_reference + lasts = u"SRA %s-%d" % (unicode(c_year), num) + lbl = self.fields['numeric_reference'].label + if lasts: + lbl += u"<br/>(dernière entrée : %s)" % lasts + self.fields['numeric_reference'].label = mark_safe(lbl) + self.fields['numeric_reference'].initial = c_num + 1 diff --git a/archaeological_files_pdl/locale/fr/LC_MESSAGES/django.po b/archaeological_files_pdl/locale/fr/LC_MESSAGES/django.po new file mode 100644 index 000000000..5d8feb4ab --- /dev/null +++ b/archaeological_files_pdl/locale/fr/LC_MESSAGES/django.po @@ -0,0 +1,139 @@ +# Ishtar po translation. +# Copyright (C) 2014 +# This file is distributed under the same license as the Ishtar package. +# Étienne Loks <etienne.loks at peacefrogs net>, 2014. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: stable\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-12-31 12:09+0100\n" +"PO-Revision-Date: 2014-12-31 12:09+0100\n" +"Last-Translator: Étienne Loks <etienne.loks at peacefrogs net>\n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1)\n" + +#: forms.py:38 +msgid "General" +msgstr "Général" + +#: forms.py:40 +msgid "File type" +msgstr "Type de dossier" + +#: forms.py:41 forms.py:199 +msgid "Year" +msgstr "Année" + +#: forms.py:45 +msgid "Creation date" +msgstr "Date de création" + +#: forms.py:47 +msgid "Reception date" +msgstr "Date de réception" + +#: forms.py:59 +msgid "Permit type" +msgstr "Type de permis" + +#: forms.py:61 +msgid "Saisine type" +msgstr "Type de saisine" + +#: forms.py:72 +msgid "Planning" +msgstr "Aménagement" + +#: forms.py:74 +msgid "Planning name" +msgstr "Nom de l'aménagement" + +#: forms.py:77 +msgid "Locality" +msgstr "Lieu-dit" + +#: forms.py:79 +msgid "Address (number/street)" +msgstr "Adresse (n° / voie)" + +#: forms.py:81 +msgid "Number/street" +msgstr "n° / voie" + +#: forms.py:84 +msgid "Postal code" +msgstr "Code postal" + +#: forms.py:88 +msgid "Total surface (m²)" +msgstr "Surface totale des terrains (m²)" + +#: forms.py:92 +msgid "Total developed surface (m²)" +msgstr "Surface totale aménagée (m²)" + +#: forms.py:97 forms.py:136 forms.py:149 +msgid "General contractor" +msgstr "Aménageur" + +#: forms.py:161 +msgid "Town planning service" +msgstr "Service instructeur" + +#: forms.py:163 +msgid "File reference" +msgstr "Référence du dossier" + +#: forms.py:169 +msgid "Responsible town planning service" +msgstr "Dossier suivi par" + +#: forms.py:185 +msgid "Person in charge" +msgstr "Dossier suivi par" + +#: forms.py:191 +msgid "Related file" +msgstr "Dossier lié à" + +#: forms.py:195 +msgid "Comment" +msgstr "Commentaire" + +#: forms.py:202 +msgid "Numeric reference" +msgstr "Référence numérique" + +#: views.py:46 +msgid "New file" +msgstr "Nouveau dossier" + +#: views.py:58 views.py:61 +msgid "File followed by" +msgstr "Dossier suivi par" + +#: templates/ishtar/wizard/wizard_generalcontractor.html:12 +msgid "Corporation" +msgstr "Personne morale" + +#: templates/ishtar/wizard/wizard_generalcontractor.html:16 +msgid "Natural person" +msgstr "Personne physique" + +#: templates/ishtar/wizard/wizard_generalcontractor.html:27 +#: templates/ishtar/wizard/wizard_instruction.html:60 +#: templates/ishtar/wizard/wizard_preventiveplanning.html:76 +msgid "Validate" +msgstr "Validation" + +#: templates/ishtar/wizard/wizard_generalcontractor.html:28 +#: templates/ishtar/wizard/wizard_instruction.html:61 +#: templates/ishtar/wizard/wizard_preventiveplanning.html:77 +msgid "Validate and end" +msgstr "Terminer" diff --git a/archaeological_files_pdl/templates/ishtar/blocks/JQueryCorporationPerson.js b/archaeological_files_pdl/templates/ishtar/blocks/JQueryCorporationPerson.js new file mode 100644 index 000000000..3eb375167 --- /dev/null +++ b/archaeological_files_pdl/templates/ishtar/blocks/JQueryCorporationPerson.js @@ -0,0 +1,2 @@ +var current_status = 'corporation'; +{% include "ishtar/blocks/JQueryPersonOrga.js" %} diff --git a/archaeological_files_pdl/templates/ishtar/blocks/JQueryNaturalPerson.js b/archaeological_files_pdl/templates/ishtar/blocks/JQueryNaturalPerson.js new file mode 100644 index 000000000..fc4b9a90c --- /dev/null +++ b/archaeological_files_pdl/templates/ishtar/blocks/JQueryNaturalPerson.js @@ -0,0 +1,2 @@ +var current_status = 'natural'; +{% include "ishtar/blocks/JQueryPersonOrga.js" %} diff --git a/archaeological_files_pdl/templates/ishtar/blocks/JQueryPersonOrga.js b/archaeological_files_pdl/templates/ishtar/blocks/JQueryPersonOrga.js new file mode 100644 index 000000000..c151a5e4d --- /dev/null +++ b/archaeological_files_pdl/templates/ishtar/blocks/JQueryPersonOrga.js @@ -0,0 +1,65 @@ +person_save_callback = function(item_id, lbl){ + var url = {{edit_source}}; + $('#id_{{field_id}}').val(null); + $('#id_select_{{field_id}}').val(lbl); + if (item_id){ + url = {{edit_source}}+item_id; + $('#id_{{field_id}}').val(item_id); + } + $("#id_select_{{field_id}}").trigger('autocompletechange'); + $.get(url , function( data ) { + $( "#div-{{field_id}}" ).html( data ); + }); +}; + +edit_url = {{edit_source}}; +parent_id = "{{field_id}}"; + +person_new_callback = function(){ + var url = {{edit_source}}; + $('#id_{{field_id}}').val(null); + $('#id_select_{{field_id}}').val(null); +} + +$(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(); + }); + + $("#id_select_{{field_id}}").autocomplete({ + source: {{source}}, + select: function( event, ui ) { + var url = {{edit_source}}; + if(ui.item){ + url = {{edit_source}}+ui.item.id; + $('#id_{{field_id}}').val(ui.item.id); + } else { + $('#id_{{field_id}}').val(null); + } + $.get(url , function( data ) { + $( "#div-{{field_id}}" ).html( data ); + }); + }, + minLength: 2{% if options %}, + {{options}} + {% endif %} + }); + + $.get( {{edit_source}}{% if selected %}+'{{selected}}'{% endif %}, function( data ) { + $( "#div-{{field_id}}" ).html( data ); + }); + + $('#id_select_{{field_id}}').live('click', function(){ + $('#id_{{field_id}}').val(null); + $('#id_select_{{field_id}}').val(null); + $.get( {{edit_source}}, function( data ) { + $( "#div-{{field_id}}" ).html( data ); + }); + }); +}); diff --git a/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html new file mode 100644 index 000000000..e43e336c4 --- /dev/null +++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html @@ -0,0 +1,15 @@ +{% extends "ishtar/wizard/wizard_person_orga.html" %} + +{% 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> +{% endblock %} + +{% 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_instruction.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html new file mode 100644 index 000000000..4162a3764 --- /dev/null +++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html @@ -0,0 +1,106 @@ +{% 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 }} + +<table> + +<tr class='required'> + <th><label for="id_instruction-{{CURRENT_ACTION}}-in_charge">Dossier suivi par</label></th> +</tr> +<tr class='required'> + <td>{{wizard.form.in_charge.errors}}{{wizard.form.in_charge|safe}}</td> +</tr> + +<tr> + <th><label for="id_instruction-{{CURRENT_ACTION}}-related_file">Dossier lié à</label></th> +</tr> +<tr> + <td>{{wizard.form.related_file|safe}}</td> +</tr> + +<tr> + <th><label for="id_instruction-{{CURRENT_ACTION}}-comment">Commentaire</label></th> +</tr> +<tr> + <td>{{wizard.form.comment|safe}}</td> +</tr> + +<tr class='required'> + <th><label>État du dossier</label></th> +</tr> +<tr> + <td><input type='radio' name='state' value='open' id='state-open'/> <label for='state-open'>Dossier actif</label></td> +</tr> +<tr> + <td><input type='radio' name='state' value='closed' id='state-closed'/> <label for='state-closed'>Dossier clos / date de clôture</label> : {{wizard.form.end_date|safe}}</td> +</tr> + +<tr class='required'> + <th><label for="id_instruction-{{CURRENT_ACTION}}-instruction_deadline">Date limite d'instruction</label></th> +</tr> +<tr class='required'> + <td>{{wizard.form.instruction_deadline.errors}}{{wizard.form.instruction_deadline|safe}}</td> +</tr> + +<tr class='required'> + <th><label for="id_instruction-{{CURRENT_ACTION}}-year">{{wizard.form.numeric_reference.label}}</label></th> +</tr> +<tr> + <td>{{wizard.form.numeric_reference.errors}}SRA <span class='small'>{{wizard.form.year|safe}}</span> - <span class='small'>{{wizard.form.numeric_reference|safe}}</span></td> +</tr> +</table> + +<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" /> +{{ previous_fields|safe }} +{% block "validation_bar" %} +{% include 'ishtar/wizard/validation_bar.html' %} +{% endblock %} +</div> +</form> +<script type='text/javascript'> +$(function(){ + + if ($('#id_instruction-{{CURRENT_ACTION}}-end_date').val()){ + $("#state-closed").prop('checked', true); + } else { + $("#state-open").prop('checked', true); + } + + check_state = function(){ + var state = $("input[name=state]:checked").val(); + if (state == 'closed'){ + $('#id_instruction-{{CURRENT_ACTION}}-end_date').focus(); + $('#id_instruction-{{CURRENT_ACTION}}-end_date').prop('disabled', false); + } else if (state == 'open'){ + $('#id_instruction-{{CURRENT_ACTION}}-end_date').val(''); + $('#id_instruction-{{CURRENT_ACTION}}-end_date').prop('disabled', true); + } + }; + + $('input[name=state]').click(check_state); + + check_state(); + + $('#submit_form').click(function(){ + var state = $("input[name=state]:checked").val(); + if (state == 'closed'){ + if (!$('#id_instruction-{{CURRENT_ACTION}}-end_date').val()){ + alert("Vous devez sélectionner une date de clôture.") + return false; + } + return true; + } else if (state == 'open'){ + return true; + } else { + alert("Vous devez choisir un état pour ce dossier.") + return false; + } + return true; + }); +}); +</script> +{% 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/templates/ishtar/wizard/wizard_preventiveplanning.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_preventiveplanning.html new file mode 100644 index 000000000..66569a66d --- /dev/null +++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_preventiveplanning.html @@ -0,0 +1,80 @@ +{% 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 }} + +<table> + +<tr class='required'> + <th><label for="id_preventiveplanning-{{CURRENT_ACTION}}-name">Nom de l'aménagement</label></th> +</tr> +<tr class='required'> + <td>{{wizard.form.name|safe}}</td> +</tr> + +</table> + +<h4>Localisation</h4> +<table> + +{% if wizard.form.main_town.errors %}<tr> + <td colspan="2">{{wizard.form.main_town.errors}}</td> +</tr>{% endif %} + +<tr> + <td>{{wizard.form.main_town|safe}}</td> +</tr> + +<tr> + <th colspan='2'><label for="id_preventiveplanning-{{CURRENT_ACTION}}-locality">Lieu-dit</label></th> +</tr> +<tr> + <td colspan='2'>{{wizard.form.locality|safe}}</td> +</tr> + +<tr> + <th colspan='2'><label for="id_preventiveplanning-{{CURRENT_ACTION}}-address">Adresse</label></th> +</tr> +<tr> + <td colspan='2'>{{wizard.form.address|safe}}</td> +</tr> + +<tr> + <th colspan='2'><label for="id_preventiveplanning-{{CURRENT_ACTION}}-postal_code">Code postal</label></th> +</tr> +<tr> + <td colspan='2'>{{wizard.form.postal_code|safe}}</td> +</tr> + +</table> + +<h4>Surfaces</h4> +<table> + +<tr> + <th><label for="id_preventiveplanning-{{CURRENT_ACTION}}-total_surface">Surface totale des terrains</label></th> +</tr> +<tr> + <td>{{wizard.form.total_surface|safe}}</td> +</tr> + +<tr> + <th><label for="id_preventiveplanning-{{CURRENT_ACTION}}-total_developed_surface">Surface totale aménagée</label></th> +</tr> +<tr> + <td>{{wizard.form.total_developed_surface|safe}}</td> +</tr> + +</table> + +<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/urls.py b/archaeological_files_pdl/urls.py index b6878e90b..4cd746e8a 100644 --- a/archaeological_files_pdl/urls.py +++ b/archaeological_files_pdl/urls.py @@ -24,4 +24,12 @@ from archaeological_files_pdl import views urlpatterns = patterns('', url(r'file_creation/(?P<step>.+)?$', views.file_creation_wizard, name='file_creation'), + url(r'file_modification/(?P<step>.+)?$', + views.file_modification_wizard, name='file_modification'), + url(r'townplanning-edit/$', + views.TownPlanningCreate.as_view(), + name='townplanning_create'), + url(r'townplanning-edit/(?P<pk>\d+)$', + views.TownPlanningEdit.as_view(), + name='townplanning_edit'), ) diff --git a/archaeological_files_pdl/views.py b/archaeological_files_pdl/views.py index 7d51c8ec5..bcb1c0211 100644 --- a/archaeological_files_pdl/views.py +++ b/archaeological_files_pdl/views.py @@ -19,30 +19,81 @@ from django.utils.translation import ugettext_lazy as _ -from archaeological_files.wizards import FileWizard +from archaeological_files_pdl.wizards import FileWizard, FileModificationWizard from archaeological_operations.wizards import is_preventive, is_not_preventive -from ishtar_common.forms_common import TownFormset +from ishtar_common.views import OrganizationPersonCreate, OrganizationPersonEdit + from archaeological_files_pdl import forms from archaeological_files import forms as ref_forms from archaeological_operations.forms import ParcelFormSet from archaeological_files import models + +file_creation_wizard_is_preventive = is_preventive('general-file_creation', + models.FileType, type_key='file_type') +file_creation_wizard_is_not_preventive = is_not_preventive( + 'general-file_creation', models.FileType, type_key='file_type') file_creation_wizard = FileWizard.as_view([ - ('general-file_creation', forms.FileFormGeneral), - ('towns-file_creation', TownFormset), - ('parcels-file_creation', ParcelFormSet), - ('preventive-file_creation', ref_forms.FileFormPreventive), - ('research-file_creation', ref_forms.FileFormResearch), - ('final-file_creation', ref_forms.FinalForm)], + ('general-file_creation', forms.FileFormGeneral), + ('preventivetype-file_creation', forms.FileFormPreventiveType), + ('preventiveplanning-file_creation', forms.FileFormPlanning), + ('researchaddress-file_creation', forms.FileFormResearchAddress), + ('parcelspdl-file_creation', ParcelFormSet), + ('generalcontractor-file_creation', + forms.FileFormGeneralContractor), + ('planningservice-file_creation', + forms.FileFormPlanningService), + ('research-file_creation', ref_forms.FileFormResearch), + ('instruction-file_creation', + forms.FileFormInstruction), + ('final-file_creation', ref_forms.FinalForm)], label=_(u"New file"), condition_dict={ - 'preventive-file_creation':\ - is_preventive( 'general-file_creation', models.FileType, - type_key='file_type'), - 'research-file_creation':\ - is_not_preventive('general-file_creation', models.FileType, - type_key='file_type'), + 'preventivetype-file_creation':file_creation_wizard_is_preventive, + 'preventiveplanning-file_creation':file_creation_wizard_is_preventive, + 'generalcontractor-file_creation':file_creation_wizard_is_preventive, + 'planningservice-file_creation':file_creation_wizard_is_preventive, + 'researchaddress-file_creation':file_creation_wizard_is_not_preventive, + 'research-file_creation':file_creation_wizard_is_not_preventive }, url_name='file_creation',) + +file_modification_wizard_is_preventive = is_preventive('general-file_modification', + models.FileType, type_key='file_type') +file_modification_wizard_is_not_preventive = is_not_preventive( + 'general-file_modification', models.FileType, type_key='file_type') +file_modification_wizard = FileModificationWizard.as_view([ + ('selec-file_modification', ref_forms.FileFormSelection), + + ('general-file_modification', forms.FileFormGeneral), + ('preventivetype-file_modification', forms.FileFormPreventiveType), + ('preventiveplanning-file_modification', forms.FileFormPlanning), + ('researchaddress-file_modification', forms.FileFormResearchAddress), + ('parcelspdl-file_modification', ParcelFormSet), + ('generalcontractor-file_modification', + forms.FileFormGeneralContractor), + ('planningservice-file_modification', + forms.FileFormPlanningService), + ('research-file_modification', ref_forms.FileFormResearch), + ('instruction-file_modification', + forms.FileFormInstruction), + ('final-file_modification', ref_forms.FinalForm)], + label=_(u"File modification"), + condition_dict={ + 'preventivetype-file_modification':file_modification_wizard_is_preventive, + 'preventiveplanning-file_modification':file_modification_wizard_is_preventive, + 'generalcontractor-file_modification':file_modification_wizard_is_preventive, + 'planningservice-file_modification':file_modification_wizard_is_preventive, + 'researchaddress-file_modification':file_modification_wizard_is_not_preventive, + 'research-file_modification':file_modification_wizard_is_not_preventive + }, + url_name='file_modification',) + + +class TownPlanningEdit(OrganizationPersonEdit): + relative_label = _("File followed by") + +class TownPlanningCreate(OrganizationPersonCreate): + relative_label = _("File followed by") diff --git a/archaeological_files_pdl/wizards.py b/archaeological_files_pdl/wizards.py new file mode 100644 index 000000000..2d3491c8d --- /dev/null +++ b/archaeological_files_pdl/wizards.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2014 É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 +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# See the file COPYING for details. + +from archaeological_files.wizards import FileWizard as BaseFileWizard + +class FileWizard(BaseFileWizard): + parcel_step_key = 'parcelspdl-' + town_step_keys = ['preventiveplanning-', 'researchaddress-'] + town_input_id = 'main_town' + multi_towns = False + 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':\ + 'ishtar/wizard/wizard_preventiveplanning.html', + } + + def get_current_year(self): + general_form_key = 'general-' + self.url_name + return self.session_get_value(general_form_key, 'year') + + def get_form_kwargs(self, *args, **kwargs): + returned = super(FileWizard, self).get_form_kwargs(*args, **kwargs) + 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-'): + returned['year'] = self.get_current_year() + return returned + +class FileModificationWizard(FileWizard): + modification = True |