summaryrefslogtreecommitdiff
path: root/archaeological_files_pdl
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-07-21 17:47:46 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2015-07-21 17:47:46 +0200
commitc55c4fad9972df04273e9a98f9dd4918998e4e70 (patch)
tree28e882ed130ed7d681f958879522cbe5ae24d814 /archaeological_files_pdl
parentc1e6542f8a339dcb60434154f4322f2dca329918 (diff)
downloadIshtar-c55c4fad9972df04273e9a98f9dd4918998e4e70.tar.bz2
Ishtar-c55c4fad9972df04273e9a98f9dd4918998e4e70.zip
Manage lan planner organizations (refs #2671)
Diffstat (limited to 'archaeological_files_pdl')
-rw-r--r--archaeological_files_pdl/forms.py96
-rw-r--r--archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html4
-rw-r--r--archaeological_files_pdl/templates/ishtar/wizard/wizard_person_orga.html2
-rw-r--r--archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html11
4 files changed, 78 insertions, 35 deletions
diff --git a/archaeological_files_pdl/forms.py b/archaeological_files_pdl/forms.py
index 102275d64..1f2dfd708 100644
--- a/archaeological_files_pdl/forms.py
+++ b/archaeological_files_pdl/forms.py
@@ -30,7 +30,8 @@ from archaeological_files import models
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
+ GENERAL_CONTRACTOR_ORGA, RESPONSIBLE_PLANNING_SERVICE, \
+ RESPONSIBLE_PLANNING_SERVICE_ORGA
from ishtar_common import widgets
@@ -109,8 +110,11 @@ class FileFormResearchAddress(forms.Form):
class PersonOrgaForm(forms.Form):
PERSON_FIELD = 'TO BE DEFINED'
- ORGA_FIELD = 'TO BE DEFINED'
PERSON_TYPE = GENERAL_CONTRACTOR
+ PERSON_LABEL = ""
+ ORGA_FIELD = 'TO BE DEFINED'
+ ORGA_TYPE = GENERAL_CONTRACTOR_ORGA
+ ORGA_LABEL = ""
def _media(self):
if self.status == 'corporation':
@@ -118,24 +122,34 @@ class PersonOrgaForm(forms.Form):
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]
+ # the order is important: PERSON can have an ORGA
+ for field in [self.ORGA_FIELD, self.PERSON_FIELD]:
+ current_item_key = ((kwargs['prefix'] + '-') \
+ if kwargs.get('prefix') else '') + field
+ if kwargs['data'] and kwargs['data'].get(current_item_key):
+ model = self.associated_models[field]
+ try:
+ item = model.objects.get(pk=kwargs['data'][current_item_key])
+ current_status = 'natural' if field == self.PERSON_FIELD \
+ else 'corporation'
+ except (model.DoesNotExist, ValueError):
+ pass
+ initial = kwargs.get("initial", {})
+ if not current_status:
+ # the order is important: PERSON can have an ORGA
+ for field in [self.ORGA_FIELD, self.PERSON_FIELD]:
+ value = initial.get(field)
+ model = self.associated_models[field]
try:
- item = model.objects.get(pk=kwargs['data'][current_item_key])
- current_status = 'natural'
+ item = model.objects.get(pk=value)
+ current_status = 'natural' if field == self.PERSON_FIELD \
+ else 'corporation'
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:
@@ -153,13 +167,15 @@ class PersonOrgaForm(forms.Form):
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,
+ label=self.PERSON_LABEL,
required=False,
+ initial= initial.get(self.PERSON_FIELD, None),
widget=widgets.JQueryPersonOrganization(
reverse_lazy('autocomplete-person',
args=[self.PERSON_TYPE.pk]),
@@ -170,37 +186,55 @@ class PersonOrgaForm(forms.Form):
js_template='ishtar/blocks/JQueryNaturalPerson.js',
new=True),
validators=[valid_id(Person)])
+ else:
+ self.fields[self.ORGA_FIELD] = forms.IntegerField(
+ label=self.ORGA_LABEL,
+ required=False,
+ initial= initial.get(self.ORGA_FIELD, None),
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy('autocomplete-organization',
+ args=[self.ORGA_TYPE.pk]),
+ limit={'organization_type':[self.ORGA_TYPE.pk]},
+ associated_model=models.Organization,
+ new=True),
+ validators=[valid_id(models.Organization)])
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)
+ associated_models = {'general_contractor':models.Person,
+ 'corporation_general_contractor':models.Organization}
PERSON_FIELD = 'general_contractor'
- ORGA_FIELD = 'raw_general_contractor'
PERSON_TYPE = GENERAL_CONTRACTOR
+ PERSON_LABEL = _(u"General contractor")
+ ORGA_FIELD = 'corporation_general_contractor'
+ ORGA_TYPE = GENERAL_CONTRACTOR_ORGA
+ ORGA_LABEL = _(u"General contractor")
+
+ # default initialisation before dynamic
+ general_contractor = forms.IntegerField(label=" ", widget=forms.HiddenInput,
+ required=False)
+ corporation_general_contractor = forms.IntegerField(label=" ",
+ widget=forms.HiddenInput, required=False)
class FileFormPlanningService(PersonOrgaForm):
form_label = _(u"Town planning service")
- associated_models = {'responsible_town_planning_service':models.Person}
+ associated_models = {'responsible_town_planning_service':models.Person,
+ 'planning_service':models.Organization}
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
+ PERSON_LABEL = _(u"Responsible town planning service")
+ ORGA_FIELD = 'planning_service'
+ ORGA_TYPE = RESPONSIBLE_PLANNING_SERVICE_ORGA
+ ORGA_LABEL = _(u"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')
+ # default initialisation before dynamic
+ responsible_town_planning_service = forms.IntegerField(label=" ",
+ widget=forms.HiddenInput, required=False)
+ planning_service = forms.IntegerField(label=" ", widget=forms.HiddenInput,
+ required=False)
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 e43e336c4..4fca7aa5e 100644
--- a/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html
+++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html
@@ -2,8 +2,8 @@
{% 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>
+ <th>{{ wizard.form.corporation_general_contractor.label_tag }}</th>
+ <td> {{ wizard.form.corporation_general_contractor.errors }}{{wizard.form.corporation_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
index 91dd7e042..d69e1e0d3 100644
--- a/archaeological_files_pdl/templates/ishtar/wizard/wizard_person_orga.html
+++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_person_orga.html
@@ -52,8 +52,10 @@ $(function() {
</table>
</div>
+<div>
{% block otherfields %}
{% endblock %}
+</div>
<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />
{{ previous_fields|safe }}
diff --git a/archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html
index 29bc2397c..6fd9eef71 100644
--- a/archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html
+++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html
@@ -2,8 +2,8 @@
{% 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>
+ <th>{{ wizard.form.planning_service.label_tag }}</th>
+ <td> {{ wizard.form.planning_service.errors }}{{wizard.form.planning_service|safe}}</td>
</tr>
{% endblock %}
@@ -13,3 +13,10 @@
<td> {{ wizard.form.responsible_town_planning_service.errors }}{{wizard.form.responsible_town_planning_service|safe}}</td>
</tr>
{% endblock %}
+
+{% block otherfields %}
+ <tr class='required'>
+ <th>{{ wizard.form.reference_number.label_tag }}</th>
+ <td> {{ wizard.form.reference_number.errors }}{{wizard.form.reference_number|safe}}</td>
+ </tr>
+{% endblock %}