summaryrefslogtreecommitdiff
path: root/archaeological_files_pdl
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2020-03-20 19:40:24 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2020-03-20 19:40:24 +0100
commitef7bc287bd743b01b534cff5b28bbe39268063a5 (patch)
treed5fc7bd1cb9d8dab4c967fcad6dccba5e6b3517a /archaeological_files_pdl
parent8d72941c7ba307d8f4541e34f24a957784e9660d (diff)
downloadIshtar-ef7bc287bd743b01b534cff5b28bbe39268063a5.tar.bz2
Ishtar-ef7bc287bd743b01b534cff5b28bbe39268063a5.zip
Refactoring and many fixes on file module
Diffstat (limited to 'archaeological_files_pdl')
-rw-r--r--archaeological_files_pdl/forms.py199
-rw-r--r--archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html39
-rw-r--r--archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html116
-rw-r--r--archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html53
-rw-r--r--archaeological_files_pdl/wizards.py14
5 files changed, 138 insertions, 283 deletions
diff --git a/archaeological_files_pdl/forms.py b/archaeological_files_pdl/forms.py
index 7ade0b3f0..7ada27be8 100644
--- a/archaeological_files_pdl/forms.py
+++ b/archaeological_files_pdl/forms.py
@@ -26,11 +26,14 @@ from ishtar_common.utils import ugettext_lazy as _
from ishtar_common.models import Person, Town, Department, valid_id, \
person_type_pk_lazy, person_type_pks_lazy, organization_type_pks_lazy, \
- organization_type_pk_lazy
+ organization_type_pk_lazy, get_sra_agent_label, \
+ get_orga_general_contractor_label, get_general_contractor_label, \
+ get_orga_planning_service_label, get_responsible_planning_service_label
+
from archaeological_files import models
from ishtar_common.forms import get_now, reverse_lazy, ManageOldType, \
- CustomForm, FieldType, IshtarForm
+ CustomForm, FieldType, IshtarForm, FormHeader
from ishtar_common import widgets
from bootstrap_datepicker.widgets import DatePicker
@@ -84,18 +87,22 @@ class FileFormPreventiveType(CustomForm, ManageOldType, forms.Form):
self.fields['permit_type'].help_text = models.PermitType.get_help()
-class FileFormPlanning(CustomForm, forms.Form):
+class FileFormPlanning(CustomForm, ManageOldType):
form_label = _(u"Planning")
form_admin_name = _(u"Archaeological file - 017 - Preventive - Planning")
form_slug = "file-017-preventiveplanning"
base_models = ['town', 'department']
associated_models = {'town': Town, 'department': Department}
+ HEADERS = {}
+ HEADERS['town'] = FormHeader(_("Localisation"))
name = forms.CharField(label=_(u"Planning name"), required=False,
max_length=100)
town = widgets.Select2MultipleField(
model=Town, label=_("Towns"), required=False, remote=True)
department = widgets.Select2MultipleField(
- model=Department, label=_("Departments"), required=False)
+ model=Department, label=_("Departments"), required=False,
+ help_text=_("Only relevant when no town is provided.")
+ )
locality = forms.CharField(label=_(u"Locality"), max_length=100,
required=False)
address = forms.CharField(
@@ -104,6 +111,7 @@ class FileFormPlanning(CustomForm, forms.Form):
required=False)
postal_code = forms.CharField(label=_(u"Postal code"), max_length=10,
required=False)
+ HEADERS['total_surface'] = FormHeader(_("Surfaces"))
total_surface = forms.FloatField(
required=False,
widget=widgets.AreaWidget,
@@ -236,33 +244,36 @@ class PersonOrgaForm(forms.Form):
validators=[valid_id(models.Organization)])
-class FileFormGeneralContractor(CustomForm, PersonOrgaForm):
+class FileFormGeneralContractor(CustomForm, ManageOldType):
form_label = _(u"General contractor")
form_admin_name = _("Archaeological file - 030 - General contractor")
form_slug = "file-030-generalcontractor"
+ extra_form_modals = ["person", "organization"]
associated_models = {'general_contractor': models.Person,
'corporation_general_contractor': models.Organization}
+
corporation_general_contractor = forms.IntegerField(
label=_("General contractor"),
- required=False,
- widget=widgets.JQueryPersonOrganization(
- reverse_lazy('autocomplete-organization',
- args=[
- organization_type_pks_lazy(['general_contractor'])]
- ),
- reverse_lazy('organization_create'),
- model=models.Organization,
+ widget=widgets.JQueryAutoComplete(
+ reverse_lazy(
+ 'autocomplete-organization',
+ args=[
+ organization_type_pks_lazy(['general_contractor']),
+ ]),
limit={
'organization_type': [
organization_type_pk_lazy('general_contractor')
- ]},
- js_template='ishtar/blocks/JQueryCorporationPerson.js',
- new=True),
- validators=[valid_id(models.Organization)]
- )
+ ]
+ },
+ tips=get_orga_general_contractor_label,
+ associated_model=models.Organization, new=True,
+ detail=True,
+ modify=True
+ ),
+ validators=[valid_id(models.Organization)])
general_contractor = forms.IntegerField(
- label=_(u"In charge"),
+ label=_("In charge"),
required=False,
widget=widgets.JQueryAutoComplete(
reverse_lazy('autocomplete-person',
@@ -271,118 +282,56 @@ class FileFormGeneralContractor(CustomForm, PersonOrgaForm):
]),
associated_model=Person,
limit={'person_types': [
- person_type_pk_lazy(['general_contractor'])
+ person_type_pk_lazy('general_contractor')
]},
- dynamic_limit=['general_contractor'],
- url_new='new-person-noorga',
+ tips=get_general_contractor_label,
+ detail=True,
+ modify=True,
new=True),
validators=[valid_id(Person)]
)
- PERSON_FIELD = 'general_contractor'
- PERSON_TYPE_PK = person_type_pk_lazy('general_contractor')
- PERSON_LABEL = _(u"General contractor")
- ORGA_FIELD = 'corporation_general_contractor'
- ORGA_TYPE_PK = organization_type_pk_lazy('general_contractor')
- ORGA_LABEL = _(u"General contractor")
-
- def __init__(self, *args, **kwargs):
- # get the status: natural person or corporation
- DEFAULT_STATUS = 'natural'
- current_status = ''
- if 'data' in kwargs:
- # the order is important: PERSON can have an ORGA
- for field in [self.PERSON_FIELD, self.ORGA_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:
- 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:
- model.objects.get(pk=value)
- current_status = 'natural' if field == self.PERSON_FIELD \
- else 'corporation'
- except (model.DoesNotExist, ValueError):
- pass
- 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
-
- user = None
- if 'user' in kwargs:
- user = kwargs.pop('user')
-
- super(PersonOrgaForm, self).__init__(*args, **kwargs)
-
- # distinct widget for natural and corporation
- if status == 'natural':
- self.fields[self.PERSON_FIELD] = forms.IntegerField(
- 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]),
- 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)])
- self.fields.pop(self.ORGA_FIELD)
-
-
-class FileFormPlanningService(CustomForm, forms.Form):
- form_label = _(u"Planning service")
+ def clean(self):
+ general_contractor = self.cleaned_data["general_contractor"]
+ corporation_general_contractor = self.cleaned_data[
+ "corporation_general_contractor"]
+ if general_contractor:
+ try:
+ person = models.Person.objects.get(pk=general_contractor)
+ except models.Person.DoesNotExist:
+ raise forms.ValidationError(_("Non existing person."))
+ if person.attached_to.pk != corporation_general_contractor:
+ raise forms.ValidationError(_(
+ "The organization of the person in charge differs from the "
+ "general contractor."))
+ return self.cleaned_data
+
+
+class FileFormPlanningService(CustomForm, IshtarForm):
+ form_label = _("Planning service")
form_admin_name = _("Archaeological file - 040 - Planning service")
form_slug = "file-040-planningservice"
+ extra_form_modals = ["person", "organization"]
associated_models = {'responsible_town_planning_service': models.Person,
'planning_service': models.Organization}
- permit_reference = forms.CharField(label=_(u"File reference"),
- required=False, max_length=200)
planning_service = forms.IntegerField(
label=_("Planning service"),
required=False,
- widget=widgets.JQueryPersonOrganization(
+ widget=widgets.JQueryAutoComplete(
reverse_lazy(
'autocomplete-organization',
args=[organization_type_pks_lazy(['planning_service'])]),
- reverse_lazy('organization_create'),
- model=models.Organization,
+ associated_model=models.Organization,
limit={
'organization_type':
[organization_type_pk_lazy(['planning_service'])],
},
- js_template='ishtar/blocks/JQueryCorporationPerson.js',
- new=True),
+ tips=get_orga_planning_service_label,
+ new=True,
+ detail=True,
+ modify=True,
+ ),
validators=[valid_id(models.Organization)]
)
responsible_town_planning_service = forms.IntegerField(
@@ -398,21 +347,39 @@ class FileFormPlanningService(CustomForm, forms.Form):
person_type_pk_lazy('responsible_planning_service')
]},
dynamic_limit=['planning_service'],
- url_new='new-person-noorga',
+ tips=get_responsible_planning_service_label,
+ detail=True,
+ modify=True,
new=True),
validators=[valid_id(Person)]
)
+ permit_reference = forms.CharField(label=_(u"File reference"),
+ required=False, max_length=200)
+
+ def clean(self):
+ responsible = self.cleaned_data["responsible_town_planning_service"]
+ orga = self.cleaned_data["planning_service"]
+ if responsible:
+ try:
+ person = models.Person.objects.get(pk=responsible)
+ except models.Person.DoesNotExist:
+ raise forms.ValidationError(_("Non existing person."))
+ if person.attached_to.pk != orga:
+ raise forms.ValidationError(_(
+ "The organization of the person in charge differs from the "
+ "planning service."))
+ return self.cleaned_data
class FileFormInstruction(CustomForm, IshtarForm):
- form_label = u"Instruction SRA"
+ form_label = _("Instruction")
form_admin_name = _("Archaeological file - 050 - Instruction")
form_slug = "file-050-instruction"
extra_form_modals = ["person", "organization"]
associated_models = {'in_charge': models.Person,
'related_file': models.File}
in_charge = forms.IntegerField(
- label=_("Person in charge"),
+ label=_("File managed by"),
widget=widgets.JQueryAutoComplete(
reverse_lazy(
'autocomplete-person',
@@ -421,7 +388,9 @@ class FileFormInstruction(CustomForm, IshtarForm):
'person_types': [
person_type_pk_lazy('sra_agent')]
},
- associated_model=Person, new=True),
+ tips=get_sra_agent_label,
+ associated_model=Person, new=True,
+ ),
validators=[valid_id(Person)])
related_file = forms.IntegerField(
label=_("Related file"), required=False,
diff --git a/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html
deleted file mode 100644
index 169b2757e..000000000
--- a/archaeological_files_pdl/templates/ishtar/wizard/wizard_generalcontractor.html
+++ /dev/null
@@ -1,39 +0,0 @@
-{% extends "ishtar/wizard/wizard_person_orga.html" %}
-{% load replace_underscore %}
-
-{% block corporation %}
- <tr class='required'>
- <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 %}
-
-{% 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 %}
-{% block extra_head_po %}
-<script type='text/javascript'>
-$(function() {
-var corp_id = '#id_{{wizard.form.prefix}}-corporation_general_contractor';
-var pers_id = "#id_select_{{wizard.form.prefix}}-general_contractor" ;
-var pers_select_id = "#id_select_{{wizard.form.prefix}}-general_contractor" ;
-$(corp_id).change(
- function(){
- $(pers_select_id).autocomplete(
- "option", "source",
- source_{{wizard.form.prefix|replace_underscore}}_general_contractor
- + $(corp_id).val() + '/');
- $(pers_select_id).val("");
- $(pers_id).val("");
- if ($(corp_id).val()){
- $(pers_select_id).prop("disabled", false);
- } else {
- $(pers_select_id).prop("disabled", true);
- }
-});
-});
-</script>
-{% endblock %}
diff --git a/archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html
index 72dc1d35d..34db944aa 100644
--- a/archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html
+++ b/archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html
@@ -1,76 +1,48 @@
{% 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>
+{% block form_detail %}
+ <div class="form-row">
+ {% with wizard.form.in_charge as field %}
+ {% include "blocks/bs_field_snippet.html" %}
+ {% endwith %}
+ {% with wizard.form.related_file as field %}
+ {% include "blocks/bs_field_snippet.html" %}
+ {% endwith %}
+ {% with wizard.form.comment as field %}
+ {% include "blocks/bs_field_snippet.html" %}
+ {% endwith %}
-<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>{{wizard.form.end_date.errors}}<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>
-{% if saisine_type %}<tr>
- <th><em>{{ saisine_type }}{% if saisine_type_delay %} : délai de {{saisine_type_delay}} jours{% endif %}</em></th>
-</tr>{% endif %}
-<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 "footer" %}
- <div id="footer">
- {% block "validation_bar" %}
- {% include 'ishtar/wizard/validation_bar.html' %}
- {% endblock %}
- {% include 'ishtar/blocks/footer.html' %}
+ <div class="form-group col-lg-6">
+ <span class="required">
+ <label class="required">{% trans "State of the file:" %}</label>
+ </span>
+ <div class="form-group col-lg-12 mb-0">
+ <span><input type='radio' name='state' value='open' id='state-open'/>
+ <label for='state-open'>Dossier actif</label></span>
+ </div>
+ <div class="form-group col-lg-12">
+ <span>{{wizard.form.end_date.errors}}<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}}</span>
+ </div>
+ </div>
+ {% with wizard.form.instruction_deadline as field %}{% with saisine_type_message as extra_field_label %}
+ {% include "blocks/bs_field_snippet.html" %}
+ {% endwith %}{% endwith %}
+ <div class="form-group col-lg-6">
+ <span class="required">
+ <label>{{wizard.form.numeric_reference.label}}{% trans ":" %}</label>
+ </span>
+ <div class="form-inline">
+ {{wizard.form.numeric_reference.errors}}
+ {% if FILE_PREFIX %}<span class="pr-2">{{FILE_PREFIX}}</span>{% endif %}
+ <span class="pr-2">{{wizard.form.year|safe}}</span> -
+ <span class="pl-2">{{wizard.form.numeric_reference|safe}}</span>
+ </div>
+ </div>
</div>
- {% endblock %}
-</div>
-</form>
-<script type='text/javascript'>
-$(function(){
+{% endblock %}
+{% block "js_extra_ready" %}
if ($('#id_instruction-{{CURRENT_ACTION}}-end_date').val()){
$("#state-closed").prop('checked', true);
} else {
@@ -96,18 +68,16 @@ $(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.")
+ alert("{% trans 'You must select a closing date.' %}")
return false;
}
return true;
} else if (state == 'open'){
return true;
} else {
- alert("Vous devez choisir un état pour ce dossier.")
+ alert("{% trans 'You must select a state for this file.' %}")
return false;
}
return true;
});
-});
-</script>
-{% endblock %}
+ {% endblock %}
diff --git a/archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html
deleted file mode 100644
index 5eb7c014b..000000000
--- a/archaeological_files_pdl/templates/ishtar/wizard/wizard_planningservice.html
+++ /dev/null
@@ -1,53 +0,0 @@
-{% 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'>
-{% if wizard.form.media %}{{ wizard.form.media }}{% endif %}
-{{ wizard.management_form }}
-
-<table>
- {% if wizard.form.non_field_errors %}<tr class='errors'>
- <td colspan='3'>{{wizard.form.non_field_errors}}</td>
- </tr>{%endif%}
-
- <tr>
- <th>{{ wizard.form.planning_service.label_tag }}</th>
- <td> {{ wizard.form.planning_service.errors }}{{wizard.form.planning_service|safe}}</td>
- </tr>
- <tr>
- <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>
-</table>
-
-
-<div>
-<table>
- {% if permit_type %}
- <tr>
- <th colspan='3'>{{permit_type}}</th>
- </tr>{% endif %}
- <tr>
- <th>{{ wizard.form.permit_reference.label_tag }}{% if permit_type_code %} [{{permit_type_code}}]{% endif %}</th>
- <td> {{ wizard.form.permit_reference.errors }}{{wizard.form.permit_reference|safe}}</td>
- </tr>
-</table>
-</div>
-
-<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />
-{{ previous_fields|safe }}
- {% block "footer" %}
- <div id="footer">
- {% block "validation_bar" %}
- {% include 'ishtar/wizard/validation_bar.html' %}
- {% endblock %}
- {% include 'ishtar/blocks/footer.html' %}
- </div>
- {% endblock %}
-</div>
-</form>
-{% endblock %}
-
-
-
diff --git a/archaeological_files_pdl/wizards.py b/archaeological_files_pdl/wizards.py
index d13811eea..988303937 100644
--- a/archaeological_files_pdl/wizards.py
+++ b/archaeological_files_pdl/wizards.py
@@ -17,9 +17,13 @@
# See the file COPYING for details.
+from django.conf import settings
+
from archaeological_files.wizards import FileWizard as BaseFileWizard
from archaeological_files import models
+from ishtar_common.utils import ugettext_lazy as _
+
class FileWizard(BaseFileWizard):
parcel_step_key = 'parcelspdl-'
@@ -28,8 +32,8 @@ class FileWizard(BaseFileWizard):
towns_formset = False
multi_towns = True
wizard_templates = {
- 'generalcontractor-%(url_name)s':
- 'ishtar/wizard/wizard_generalcontractor.html',
+ #'generalcontractor-%(url_name)s':
+ # 'ishtar/wizard/wizard_generalcontractor.html',
'planningservice-%(url_name)s':
'ishtar/wizard/wizard_planningservice.html',
'instruction-%(url_name)s':
@@ -82,9 +86,13 @@ class FileWizard(BaseFileWizard):
pass
elif self.steps.current == forminstruction:
saisine_type = self.get_saisine_type()
+ context['FILE_PREFIX'] = settings.ISHTAR_FILE_PREFIX
if saisine_type:
context['saisine_type'] = str(saisine_type)
- context['saisine_type_delay'] = saisine_type.delay or 0
+ context['saisine_type_message'] = str(saisine_type)
+ if saisine_type.delay:
+ context['saisine_type_message'] += str(_(
+ ": delay of {} days")).format(saisine_type.delay)
elif self.steps.current == formfinal:
if self.steps.current.endswith('creation'): # creation only
parcels = []