summaryrefslogtreecommitdiff
path: root/archaeological_finds/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds/forms.py')
-rw-r--r--archaeological_finds/forms.py232
1 files changed, 101 insertions, 131 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index 66ba9f8ea..9441e6899 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -21,6 +21,8 @@
Finds forms definitions
"""
+import logging
+
from django import forms
from django.conf import settings
from django.core import validators
@@ -29,21 +31,57 @@ from django.forms.formsets import formset_factory
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
-from ishtar_common.models import Person, valid_id, valid_ids, \
- get_current_profile
+from ishtar_common.models import valid_id, valid_ids, get_current_profile
from archaeological_operations.models import Period, ArchaeologicalSite, \
RelationType as OpeRelationType
from archaeological_context_records.models import DatingType, DatingQuality, \
ContextRecord
-from archaeological_warehouse.models import Warehouse
import models
-from ishtar_common import widgets
-from archaeological_operations.widgets import OAWidget
from ishtar_common.forms import FormSet, FloatField, \
get_form_selection, reverse_lazy, TableSelect, get_now, FinalForm, \
ManageOldType
+
from ishtar_common.forms_common import get_town_field, SourceSelect
+from ishtar_common import widgets
+from archaeological_operations.widgets import OAWidget
+
+from archaeological_finds.forms_treatments import TreatmentSelect, \
+ TreatmentFormSelection, BaseTreatmentForm, TreatmentModifyForm, \
+ AdministrativeActTreatmentForm, TreatmentFormFileChoice, \
+ TreatmentDeletionForm, TreatmentFileSelect, TreatmentFileFormSelection, \
+ TreatmentFileForm, TreatmentFileModifyForm, TreatmentFileDeletionForm, \
+ AdministrativeActTreatmentFormSelection, \
+ AdministrativeActTreatmentModifForm, \
+ AdministrativeActTreatmentFileForm, \
+ AdministrativeActTreatmentFileFormSelection, \
+ AdministrativeActTreatmentFileModifForm, SourceTreatmentFormSelection, \
+ SourceTreatmentFileFormSelection, TreatmentSourceFormSelection, \
+ TreatmentFileSourceFormSelection
+
+__all__ = [
+ 'TreatmentSelect', 'TreatmentFormSelection', 'BaseTreatmentForm',
+ 'TreatmentModifyForm', 'AdministrativeActTreatmentForm',
+ 'TreatmentFormFileChoice', 'TreatmentDeletionForm',
+ 'AdministrativeActTreatmentModifForm', 'TreatmentFileSelect',
+ 'TreatmentFileFormSelection', 'TreatmentFileForm',
+ 'TreatmentFileModifyForm', 'TreatmentFileDeletionForm',
+ 'AdministrativeActTreatmentFileForm',
+ 'AdministrativeActTreatmentFileFormSelection',
+ 'AdministrativeActTreatmentFormSelection',
+ 'AdministrativeActTreatmentFileModifForm', 'SourceTreatmentFormSelection',
+ 'SourceTreatmentFileFormSelection', 'TreatmentSourceFormSelection',
+ 'TreatmentFileSourceFormSelection',
+ 'RecordFormSelection', 'FindForm', 'DateForm', 'DatingFormSet',
+ 'FindSelect', 'FindFormSelection', 'MultipleFindFormSelection',
+ 'FindMultipleFormSelection', 'check_form', 'check_exist', 'check_not_exist',
+ 'check_value', 'check_type_field', 'check_type_not_field',
+ 'check_treatment', 'ResultFindForm', 'ResultFindFormSet',
+ 'FindDeletionForm', 'UpstreamFindFormSelection', 'SourceFindFormSelection',
+ 'FindSourceSelect', 'FindSourceFormSelection', 'NewFindBasketForm',
+ 'SelectFindBasketForm', 'DeleteFindBasketForm', 'FindBasketAddItemForm']
+
+logger = logging.getLogger(__name__)
class RecordFormSelection(forms.Form):
@@ -112,22 +150,29 @@ class FindForm(ManageOldType, forms.Form):
model=models.ObjectType, label=_(u"Object types"), required=False)
preservation_to_consider = forms.MultipleChoiceField(
label=_(u"Preservation type"), choices=[],
- widget=forms.CheckboxSelectMultiple, required=False)
+ widget=widgets.CheckboxSelectMultiple, required=False)
integritie = forms.MultipleChoiceField(
label=_(u"Integrity / interest"), choices=[],
- widget=forms.CheckboxSelectMultiple, required=False)
+ widget=widgets.CheckboxSelectMultiple, required=False)
remarkabilitie = forms.MultipleChoiceField(
label=_(u"Remarkability"), choices=[],
- widget=forms.CheckboxSelectMultiple, required=False)
+ widget=widgets.CheckboxSelectMultiple, required=False)
+ topographic_reference_point = forms.CharField(
+ label=_(u"Point of topographic reference"),
+ required=False, max_length=20
+ )
length = FloatField(label=_(u"Length (cm)"), required=False)
width = FloatField(label=_(u"Width (cm)"), required=False)
height = FloatField(label=_(u"Height (cm)"), required=False)
diameter = FloatField(label=_(u"Diameter (cm)"), required=False)
+ thickness = FloatField(label=_(u"Thickness (cm)"), required=False)
volume = FloatField(label=_(u"Volume (l)"), required=False)
weight = FloatField(label=_(u"Weight (g)"), required=False)
dimensions_comment = forms.CharField(
label=_(u"Dimensions comment"), required=False, widget=forms.Textarea)
find_number = forms.IntegerField(label=_(u"Find number"), required=False)
+ min_number_of_individuals = forms.IntegerField(
+ label=_(u"Minimum number of individuals (MNI)"), required=False)
mark = forms.CharField(label=_(u"Mark"), required=False)
checked = forms.ChoiceField(label=_(u"Check"))
check_date = forms.DateField(
@@ -227,14 +272,14 @@ class FindSelect(TableSelect):
widget=OAWidget
)
archaeological_sites = forms.IntegerField(
- label=_("Archaelogical site"),
+ label=_("Archaeological site"),
widget=widgets.JQueryAutoComplete(
reverse_lazy('autocomplete-archaeologicalsite'),
associated_model=ArchaeologicalSite),
validators=[valid_id(ArchaeologicalSite)])
ope_relation_types = forms.MultipleChoiceField(
- label=_(u"Search within operation relations"), choices=[],
- widget=forms.CheckboxSelectMultiple)
+ label=_(u"Search within related operations"), choices=[],
+ widget=widgets.CheckboxSelectMultiple)
datings__period = forms.ChoiceField(label=_(u"Period"), choices=[])
# TODO search by warehouse
material_types = forms.ChoiceField(label=_(u"Material type"), choices=[])
@@ -338,15 +383,23 @@ class FindMultipleFormSelection(forms.Form):
return self.cleaned_data
+def check_form(wizard, form_name, key):
+ request = wizard.request
+ storage = wizard.storage
+ if storage.prefix not in request.session or \
+ 'step_data' not in request.session[storage.prefix] or \
+ form_name not in request.session[storage.prefix]['step_data'] or \
+ form_name + '-' + key not in \
+ request.session[storage.prefix]['step_data'][form_name]:
+ return False
+ return True
+
+
def check_exist(form_name, key):
def func(self):
request = self.request
storage = self.storage
- if storage.prefix not in request.session or \
- 'step_data' not in request.session[storage.prefix] or \
- form_name not in request.session[storage.prefix]['step_data'] or\
- form_name + '-' + key not in \
- request.session[storage.prefix]['step_data'][form_name]:
+ if not check_form(self, form_name, key):
return False
try:
val = request.session[storage.prefix][
@@ -365,15 +418,28 @@ def check_not_exist(form_name, key):
return func
+def check_value(form_name, key, value):
+ def func(self):
+ request = self.request
+ storage = self.storage
+ if not check_form(self, form_name, key):
+ return False
+ try:
+ val = request.session[storage.prefix][
+ 'step_data'][form_name][form_name + '-' + key]
+ if val and len(val) > 0:
+ val = val[0]
+ return unicode(val) == unicode(value)
+ except ValueError:
+ return False
+ return func
+
+
def check_type_field(form_name, key, model, field):
def func(self):
request = self.request
storage = self.storage
- if storage.prefix not in request.session or \
- 'step_data' not in request.session[storage.prefix] or \
- form_name not in request.session[storage.prefix]['step_data'] or\
- form_name + '-' + key not in \
- request.session[storage.prefix]['step_data'][form_name]:
+ if not check_form(self, form_name, key):
return False
try:
val = model.objects.get(pk=request.session[storage.prefix][
@@ -399,11 +465,7 @@ def check_treatment(form_name, type_key, type_list=[], not_type_list=[]):
def func(self):
request = self.request
storage = self.storage
- if storage.prefix not in request.session or \
- 'step_data' not in request.session[storage.prefix] or \
- form_name not in request.session[storage.prefix]['step_data'] or\
- form_name + '-' + type_key not in \
- request.session[storage.prefix]['step_data'][form_name]:
+ if not check_form(self, form_name, type_key):
return False
try:
tpe = request.session[storage.prefix][
@@ -453,10 +515,12 @@ class UpstreamFindFormSelection(FindFormSelection):
def __init__(self, *args, **kwargs):
super(UpstreamFindFormSelection, self).__init__(*args, **kwargs)
self.fields['pk'].required = True
+ self.fields['resulting_pk'] = self.fields.pop('pk')
-#############################################
-# Source management for archaelogical finds #
-#############################################
+
+##############################################
+# Source management for archaeological finds #
+##############################################
SourceFindFormSelection = get_form_selection(
'SourceFindFormSelection', _(u"Archaeological find search"), 'find',
@@ -475,11 +539,11 @@ class FindSourceSelect(SourceSelect):
widget=OAWidget,
label="Code PATRIARCHE")
find__datings__period = forms.ChoiceField(
- label=_(u"Period of the archaelogical find"), choices=[])
+ label=_(u"Period of the archaeological find"), choices=[])
find__material_type = forms.ChoiceField(
- label=_("Material type of the archaelogical find"), choices=[])
+ label=_("Material type of the archaeological find"), choices=[])
find__description = forms.CharField(
- label=_(u"Description of the archaelogical find"))
+ label=_(u"Description of the archaeological find"))
def __init__(self, *args, **kwargs):
super(FindSourceSelect, self).__init__(*args, **kwargs)
@@ -510,7 +574,7 @@ class NewFindBasketForm(forms.ModelForm):
q = models.FindBasket.objects.filter(user=self.user,
label=self.cleaned_data['label'])
if q.count():
- raise forms.ValidationError(_(u"Another basket already exist with "
+ raise forms.ValidationError(_(u"Another basket already exists with "
u"this name."))
return self.cleaned_data
@@ -520,6 +584,10 @@ class NewFindBasketForm(forms.ModelForm):
class SelectFindBasketForm(forms.Form):
+ form_label = _(u"Basket")
+ associated_models = {'basket': models.FindBasket}
+ need_user_for_initialization = True
+
basket = forms.ChoiceField(label=_(u"Basket"), required=True, choices=[])
def __init__(self, *args, **kwargs):
@@ -567,101 +635,3 @@ class FindBasketAddItemForm(forms.Form):
raise PermissionDenied
basket.items.add(item)
return basket
-
-
-class BaseTreatmentForm(ManageOldType, SelectFindBasketForm):
- form_label = _(u"Base treatment")
- associated_models = {'treatment_type': models.TreatmentType,
- 'person': Person,
- 'location': Warehouse,
- 'basket': models.FindBasket}
- treatment_type = forms.ChoiceField(label=_(u"Treatment type"), choices=[])
- person = forms.IntegerField(
- label=_(u"Doer"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy('autocomplete-person'), associated_model=Person,
- new=True),
- validators=[valid_id(Person)])
- location = forms.IntegerField(
- label=_(u"Location"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy('autocomplete-warehouse'), associated_model=Warehouse,
- new=True),
- validators=[valid_id(Warehouse)])
- description = forms.CharField(label=_(u"Description"),
- widget=forms.Textarea, required=False)
- start_date = forms.DateField(label=_(u"Start date"), required=False,
- widget=widgets.JQueryDate)
- end_date = forms.DateField(label=_(u"End date"), required=False,
- widget=widgets.JQueryDate)
-
- def __init__(self, *args, **kwargs):
- super(BaseTreatmentForm, self).__init__(*args, **kwargs)
- self.fields['treatment_type'].choices = models.TreatmentType.get_types(
- initial=self.init_data.get('treatment_type'),
- exclude=['packaging'])
- self.fields['treatment_type'].help_text = \
- models.TreatmentType.get_help(exclude=['packaging'])
- self.fields['basket'].required = False
- self.fields['basket'].help_text = \
- _(u"Leave it blank if you want to select a single item")
-
- def clean(self, *args, **kwargs):
- try:
- treatment = models.TreatmentType.objects.get(
- pk=self.cleaned_data['treatment_type'], available=True)
- except models.TreatmentType.DoesNotExist:
- raise forms.ValidationError(_(u"This treatment type is not "
- u"available."))
- if treatment.upstream_is_many and \
- not self.cleaned_data.get('basket'):
- raise forms.ValidationError(_(u"This treatment needs a basket."))
- return self.cleaned_data
-
-"""
-####################################
-# Source management for treatments #
-####################################
-
-SourceTreatementFormSelection = get_form_selection(
- 'SourceTreatmentFormSelection', _(u"Treatment search"), 'operation',
- models.Treatment, TreatmentSelect, 'get-treatment',
- _(u"You should select a treatment."))
-
-class TreatmentSourceSelect(SourceSelect):
- operation__towns = get_town_field(label=_(u"Operation's town"))
- treatment__treatment_type = forms.ChoiceField(label=_(u"Operation type"),
- choices=[])
- operation__year = forms.IntegerField(label=_(u"Operation's year"))
-
- def __init__(self, *args, **kwargs):
- super(OperationSourceSelect, self).__init__(*args, **kwargs)
- self.fields['operation__operation_type'].choices = \
- OperationType.get_types()
- self.fields['operation__operation_type'].help_text = \
- OperationType.get_help()
-
-"""
-
-"""
-OperationSourceFormSelection = get_form_selection(
- 'OperationSourceFormSelection', _(u"Documentation search"), 'pk',
- models.OperationSource, OperationSourceSelect, 'get-operationsource',
- _(u"You should select a document."))
-
-operation_source_modification_wizard = OperationSourceWizard([
- ('selec-operation_source_modification', OperationSourceFormSelection),
- ('source-operation_source_modification', SourceForm),
- ('authors-operation_source_modification', AuthorFormset),
- ('final-operation_source_modification', FinalForm)],
- url_name='operation_source_modification',)
-
-class OperationSourceDeletionWizard(DeletionWizard):
- model = models.OperationSource
- fields = ['operation', 'title', 'source_type', 'authors',]
-
-operation_source_deletion_wizard = OperationSourceDeletionWizard([
- ('selec-operation_source_deletion', OperationSourceFormSelection),
- ('final-operation_source_deletion', SourceDeletionForm)],
- url_name='operation_source_deletion',)
-"""