diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2014-12-30 16:59:44 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-05-06 15:38:32 +0200 |
commit | fea9c2d83c910d890ee1600545a61d88e9df6851 (patch) | |
tree | 52e8f0c1333377628b60f0feefad64861980519f /archaeological_files_pdl | |
parent | fa7d0e715228ccec391f6cc87b69abd50f442ef9 (diff) | |
download | Ishtar-fea9c2d83c910d890ee1600545a61d88e9df6851.tar.bz2 Ishtar-fea9c2d83c910d890ee1600545a61d88e9df6851.zip |
Work on new town field (with state and department) - work on new UI for files
Diffstat (limited to 'archaeological_files_pdl')
-rw-r--r-- | archaeological_files_pdl/forms.py | 56 | ||||
-rw-r--r-- | archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html | 100 | ||||
-rw-r--r-- | archaeological_files_pdl/templates/ishtar/wizard/wizard_preventiveplanning.html | 77 | ||||
-rw-r--r-- | archaeological_files_pdl/views.py | 2 | ||||
-rw-r--r-- | archaeological_files_pdl/wizards.py | 17 |
5 files changed, 245 insertions, 7 deletions
diff --git a/archaeological_files_pdl/forms.py b/archaeological_files_pdl/forms.py index 2703e52fd..295edcd36 100644 --- a/archaeological_files_pdl/forms.py +++ b/archaeological_files_pdl/forms.py @@ -21,13 +21,14 @@ 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, valid_id +from ishtar_common.models import Person, PersonType, valid_id from archaeological_files import models from ishtar_common.forms import get_now, reverse_lazy -from ishtar_common.forms_common import get_town_field +from ishtar_common.forms_common import get_advanced_town_field from archaeological_files.forms import GENERAL_CONTRACTOR, \ RESPONSIBLE_PLANNING_SERVICE @@ -72,11 +73,14 @@ class FileFormPlanning(forms.Form): associated_models = {'town':models.Town} name = forms.CharField(label=_(u"Planning name"), required=False, max_length=100) - main_town = get_town_field(required=False) + 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, required=False) + 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, @@ -156,6 +160,8 @@ class FileFormGeneralContractor(forms.Form): class FileFormPlanningService(forms.Form): form_label = _(u"Town planning service") associated_models = {'responsible_planning_service':models.Person} + reference_number = forms.IntegerField(label=_(u"File reference"), + required=False) def __init__(self, *args, **kwargs): super(FileFormPlanningService, self).__init__(*args, **kwargs) @@ -170,4 +176,46 @@ class FileFormPlanningService(forms.Form): js_template='ishtar/blocks/JQueryCorporationPerson.js', new=True), validators=[valid_id(Person)]) + self.fields.keyOrder = ['responsible_planning_service', + 'reference_number'] + +class FileFormInstruction(forms.Form): + form_label = u"Instruction SRA" + 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) + 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/templates/ishtar/wizard/wizard_instruction.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html new file mode 100644 index 000000000..b47de2cce --- /dev/null +++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html @@ -0,0 +1,100 @@ +{% 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|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}}-year">{{wizard.form.numeric_reference.label}}</label></th> +</tr> +<tr> + <td>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 }} +<div id='validation-bar'> + <input type="submit" id="submit_form" name='validate' value="{% trans "Validate" %}"/> + {% if next_steps %}<input type="submit" id="submit_end_form" name='validate_and_end' value="{% trans "Validate and end" %}"/>{% endif %} +</div> +</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_preventiveplanning.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_preventiveplanning.html new file mode 100644 index 000000000..41527629d --- /dev/null +++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_preventiveplanning.html @@ -0,0 +1,77 @@ +{% 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> + +<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 }} +<div id='validation-bar'> + <input type="submit" id="submit_form" name='validate' value="{% trans "Validate" %}"/> + {% if next_steps %}<input type="submit" id="submit_end_form" name='validate_and_end' value="{% trans "Validate and end" %}"/>{% endif %} +</div> +</div> +</form> +{% endblock %} diff --git a/archaeological_files_pdl/views.py b/archaeological_files_pdl/views.py index 712990234..c8e1d1498 100644 --- a/archaeological_files_pdl/views.py +++ b/archaeological_files_pdl/views.py @@ -39,6 +39,8 @@ file_creation_wizard = FileWizard.as_view([ forms.FileFormGeneralContractor), ('planningservice-file_creation', forms.FileFormPlanningService), + ('instruction-file_creation', + forms.FileFormInstruction), ('research-file_creation', ref_forms.FileFormResearch), ('final-file_creation', ref_forms.FinalForm)], label=_(u"New file"), diff --git a/archaeological_files_pdl/wizards.py b/archaeological_files_pdl/wizards.py index 4abe5f0d5..6f688d7ca 100644 --- a/archaeological_files_pdl/wizards.py +++ b/archaeological_files_pdl/wizards.py @@ -25,12 +25,23 @@ class FileWizard(BaseFileWizard): town_input_id = 'main_town' multi_towns = False wizard_templates = { - 'generalcontractor-file_creation':\ - 'ishtar/wizard/wizard_generalcontractor.html',} + 'generalcontractor-%(url_name)s':\ + 'ishtar/wizard/wizard_generalcontractor.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-file_creation'): + if args and args[0].startswith('generalcontractor-'): 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 |