summaryrefslogtreecommitdiff
path: root/archaeological_files_pdl
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-11-15 16:29:30 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:19 +0100
commitcda77c979e232386ef24ea7a04600f16f3c32c98 (patch)
tree7d53e762723338913594ccdb42c6fa08c4bfb5ef /archaeological_files_pdl
parent4746cd2938df3cf87ae338d22eb4f67f35bac960 (diff)
downloadIshtar-cda77c979e232386ef24ea7a04600f16f3c32c98.tar.bz2
Ishtar-cda77c979e232386ef24ea7a04600f16f3c32c98.zip
File module refactoring - more tests for files
Diffstat (limited to 'archaeological_files_pdl')
-rw-r--r--archaeological_files_pdl/forms.py515
-rw-r--r--archaeological_files_pdl/templates/ishtar/blocks/JQueryCorporationPerson.js2
-rw-r--r--archaeological_files_pdl/templates/ishtar/blocks/JQueryNaturalPerson.js2
-rw-r--r--archaeological_files_pdl/templates/ishtar/blocks/JQueryPersonOrga.js66
-rw-r--r--archaeological_files_pdl/templates/ishtar/wizard/file_confirm_wizard.html27
-rw-r--r--archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html83
-rw-r--r--archaeological_files_pdl/templates/ishtar/wizard/wizard_person_orga.html76
-rw-r--r--archaeological_files_pdl/urls.py45
-rw-r--r--archaeological_files_pdl/views.py100
-rw-r--r--archaeological_files_pdl/wizards.py144
10 files changed, 0 insertions, 1060 deletions
diff --git a/archaeological_files_pdl/forms.py b/archaeological_files_pdl/forms.py
deleted file mode 100644
index 58480a36b..000000000
--- a/archaeological_files_pdl/forms.py
+++ /dev/null
@@ -1,515 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-# Copyright (C) 2014-2016 É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.
-
-import datetime
-
-from django import forms
-from django.core import validators
-from django.utils.functional import lazy
-from django.utils.safestring import mark_safe
-from ishtar_common.utils import ugettext_lazy as _
-
-from ishtar_common.models import (
- Person,
- Town,
- valid_id,
- person_type_pk_lazy,
- person_type_pks_lazy,
- organization_type_pks_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 ishtar_common.models_common import Department
-
-from archaeological_files import models
-
-from ishtar_common.forms import (
- get_now,
- reverse_lazy,
- ManageOldType,
- CustomForm,
- FieldType,
- IshtarForm,
- FormHeader,
-)
-
-from ishtar_common import widgets
-from bootstrap_datepicker.widgets import DatePicker
-
-
-class FileFormGeneral(CustomForm, ManageOldType):
- form_label = _("General")
- form_admin_name = _("Archaeological file - 010 - General")
- form_slug = "file-010-general"
- 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,
- validators=[
- validators.MinValueValidator(1000),
- validators.MaxValueValidator(2100),
- ],
- )
- creation_date = forms.DateField(
- label=_("Creation date"), initial=get_now, widget=DatePicker
- )
- reception_date = forms.DateField(
- label=_("Reception date"), initial=get_now, widget=DatePicker
- )
-
- TYPES = [
- FieldType("file_type", models.FileType),
- ]
-
- def clean_reception_date(self):
- value = self.cleaned_data.get("reception_date", None)
- if value and value > datetime.date.today():
- raise forms.ValidationError(_("Reception date cannot be after today."))
- return value
-
-
-class FileFormPreventiveType(CustomForm, ManageOldType, forms.Form):
- form_label = "Saisine"
- form_admin_name = _("Archaeological file - 013 - Preventive - Saisine")
- form_slug = "file-013-preventivesaisine"
- associated_models = {
- "saisine_type": models.SaisineType,
- "permit_type": models.PermitType,
- }
- permit_type = forms.ChoiceField(label=_("Permit type"), required=False, choices=[])
- saisine_type = forms.ChoiceField(label=_("Saisine type"), choices=[])
- TYPES = [
- FieldType("saisine_type", models.SaisineType),
- ]
-
- def __init__(self, *args, **kwargs):
- super(FileFormPreventiveType, self).__init__(*args, **kwargs)
- self.fields["permit_type"].choices = models.PermitType.get_types(
- default="NP", initial=self.init_data.get("permit_type")
- )
- self.fields["permit_type"].help_text = models.PermitType.get_help()
-
-
-class FileFormPlanning(CustomForm, ManageOldType):
- form_label = _("Planning")
- form_admin_name = _("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=_("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,
- help_text=_("Only relevant when no town is provided."),
- )
- locality = forms.CharField(label=_("Locality"), max_length=100, required=False)
- address = forms.CharField(
- label=_("Address (number/street)"),
- widget=forms.Textarea(attrs={"placeholder": _("Number/street")}),
- required=False,
- )
- postal_code = forms.CharField(label=_("Postal code"), max_length=10, required=False)
- HEADERS["total_surface"] = FormHeader(_("Surfaces"))
- total_surface = forms.FloatField(
- required=False,
- widget=widgets.AreaWidget,
- label=_("Total surface (m2)"),
- validators=[
- validators.MinValueValidator(0),
- validators.MaxValueValidator(999999999),
- ],
- )
- total_developed_surface = forms.FloatField(
- widget=widgets.AreaWidget,
- label=_("Total developed surface (m2)"),
- required=False,
- validators=[
- validators.MinValueValidator(0),
- validators.MaxValueValidator(999999999),
- ],
- )
-
-
-class FileFormResearchAddress(CustomForm, forms.Form):
- form_label = _("Address")
- form_admin_name = _("Archaeological file - 015 - Research - Address")
- form_slug = "file-015-researchplanning"
- base_models = ["town", "department"]
- associated_models = {"town": Town, "department": Department}
- name = forms.CharField(label=_("Project 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
- )
- locality = forms.CharField(label=_("Locality"), max_length=100, required=False)
- address = forms.CharField(
- label=_("Address (number/street)"),
- widget=forms.Textarea(attrs={"placeholder": _("Number/street")}),
- required=False,
- )
- postal_code = forms.CharField(label=_("Postal code"), max_length=10, required=False)
-
-
-class PersonOrgaForm(forms.Form):
- PERSON_FIELD = "TO BE DEFINED"
- PERSON_TYPE_PK = person_type_pk_lazy("general_contractor")
- PERSON_LABEL = ""
- ORGA_FIELD = "TO BE DEFINED"
- ORGA_TYPE_PK = organization_type_pk_lazy("general_contractor")
- ORGA_LABEL = ""
-
- def _media(self):
- if self.status == "corporation":
- return forms.Media(js=("js/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:
- # 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:
- 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
-
- 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)],
- )
- else:
- self.fields[self.ORGA_FIELD] = forms.IntegerField(
- label=self.ORGA_LABEL,
- required=False,
- initial=initial.get(self.ORGA_FIELD, None),
- widget=widgets.JQueryPersonOrganization(
- reverse_lazy("autocomplete-organization", args=[self.ORGA_TYPE_PK]),
- reverse_lazy("organization_create"),
- model=models.Organization,
- limit={"organization_type": [self.ORGA_TYPE_PK]},
- js_template="ishtar/blocks/JQueryCorporationPerson.js",
- new=True,
- ),
- validators=[valid_id(models.Organization)],
- )
-
-
-class FileFormGeneralContractor(CustomForm, ManageOldType):
- form_label = _("General contractor")
- form_admin_name = _("Archaeological file - 030 - General contractor")
- form_slug = "file-030-generalcontractor"
-
- associated_models = {
- "general_contractor": models.Person,
- "corporation_general_contractor": models.Organization,
- }
-
- corporation_general_contractor = forms.IntegerField(
- label=_("General contractor"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy(
- "autocomplete-organization",
- args=[
- organization_type_pks_lazy(["general_contractor"]),
- ],
- ),
- limit={
- "organization_type": [organization_type_pk_lazy("general_contractor")]
- },
- tips=lazy(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=_("In charge"),
- required=False,
- widget=widgets.JQueryAutoComplete(
- reverse_lazy(
- "autocomplete-person",
- args=[person_type_pks_lazy(["general_contractor"])],
- ),
- associated_model=Person,
- limit={"person_types": [person_type_pk_lazy("general_contractor")]},
- tips=lazy(get_general_contractor_label),
- detail=True,
- modify=True,
- new=True,
- ),
- validators=[valid_id(Person)],
- )
-
- def clean(self):
- general_contractor = self.cleaned_data.get("general_contractor", None)
- corporation_general_contractor = self.cleaned_data.get(
- "corporation_general_contractor", None
- )
- if general_contractor and corporation_general_contractor:
- try:
- person = models.Person.objects.get(pk=general_contractor)
- except models.Person.DoesNotExist:
- raise forms.ValidationError(_("Non existing person."))
- if (
- not person.attached_to
- or 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"
- associated_models = {
- "responsible_town_planning_service": models.Person,
- "planning_service": models.Organization,
- }
-
- planning_service = forms.IntegerField(
- label=_("Planning service"),
- required=False,
- widget=widgets.JQueryAutoComplete(
- reverse_lazy(
- "autocomplete-organization",
- args=[organization_type_pks_lazy(["planning_service"])],
- ),
- associated_model=models.Organization,
- limit={
- "organization_type": [organization_type_pk_lazy(["planning_service"])],
- },
- tips=lazy(get_orga_planning_service_label),
- new=True,
- detail=True,
- modify=True,
- ),
- validators=[valid_id(models.Organization)],
- )
- responsible_town_planning_service = forms.IntegerField(
- label=_("In charge"),
- required=False,
- widget=widgets.JQueryAutoComplete(
- reverse_lazy(
- "autocomplete-person",
- args=[person_type_pks_lazy(["responsible_planning_service"])],
- ),
- associated_model=Person,
- limit={
- "person_types": [person_type_pk_lazy("responsible_planning_service")]
- },
- dynamic_limit=["planning_service"],
- tips=lazy(get_responsible_planning_service_label),
- detail=True,
- modify=True,
- new=True,
- ),
- validators=[valid_id(Person)],
- )
- permit_reference = forms.CharField(
- label=_("File reference"), required=False, max_length=200
- )
- planning_service_date = forms.DateField(
- label=_("Date of planning service file"), widget=DatePicker, required=False
- )
-
- 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 not person.attached_to or 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 = _("Instruction")
- form_admin_name = _("Archaeological file - 050 - Instruction")
- form_slug = "file-050-instruction"
- associated_models = {"in_charge": models.Person, "related_file": models.File}
- in_charge = forms.IntegerField(
- label=_("File managed by"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy(
- "autocomplete-person", args=[person_type_pks_lazy(["sra_agent"])]
- ),
- limit={"person_types": [person_type_pk_lazy("sra_agent")]},
- tips=lazy(get_sra_agent_label),
- 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=_("Comment"), widget=forms.Textarea, required=False)
- instruction_deadline = forms.DateField(widget=DatePicker, required=False)
- year = forms.IntegerField(
- label=_("Year"),
- validators=[
- validators.MinValueValidator(1000),
- validators.MaxValueValidator(2100),
- ],
- )
- numeric_reference = forms.IntegerField(label=_("Numeric reference"), required=False)
- numeric_reference_is_readonly = True
- end_date = forms.DateField(widget=DatePicker, required=False)
-
- def __init__(self, *args, **kwargs):
- c_year = datetime.date.today().year
- if "year" in kwargs:
- c_year = kwargs.pop("year")
- saisine_type = None
- if "saisine_type" in kwargs:
- saisine_type = kwargs.pop("saisine_type")
- reception_date = None
- if "reception_date" in kwargs:
- reception_date = kwargs.pop("reception_date")
- if "data" in kwargs and kwargs["data"]:
- kwargs["data"][kwargs.get("prefix", "") + "-year"] = c_year
-
- super(FileFormInstruction, self).__init__(*args, **kwargs)
- self.fields["year"].initial = c_year
-
- self.fields["year"].widget.attrs.update({"readonly": "readonly"})
- c_num = 0
- q = models.File.objects.filter(
- numeric_reference__isnull=False, year=c_year
- ).order_by("-numeric_reference")
- if q.count():
- c_num = q.all()[0].numeric_reference
- lbl = self.fields["numeric_reference"].label
- self.fields["numeric_reference"].label = mark_safe(lbl)
- self.fields["numeric_reference"].initial = c_num + 1
- if self.numeric_reference_is_readonly:
- self.fields["numeric_reference"].widget.attrs["readonly"] = True
- if reception_date and saisine_type:
- if type(reception_date) == str:
- try:
- reception_date = datetime.datetime.strptime(
- reception_date, "%d/%m/%Y"
- )
- self.fields["instruction_deadline"].initial = (
- reception_date
- + datetime.timedelta(days=saisine_type.delay or 0)
- ).strftime("%Y-%m-%d")
- except ValueError:
- pass
-
- def clean_numeric_reference(self):
- if self.numeric_reference_is_readonly:
- return self.fields["numeric_reference"].initial
- return self.cleaned_data["numeric_reference"]
-
-
-class FileFormInstructionEdit(FileFormInstruction):
- numeric_reference_is_readonly = False
diff --git a/archaeological_files_pdl/templates/ishtar/blocks/JQueryCorporationPerson.js b/archaeological_files_pdl/templates/ishtar/blocks/JQueryCorporationPerson.js
deleted file mode 100644
index 3eb375167..000000000
--- a/archaeological_files_pdl/templates/ishtar/blocks/JQueryCorporationPerson.js
+++ /dev/null
@@ -1,2 +0,0 @@
-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
deleted file mode 100644
index fc4b9a90c..000000000
--- a/archaeological_files_pdl/templates/ishtar/blocks/JQueryNaturalPerson.js
+++ /dev/null
@@ -1,2 +0,0 @@
-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
deleted file mode 100644
index 1877e4579..000000000
--- a/archaeological_files_pdl/templates/ishtar/blocks/JQueryPersonOrga.js
+++ /dev/null
@@ -1,66 +0,0 @@
-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);
- $('#id_{{field_id}}').change();
- } 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 );
- });
-
- $(document).on("click", '#id_select_{{field_id}}', 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/file_confirm_wizard.html b/archaeological_files_pdl/templates/ishtar/wizard/file_confirm_wizard.html
deleted file mode 100644
index 914a5198b..000000000
--- a/archaeological_files_pdl/templates/ishtar/wizard/file_confirm_wizard.html
+++ /dev/null
@@ -1,27 +0,0 @@
-{% extends "ishtar/wizard/confirm_wizard.html" %}
-{% load i18n %}
-
-{% block "warning_informations" %}
-{% for file in numeric_reference_files %}
-{% if forloop.first %}
-<p class='alert'><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> <label>{% trans "The following files have the same numeric index as this file:" %}</label></p>
-<ul>
-{% endif%}
- <li>{{file}} <a href='#' onclick='load_window("{% url 'show-file' file.pk '' %}", "{{model_name}}");' class='display_details'><i class="fa fa-info-circle" aria-hidden="true"></i></a></li>
-{% if forloop.last %}
-</ul>
-<hr/>
-{% endif %}
-{% endfor %}
-{% for file in similar_files %}
-{% if forloop.first %}
-<p class='alert'><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> <label>{% trans "The following files are in the same town and have parcels in common with this file:" %}</label></p>
-<ul>
-{% endif%}
- <li>{{file}} <a href='#' onclick='load_window("{% url 'show-file' file.pk '' %}", "{{model_name}}");' class='display_details'><i class="fa fa-info-circle" aria-hidden="true"></i></a></li>
-{% if forloop.last %}
-</ul>
-<hr/>
-{% endif %}
-{% endfor %}
-{% endblock %}
diff --git a/archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html
deleted file mode 100644
index 34db944aa..000000000
--- a/archaeological_files_pdl/templates/ishtar/wizard/wizard_instruction.html
+++ /dev/null
@@ -1,83 +0,0 @@
-{% extends "ishtar/wizard/default_wizard.html" %}
-{% load i18n range table_form %}
-{% 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 %}
-
- <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 %}
-
-{% block "js_extra_ready" %}
- 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("{% trans 'You must select a closing date.' %}")
- return false;
- }
- return true;
- } else if (state == 'open'){
- return true;
- } else {
- alert("{% trans 'You must select a state for this file.' %}")
- return false;
- }
- return true;
- });
- {% 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
deleted file mode 100644
index 36f1aa4f8..000000000
--- a/archaeological_files_pdl/templates/ishtar/wizard/wizard_person_orga.html
+++ /dev/null
@@ -1,76 +0,0 @@
-{% 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();
- $('#orga-form').show();
- } else {
- $('#natural_div').show();
- $('#corporation_div').hide();
- $('#orga-form').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>
-
-<div>
-{% block otherfields %}
-{% endblock %}
-</div>
-{% block extra_head_po %}
-{% endblock %}
-
-<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/urls.py b/archaeological_files_pdl/urls.py
deleted file mode 100644
index 186135b93..000000000
--- a/archaeological_files_pdl/urls.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python3
-# -*- 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 django.conf.urls import url
-
-from archaeological_files_pdl import views
-
-urlpatterns = [
- 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
deleted file mode 100644
index 717f945cf..000000000
--- a/archaeological_files_pdl/views.py
+++ /dev/null
@@ -1,100 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-# Copyright (C) 2015 É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 ishtar_common.utils import ugettext_lazy as _
-
-from archaeological_files_pdl.wizards import FileWizard, FileModificationWizard
-from archaeological_operations.wizards import is_preventive, is_not_preventive
-
-from ishtar_common.views import OrganizationPersonCreate, OrganizationPersonEdit
-
-from archaeological_files_pdl import forms
-from archaeological_files import forms as ref_forms
-
-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),
- ("preventivetype-file_creation", forms.FileFormPreventiveType),
- ("preventiveplanning-file_creation", forms.FileFormPlanning),
- ("researchaddress-file_creation", forms.FileFormResearchAddress),
- ("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=_("New file"),
- condition_dict={
- "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),
- ("generalcontractor-file_modification", forms.FileFormGeneralContractor),
- ("planningservice-file_modification", forms.FileFormPlanningService),
- ("research-file_modification", ref_forms.FileFormResearch),
- ("instruction-file_modification", forms.FileFormInstructionEdit),
- ("final-file_modification", ref_forms.FinalForm),
- ],
- label=_("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
deleted file mode 100644
index 211ea84f8..000000000
--- a/archaeological_files_pdl/wizards.py
+++ /dev/null
@@ -1,144 +0,0 @@
-#!/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 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-"
- town_step_keys = ["preventiveplanning-", "researchaddress-"]
- town_input_id = "town"
- towns_formset = False
- multi_towns = True
- 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",
- }
- wizard_confirm = "ishtar/wizard/file_confirm_wizard.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-"):
- 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()
- returned["saisine_type"] = self.get_saisine_type()
- returned["reception_date"] = self.session_get_value(
- "general-" + self.url_name, "reception_date"
- )
- return returned
-
- def get_saisine_type(self):
- try:
- idx = int(
- self.session_get_value(
- "preventivetype-" + self.url_name, "saisine_type"
- )
- )
- return models.SaisineType.objects.get(pk=idx)
- except (TypeError, ValueError, models.PermitType.DoesNotExist):
- pass
-
- def get_context_data(self, form, **kwargs):
- context = super(FileWizard, self).get_context_data(form)
- formplanning = "planningservice-" + self.url_name
- forminstruction = "instruction-" + self.url_name
- formfinal = "final-" + self.url_name
- if self.steps.current == formplanning:
- try:
- idx = int(
- self.session_get_value(
- "preventivetype-" + self.url_name, "permit_type"
- )
- )
- permit_type = models.PermitType.objects.get(pk=idx)
- context["permit_type"] = str(permit_type)
- context["permit_type_code"] = str(permit_type.txt_idx)
- except (TypeError, ValueError, models.PermitType.DoesNotExist):
- 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_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 = []
- parcel_step_key = self.parcel_step_key + self.url_name
-
- parcel_numbers = (
- self.session_get_value(parcel_step_key, "parcel_number", multi=True)
- or []
- )
- sections = (
- self.session_get_value(parcel_step_key, "section", multi=True) or []
- )
- towns = (
- self.session_get_value(parcel_step_key, "town", multi=True) or []
- )
- for idx, parcel_number in enumerate(parcel_numbers):
- if not parcel_number or len(sections) <= idx or len(towns) <= idx:
- continue
- parcels.append(
- {
- "town": towns[idx],
- "section": sections[idx],
- "parcel_number": parcel_number,
- }
- )
- context["similar_files"] = models.File.similar_files(parcels)
- else: # edition only
- try:
- numeric_reference = int(
- self.session_get_value(
- "instruction-" + self.url_name, "numeric_reference"
- )
- )
-
- q = models.File.objects.filter(
- numeric_reference=numeric_reference,
- year=self.get_current_year(),
- ).exclude(pk=self.get_current_object().pk)
- context["numeric_reference_files"] = q.all()
- except ValueError:
- pass
-
- return context
-
-
-class FileModificationWizard(FileWizard):
- modification = True