summaryrefslogtreecommitdiff
path: root/archaeological_files_pdl/forms.py
diff options
context:
space:
mode:
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
commit25ec2a9794786ac83fa8ce743078305682d8298d (patch)
tree52e8f0c1333377628b60f0feefad64861980519f /archaeological_files_pdl/forms.py
parent155b3890c7938e98f6c1596551260a92041bea68 (diff)
downloadIshtar-25ec2a9794786ac83fa8ce743078305682d8298d.tar.bz2
Ishtar-25ec2a9794786ac83fa8ce743078305682d8298d.zip
Work on new town field (with state and department) - work on new UI for files
Diffstat (limited to 'archaeological_files_pdl/forms.py')
-rw-r--r--archaeological_files_pdl/forms.py56
1 files changed, 52 insertions, 4 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