summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_operations/forms.py184
-rw-r--r--archaeological_operations/views.py32
-rw-r--r--archaeological_operations/wizards.py103
-rw-r--r--ishtar_common/wizards.py9
4 files changed, 64 insertions, 264 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index caa19a1fb..6b5bfbd51 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -673,15 +673,6 @@ class OperationFormFileChoice(IshtarForm):
validators=[valid_id(File)], required=False)
-class OperationFormAbstract(CustomForm, IshtarForm):
- form_label = _("Abstract")
- form_admin_name = _("Operation - 090 - Abstract")
- form_slug = "operation-090-abstract"
- abstract = forms.CharField(
- label=_("Abstract"),
- widget=forms.Textarea(attrs={'class': 'xlarge'}), required=False)
-
-
SLICING = (("month", _("months")), ('year', _("years")),)
DATE_SOURCE = (('creation', _("Creation date")),
@@ -767,6 +758,13 @@ class OperationFormGeneral(CustomForm, ManageOldType):
form_slug = "operation-010-general"
file_upload = True
+ base_models = [
+ "archaeological_site",
+ "collaborator",
+ "period",
+ "town",
+ "remain",
+ ]
associated_models = {
'scientist': Person,
'in_charge': Person,
@@ -775,8 +773,13 @@ class OperationFormGeneral(CustomForm, ManageOldType):
'operation_type': models.OperationType,
'record_quality_type': models.RecordQualityType,
'report_processing': models.ReportState,
- 'spatial_reference_system': SpatialReferenceSystem,
+ 'collaborator': Person,
+ 'remain': models.RemainType,
+ 'period': models.Period,
+ 'archaeological_site': models.ArchaeologicalSite,
+ 'town': Town,
}
+ HEADERS['code_patriarche'] = FormHeader(_("General"))
pk = forms.IntegerField(required=False, widget=forms.HiddenInput)
code_patriarche = forms.CharField(label="Code PATRIARCHE",
max_length=500,
@@ -790,6 +793,13 @@ class OperationFormGeneral(CustomForm, ManageOldType):
max_length=500, widget=forms.Textarea)
address = forms.CharField(label=_("Address / Locality"), required=False,
max_length=500, widget=forms.Textarea)
+ town = widgets.Select2MultipleField(
+ label=_("Towns"),
+ model=Town,
+ required=False, remote=True)
+ archaeological_site = widgets.Select2MultipleField(
+ model=models.ArchaeologicalSite,
+ required=False, remote=True)
year = forms.IntegerField(label=_("Year"),
initial=lambda: datetime.datetime.now().year,
validators=[validators.MinValueValidator(1000),
@@ -797,6 +807,16 @@ class OperationFormGeneral(CustomForm, ManageOldType):
old_code = forms.CharField(
label=_("Old code"), required=False,
validators=[validators.MaxLengthValidator(200)])
+ surface = forms.FloatField(
+ required=False, widget=widgets.AreaWidget,
+ label=_("Total surface (m2)"),
+ validators=[validators.MinValueValidator(0),
+ validators.MaxValueValidator(999999999)])
+ virtual_operation = forms.BooleanField(required=False,
+ label=_("Virtual operation"))
+ comment = forms.CharField(label=_("Comment"), widget=forms.Textarea,
+ required=False)
+ HEADERS['scientist'] = FormHeader(_("Actors"))
scientist = forms.IntegerField(
label=_("Head scientist"),
widget=widgets.JQueryAutoComplete(
@@ -832,11 +852,9 @@ class OperationFormGeneral(CustomForm, ManageOldType):
limit={'person_types': [person_type_pk_lazy('sra_agent')]},
new=True),
validators=[valid_id(Person)], required=False)
- surface = forms.FloatField(
- required=False, widget=widgets.AreaWidget,
- label=_("Total surface (m2)"),
- validators=[validators.MinValueValidator(0),
- validators.MaxValueValidator(999999999)])
+ collaborator = widgets.Select2MultipleField(
+ model=Person, label=_("Collaborators"), required=False, remote=True)
+ HEADERS['start_date'] = FormHeader(_("Dates / Administrative"))
start_date = DateField(label=_("Start date"), required=False)
excavation_end_date = DateField(label=_("Excavation end date"),
required=False)
@@ -872,28 +890,21 @@ class OperationFormGeneral(CustomForm, ManageOldType):
finds_received = forms.NullBooleanField(
required=False, label=_("Finds received"))
- comment = forms.CharField(label=_("Comment"), widget=forms.Textarea,
- required=False)
+ HEADERS['scientific_documentation_comment'] = FormHeader(_("Scientific"))
scientific_documentation_comment = forms.CharField(
label=_("Comment about scientific documentation"),
widget=forms.Textarea, required=False)
record_quality_type = forms.ChoiceField(label=_("Record quality"),
required=False)
- virtual_operation = forms.BooleanField(required=False,
- label=_("Virtual operation"))
-
- HEADERS['x'] = FormHeader(_("Coordinates"))
- x = forms.FloatField(label=_("X"), required=False)
- estimated_error_x = forms.FloatField(label=_("Estimated error for X"),
- required=False)
- y = forms.FloatField(label=_("Y"), required=False)
- estimated_error_y = forms.FloatField(label=_("Estimated error for Y"),
- required=False)
- z = forms.FloatField(label=_("Z"), required=False)
- estimated_error_z = forms.FloatField(label=_("Estimated error for Z"),
- required=False)
- spatial_reference_system = forms.ChoiceField(
- label=_("Spatial Reference System"), required=False, choices=[])
+ remain = widgets.Select2MultipleField(
+ label=_("Remain type"), required=False
+ )
+ period = widgets.Select2MultipleField(
+ label=_("Period"), required=False
+ )
+ abstract = forms.CharField(
+ label=_("Abstract"),
+ widget=forms.Textarea(attrs={'class': 'xlarge'}), required=False)
FILE_FIELDS = [
'report_delivery_date',
@@ -902,17 +913,6 @@ class OperationFormGeneral(CustomForm, ManageOldType):
'cira_date',
'negative_result'
]
- PROFILE_FILTER = {
- 'mapping': [
- 'x',
- 'y',
- 'z',
- 'estimated_error_x',
- 'estimated_error_y',
- 'estimated_error_z',
- 'spatial_reference_system'
- ],
- }
WAREHOUSE_FIELDS = [
'documentation_deadline',
'documentation_received',
@@ -924,9 +924,14 @@ class OperationFormGeneral(CustomForm, ManageOldType):
FieldType('record_quality_type', models.RecordQualityType),
FieldType('report_processing', models.ReportState),
FieldType('spatial_reference_system', SpatialReferenceSystem),
+ FieldType('remain', models.RemainType, is_multiple=True),
+ FieldType('period', models.Period, is_multiple=True),
]
def __init__(self, *args, **kwargs):
+ towns = None
+ if kwargs.get("data", None) and kwargs['data'].get("TOWNS", None):
+ towns = kwargs['data']['TOWNS']
super(OperationFormGeneral, self).__init__(*args, **kwargs)
profile = get_current_profile()
if not profile.files:
@@ -937,6 +942,12 @@ class OperationFormGeneral(CustomForm, ManageOldType):
self.remove_field(key)
if not profile.underwater:
self.fields.pop('drassm_code')
+ if 'collaborator' in self.fields:
+ self.fields['collaborator'].widget.attrs['full-width'] = True
+ if towns and towns != -1:
+ self.fields['town'].choices = [('', '--')] + towns
+ if 'archaeological_site' in self.fields:
+ self.fields['archaeological_site'].label = get_current_profile().get_site_label()
def clean(self):
cleaned_data = self.cleaned_data
@@ -1010,11 +1021,11 @@ class OperationFormModifGeneral(OperationFormGeneral):
for idx, field in enumerate(list(self.fields.items())):
key, value = field
if 'associated_file' in self.fields and (
- key == 'in_charge' or idx > 6):
+ key == 'in_charge' or idx > 8):
fields['associated_file'] = self.fields.pop('associated_file')
fields[key] = value
if 'operation_code' in self.fields and (
- key == 'year' or idx > 5):
+ key == 'year' or idx > 7):
fields['operation_code'] = self.fields.pop('operation_code')
self.fields = fields
@@ -1061,22 +1072,6 @@ class CourtOrderedSeizureForm(CustomForm, IshtarForm):
)
-class CollaboratorForm(CustomForm, IshtarForm):
- form_label = _("Collaborators")
- form_admin_name = _("Operation - 020 - Collaborators")
- form_slug = "operation-020-collaborators"
-
- base_models = ['collaborator']
- associated_models = {'collaborator': Person, }
- collaborator = widgets.Select2MultipleField(
- model=Person, label=_("Collaborators"), required=False, remote=True)
-
- def __init__(self, *args, **kwargs):
- super(CollaboratorForm, self).__init__(*args, **kwargs)
- if 'collaborator' in self.fields:
- self.fields['collaborator'].widget.attrs['full-width'] = True
-
-
class OperationFormPreventive(CustomForm, IshtarForm):
form_label = _("Preventive informations - excavation")
form_admin_name = _("Operation - 033 - Preventive - Excavation")
@@ -1192,38 +1187,6 @@ class SelectedParcelFormSet(forms.Form):
"""
-class RemainForm(CustomForm, ManageOldType, forms.Form):
- form_label = _("Remain types")
- form_admin_name = _("Operation - 060 - Remains")
- form_slug = "operation-060-remains"
-
- base_model = 'remain'
- associated_models = {'remain': models.RemainType}
- remain = widgets.Select2MultipleField(
- label=_("Remain type"), required=False
- )
-
- TYPES = [
- FieldType('remain', models.RemainType, True),
- ]
-
-
-class PeriodForm(CustomForm, ManageOldType, forms.Form):
- form_label = _("Periods")
- form_admin_name = _("Operation - 070 - Periods")
- form_slug = "operation-070-periods"
-
- base_model = 'period'
- associated_models = {'period': models.Period}
- period = widgets.Select2MultipleField(
- label=_("Period"), required=False
- )
-
- TYPES = [
- FieldType('period', models.Period, True),
- ]
-
-
class ArchaeologicalSiteForm(ManageOldType):
associated_models = {'period': models.Period, 'remain': models.RemainType,
'cultural_attribution': models.CulturalAttributionType,
@@ -1326,41 +1289,6 @@ class ArchaeologicalSiteForm(ManageOldType):
return item
-class ArchaeologicalSiteBasicForm(widgets.Select2Media, IshtarForm):
- form_label = _("Archaeological site")
- base_model = 'archaeological_site'
- associated_models = {'archaeological_site': models.ArchaeologicalSite}
- archaeological_site = forms.IntegerField(
- label=_("Archaeological site"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy('autocomplete-archaeologicalsite'),
- associated_model=models.ArchaeologicalSite,
- new=True),
- validators=[valid_id(models.ArchaeologicalSite)],
- required=False)
- SITE_KEYS = {"archaeological_site": None}
-
-
-ArchaeologicalSiteFormSet = formset_factory(
- ArchaeologicalSiteBasicForm, can_delete=True, formset=FormSet)
-ArchaeologicalSiteFormSet.form_label = _("Archaeological sites")
-ArchaeologicalSiteFormSet.form_admin_name = _(
- "Operation - 030 - Archaeological sites")
-ArchaeologicalSiteFormSet.form_slug = "operation-030-archaeological-sites"
-ArchaeologicalSiteFormSet.extra_form_modals = ["archaeologicalsite"]
-
-
-class ArchaeologicalSiteSelectionForm(IshtarForm):
- # TODO: used?
- form_label = _("Associated archaeological sites")
- archaeological_sites = forms.IntegerField(
- widget=widgets.JQueryAutoComplete(
- reverse_lazy('autocomplete-archaeologicalsite'),
- associated_model=models.ArchaeologicalSite, new=True,
- multiple=True),
- label=_("Search"))
-
-
class FinalOperationClosingForm(FinalForm):
confirm_msg = " "
confirm_end_msg = _("Would you like to close this operation?")
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 468a864b8..d3bccb635 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -210,16 +210,9 @@ wizard_steps = [
("filechoice-operation_creation", forms.OperationFormFileChoice),
("general-operation_creation", forms.OperationFormGeneral),
("judiciary-operation_creation", forms.CourtOrderedSeizureForm),
- ("collaborators-operation_creation", forms.CollaboratorForm),
- ("archaeologicalsite-operation_creation", forms.ArchaeologicalSiteFormSet),
("preventive-operation_creation", forms.OperationFormPreventive),
("preventivediag-operation_creation", forms.OperationFormPreventiveDiag),
- ("townsgeneral-operation_creation", forms.TownFormset),
- ("towns-operation_creation", forms.SelectedTownFormset),
- ("remains-operation_creation", forms.RemainForm),
- ("periods-operation_creation", forms.PeriodForm),
("relations-operation_creation", forms.RecordRelationsFormSet),
- ("abstract-operation_creation", forms.OperationFormAbstract),
("final-operation_creation", FinalForm),
]
@@ -263,12 +256,6 @@ ope_crea_condition_dict = {
"arch_diagnostic",
)
),
- "townsgeneral-operation_creation": wizards.has_associated_file(
- "filechoice-operation_creation", negate=True
- ),
- "towns-operation_creation": wizards.has_associated_file(
- "filechoice-operation_creation"
- ),
"parcelsgeneral-operation_creation": wizards.has_associated_file(
"filechoice-operation_creation", negate=True
), # TODO: AFAC
@@ -288,16 +275,9 @@ operation_modif_wizard_steps = [
("selec-operation_modification", forms.OperationFormSelection),
("general-operation_modification", forms.OperationFormModifGeneral),
("judiciary-operation_modification", forms.CourtOrderedSeizureForm),
- ("collaborators-operation_modification", forms.CollaboratorForm),
- ("archaeologicalsite-operation_modification", forms.ArchaeologicalSiteFormSet),
("preventive-operation_modification", forms.OperationFormPreventive),
("preventivediag-operation_modification", forms.OperationFormPreventiveDiag),
- ("towns-operation_modification", forms.SelectedTownFormset),
- ("townsgeneral-operation_modification", forms.TownFormset),
- ("remains-operation_modification", forms.RemainForm),
- ("periods-operation_modification", forms.PeriodForm),
("relations-operation_modification", forms.RecordRelationsFormSet),
- ("abstract-operation_modification", forms.OperationFormAbstract),
("final-operation_modification", FinalForm),
]
@@ -324,18 +304,6 @@ ope_modif_condition_dict = {
models.OperationType,
"operation_type",
),
- "townsgeneral-operation_modification": wizards.has_associated_file(
- "general-operation_modification", negate=True
- ),
- "towns-operation_modification": wizards.has_associated_file(
- "general-operation_modification"
- ),
- "parcelsgeneral-operation_modification": wizards.has_associated_file(
- "general-operation_modification", negate=True
- ), # TODO: AFAC
- "parcels-operation_modification": wizards.has_associated_file(
- "general-operation_modification"
- ), # TODO: AFAC
}
operation_modification_wizard = wizards.OperationModificationWizard.as_view(
diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py
index 7afe73442..44b3988eb 100644
--- a/archaeological_operations/wizards.py
+++ b/archaeological_operations/wizards.py
@@ -48,8 +48,6 @@ class OperationSearch(SearchWizard):
class OperationWizard(Wizard):
model = models.Operation
- object_parcel_type = "operation"
- parcel_step_key = "parcels"
relations_step_key = "relations"
# step including the current(s) town(s)
town_step_keys = ["towns-", "townsgeneral-"]
@@ -62,9 +60,7 @@ class OperationWizard(Wizard):
def get_template_names(self):
templates = super(OperationWizard, self).get_template_names()
current_step = self.steps.current
- if current_step.startswith(self.parcel_step_key):
- templates = ["ishtar/wizard/parcels_wizard.html"] + templates
- elif current_step.startswith(self.relations_step_key):
+ if current_step.startswith(self.relations_step_key):
templates = ["ishtar/wizard/relations_wizard.html"] + templates
return templates
@@ -94,13 +90,8 @@ class OperationWizard(Wizard):
"""
context = super(OperationWizard, self).get_context_data(form, **kwargs)
step = self.steps.current
- if step.startswith("towns"):
+ if step.startswith("general"):
context["TOWNS"] = self.get_towns()
- elif step.startswith("parcels-") and self.get_current_file():
- # if a file is associated to the operation add the button "Add all"
- context["add_all"] = True
- if step.startswith("parcels") and hasattr(self, "automatic_parcel_association"):
- context["automatic_parcel_association"] = self.automatic_parcel_association
# reminder of the current file
reminder = self.get_reminder()
if reminder:
@@ -121,31 +112,6 @@ class OperationWizard(Wizard):
pass
return sorted(towns, key=lambda x: x[1])
- def get_available_parcels(self, file):
- self.automatic_parcel_association = False
- parcels = []
- current_parcels = []
- operation = self.get_current_object()
- if operation:
- for parcel in operation.parcels.all():
- current_parcels.append(
- (parcel.town, parcel.section, parcel.parcel_number)
- )
- parcels.append((parcel.pk, parcel.short_label))
- try:
- for parcel in file.parcels.all():
- key = (parcel.town, parcel.section, parcel.parcel_number)
- if key in current_parcels:
- current_parcels.pop(current_parcels.index(key))
- continue
- parcels.append((parcel.pk, parcel.short_label))
- if current_parcels:
- # not all operation parcel exist for the file
- self.automatic_parcel_association = True
- except (ValueError, ObjectDoesNotExist):
- pass
- return sorted(parcels, key=lambda x: x[1])
-
def get_form(self, step=None, data=None, files=None):
"""
Manage specifics fields
@@ -163,43 +129,6 @@ class OperationWizard(Wizard):
# manage the dynamic choice of towns
if step.startswith("towns") and hasattr(form, "management_form"):
data["TOWNS"] = self.get_towns()
- elif step.startswith(self.parcel_step_key) and hasattr(form, "management_form"):
- file = self.get_current_file()
- if file:
- data["PARCELS"] = self.get_available_parcels(file)
- else:
- town_ids = []
- for town_step_key in self.town_step_keys:
- town_form_key = town_step_key + self.url_name
- town_ids = (
- self.session_get_value(
- town_form_key,
- self.town_input_id,
- multi=self.towns_formset,
- multi_value=self.multi_towns,
- )
- or []
- )
- if town_ids:
- towns = []
- if type(town_ids) == str:
- town_ids = [town_ids]
- for ids in town_ids:
- for d in ids.split(","):
- if d:
- towns.append(d)
- town_ids = towns
- break
- if type(town_ids) not in (list, tuple):
- town_ids = [town_ids]
- towns = []
- for town_id in town_ids:
- try:
- town = models.Town.objects.get(pk=int(town_id))
- towns.append((town.pk, str(town)))
- except (ValueError, ObjectDoesNotExist):
- pass
- data["TOWNS"] = sorted(towns, key=lambda x: x[1])
data = data or None
form = super(OperationWizard, self).get_form(step, data, files)
return form
@@ -267,34 +196,6 @@ class OperationWizard(Wizard):
initial.update(self.__copy_fields(file, keys))
return initial
- def post(self, *args, **kwargs):
- request = self.request
- post_data = request.POST.copy()
-
- # add all parcel from available in the archaeological file
- if not post_data.get("add_all_parcels", None):
- return super(OperationWizard, self).post(*args, **kwargs)
-
- file = self.get_current_file()
- if not file:
- return super(OperationWizard, self).post(*args, **kwargs)
- parcel_form_key = self.steps.current
- # parcel_form_key = "parcels-" + self.url_name
- idx = -1
- # remove non relevant deleted keys
- for k in post_data.keys():
- if k.startswith(parcel_form_key) and k.endswith("-DELETE"):
- post_data.pop(k)
- for idx, parcel in enumerate(self.get_available_parcels(file)):
- parcel_pk, parcel_name = parcel
- post_data["%s-%d-parcel" % (parcel_form_key, idx)] = parcel_pk
- post_data[parcel_form_key + "-TOTAL_FORMS"] = idx + 2
- request.POST = post_data
- return super(OperationWizard, self).post(*args, **kwargs)
-
- def post_save(self):
- self.current_object.clean_parcel_duplicates()
-
class OperationModificationWizard(OperationWizard):
modification = True
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index ba3eb4556..6e4e8544f 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -837,6 +837,7 @@ class Wizard(IshtarWizard):
else:
for r in related_model.all():
r.delete()
+ need_update = False
for key, value in m2m:
related_model = getattr(obj, key + "s")
related_data = {} # used for intermediary models
@@ -871,6 +872,7 @@ class Wizard(IshtarWizard):
else:
m2m_items[key] = related_model.all()
if value not in m2m_items[key]:
+ need_update = True
if type(value) == dict:
model = related_model.model
if (
@@ -1016,9 +1018,10 @@ class Wizard(IshtarWizard):
related_model.add(value)
# necessary to manage interaction between models like
# material_index management for baseitems
- obj._cached_label_checked = False
- obj._post_saved_geo = False
- obj.save()
+ if need_update:
+ obj = self.model.objects.get(pk=obj.pk)
+ obj.skip_history_when_saving = True
+ obj.save()
# force post_save for old related m2ms (which can have been detached
# from the current object)