summaryrefslogtreecommitdiff
path: root/archaeological_operations/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/forms.py')
-rw-r--r--archaeological_operations/forms.py184
1 files changed, 56 insertions, 128 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?")