summaryrefslogtreecommitdiff
path: root/archaeological_finds/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-09-09 20:04:26 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2015-09-09 20:04:26 +0200
commitb6f2dfaeca2bd8e507333b299985e1e3386f6689 (patch)
tree7c7a7a01a5cf2be00a3e737341d65c18d264e7a7 /archaeological_finds/forms.py
parent9fefb173a1c5a76df73dc5d5c94dcdb6f303990a (diff)
downloadIshtar-b6f2dfaeca2bd8e507333b299985e1e3386f6689.tar.bz2
Ishtar-b6f2dfaeca2bd8e507333b299985e1e3386f6689.zip
Add many fields to finds - associated migrations, forms and autocomplete view (refs #2784)
Diffstat (limited to 'archaeological_finds/forms.py')
-rw-r--r--archaeological_finds/forms.py171
1 files changed, 103 insertions, 68 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index 65a1570d8..82c32b2dc 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2010-2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2010-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
@@ -43,43 +43,59 @@ from ishtar_common.forms_common import get_town_field, SourceSelect
class FindForm(forms.Form):
file_upload = True
form_label = _("Find")
- base_model = 'base_finds'
- associated_models = {'material_type':models.MaterialType,
- 'conservatory_state':models.ConservatoryState}
- label = forms.CharField(label=_(u"ID"),
- validators=[validators.MaxLengthValidator(60)])
+ base_models = ['base_finds', 'object_type']
+ associated_models = {'material_type': models.MaterialType,
+ 'conservatory_state': models.ConservatoryState,
+ 'object_type': models.ObjectType}
+ label = forms.CharField(
+ label=_(u"ID"), validators=[validators.MaxLengthValidator(60)])
description = forms.CharField(label=_("Description"),
- widget=forms.Textarea)
- base_finds__is_isolated = forms.NullBooleanField(label=_(u"Is isolated?"),
+ widget=forms.Textarea, required=False)
+ base_finds__is_isolated = forms.NullBooleanField(
+ label=_(u"Is isolated?"), required=False)
+ is_complete = forms.NullBooleanField(label=_(u"Is complete?"),
required=False)
material_type = forms.ChoiceField(label=_("Material type"), choices=[])
conservatory_state = forms.ChoiceField(label=_(u"Conservatory state"),
choices=[], required=False)
+ object_type = widgets.MultipleAutocompleteField(
+ model=models.ObjectType,
+ label=_("Object types"), required=False)
+ 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)
volume = FloatField(label=_(u"Volume (l)"), required=False)
weight = FloatField(label=_(u"Weight (g)"), required=False)
find_number = forms.IntegerField(label=_(u"Find number"), required=False)
- image = forms.ImageField(label=_(u"Image"), help_text=mark_safe(
- _(u"<p>Heavy images are resized to: %(width)dx%(height)d "
- u"(ratio is preserved).</p>") % {
- 'width':settings.IMAGE_MAX_SIZE[0],
- 'height':settings.IMAGE_MAX_SIZE[1]}),
- required=False, widget=widgets.ImageFileInput())
+ mark = forms.CharField(label=_("Mark"), required=False)
+ comment = forms.CharField(label=_("Comment"), required=False,
+ widget=forms.Textarea)
+ previous_id = forms.CharField(label=_("Previous ID"), required=False)
+ image = forms.ImageField(
+ label=_(u"Image"), help_text=mark_safe(
+ _(u"<p>Heavy images are resized to: %(width)dx%(height)d "
+ u"(ratio is preserved).</p>") % {
+ 'width': settings.IMAGE_MAX_SIZE[0],
+ 'height': settings.IMAGE_MAX_SIZE[1]}),
+ required=False, widget=widgets.ImageFileInput())
def __init__(self, *args, **kwargs):
super(FindForm, self).__init__(*args, **kwargs)
self.fields['material_type'].choices = models.MaterialType.get_types()
self.fields['material_type'].help_text = models.MaterialType.get_help()
self.fields['conservatory_state'].choices = \
- models.ConservatoryState.get_types()
+ models.ConservatoryState.get_types()
self.fields['conservatory_state'].help_text = \
- models.ConservatoryState.get_help()
+ models.ConservatoryState.get_help()
+
class DateForm(forms.Form):
form_label = _("Dating")
base_model = 'dating'
- associated_models = {'dating__dating_type':DatingType,
- 'dating__quality':DatingQuality,
- 'dating__period':Period}
+ associated_models = {'dating__dating_type': DatingType,
+ 'dating__quality': DatingQuality,
+ 'dating__period': Period}
dating__period = forms.ChoiceField(label=_("Period"), choices=[])
dating__start_date = forms.IntegerField(label=_(u"Start date"),
required=False)
@@ -88,6 +104,8 @@ class DateForm(forms.Form):
choices=[])
dating__dating_type = forms.ChoiceField(label=_("Dating type"),
required=False, choices=[])
+ dating__precise_dating = forms.CharField(label=_("Precise dating"),
+ required=False)
def __init__(self, *args, **kwargs):
super(DateForm, self).__init__(*args, **kwargs)
@@ -98,12 +116,13 @@ class DateForm(forms.Form):
self.fields['dating__quality'].choices = DatingQuality.get_types()
self.fields['dating__quality'].help_text = DatingQuality.get_help()
+
class FindSelect(TableSelect):
base_finds__context_record__parcel__town = get_town_field()
base_finds__context_record__operation__year = forms.IntegerField(
- label=_(u"Year"))
+ label=_(u"Year"))
base_finds__context_record__operation__code_patriarche = \
- forms.IntegerField(label=_(u"Code PATRIARCHE"))
+ forms.IntegerField(label=_(u"Code PATRIARCHE"))
dating__period = forms.ChoiceField(label=_(u"Period"), choices=[])
# TODO search by warehouse
material_type = forms.ChoiceField(label=_(u"Material type"), choices=[])
@@ -118,93 +137,107 @@ class FindSelect(TableSelect):
self.fields['dating__period'].choices = Period.get_types()
self.fields['dating__period'].help_text = Period.get_help()
self.fields['material_type'].choices = \
- models.MaterialType.get_types()
+ models.MaterialType.get_types()
self.fields['material_type'].help_text = \
- models.MaterialType.get_help()
+ models.MaterialType.get_help()
self.fields['conservatory_state'].choices = \
- models.ConservatoryState.get_types()
+ models.ConservatoryState.get_types()
self.fields['conservatory_state'].help_text = \
- models.ConservatoryState.get_help()
+ models.ConservatoryState.get_help()
+
class FindFormSelection(forms.Form):
form_label = _("Find search")
- associated_models = {'pk':models.Find}
- currents = {'pk':models.Find}
- pk = forms.IntegerField(label="", required=False,
- widget=widgets.JQueryJqGrid(reverse_lazy('get-find'),
- FindSelect, models.Find, source_full=reverse_lazy('get-find-full')),
- validators=[valid_id(models.Find)])
+ associated_models = {'pk': models.Find}
+ currents = {'pk': models.Find}
+ pk = forms.IntegerField(
+ label="", required=False,
+ widget=widgets.JQueryJqGrid(
+ reverse_lazy('get-find'),
+ FindSelect, models.Find,
+ source_full=reverse_lazy('get-find-full')),
+ validators=[valid_id(models.Find)])
+
class BaseTreatmentForm(forms.Form):
form_label = _(u"Base treatment")
- associated_models = {'treatment_type':models.TreatmentType,
- 'person':Person,
- 'location':Warehouse}
+ associated_models = {'treatment_type': models.TreatmentType,
+ 'person': Person,
+ 'location': Warehouse}
treatment_type = forms.ChoiceField(label=_(u"Treatment type"), choices=[])
- person = forms.IntegerField(label=_(u"Person"),
- 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)])
+ person = forms.IntegerField(
+ label=_(u"Person"),
+ 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)
+ 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(
- exclude=['packaging'])
- self.fields['treatment_type'].help_text = models.TreatmentType.get_help(
- exclude=['packaging'])
+ exclude=['packaging'])
+ self.fields['treatment_type'].help_text = \
+ models.TreatmentType.get_help(exclude=['packaging'])
+
class FindMultipleFormSelection(forms.Form):
form_label = _(u"Upstream finds")
- associated_models = {'finds':models.Find}
- associated_labels = {'finds':_(u"Finds")}
- finds = forms.CharField(label="", required=False,
- widget=widgets.JQueryJqGrid(reverse_lazy('get-find'),
- FindSelect, models.Find, multiple=True, multiple_cols=[2, 3, 4]),
- validators=[valid_ids(models.Find)])
+ associated_models = {'finds': models.Find}
+ associated_labels = {'finds': _(u"Finds")}
+ finds = forms.CharField(
+ label="", required=False,
+ widget=widgets.JQueryJqGrid(
+ reverse_lazy('get-find'), FindSelect, models.Find, multiple=True,
+ multiple_cols=[2, 3, 4]),
+ validators=[valid_ids(models.Find)])
def clean(self):
- if not 'finds' in self.cleaned_data or not self.cleaned_data['finds']:
+ if 'finds' not in self.cleaned_data or not self.cleaned_data['finds']:
raise forms.ValidationError(_(u"You should at least select one "
u"archaeological find."))
return self.cleaned_data
+
def check_treatment(form_name, type_key, type_list=[], not_type_list=[]):
type_list = [models.TreatmentType.objects.get(txt_idx=tpe).pk
for tpe in type_list]
not_type_list = [models.TreatmentType.objects.get(txt_idx=tpe).pk
- for tpe in not_type_list]
+ for tpe in not_type_list]
+
def func(self, request, 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]:
+ request.session[storage.prefix]['step_data'][form_name]:
return False
try:
- type = int(request.session[storage.prefix]['step_data']\
- [form_name][form_name+'-'+type_key])
+ type = int(request.session[storage.prefix]['step_data']
+ [form_name][form_name + '-' + type_key])
return (not type_list or type in type_list) \
- and type not in not_type_list
+ and type not in not_type_list
except ValueError:
return False
return func
+
class ResultFindForm(forms.Form):
form_label = _(u"Resulting find")
- associated_models = {'material_type':models.MaterialType}
- label = forms.CharField(label=_(u"ID"),
- validators=[validators.MaxLengthValidator(60)])
+ associated_models = {'material_type': models.MaterialType}
+ label = forms.CharField(
+ label=_(u"ID"), validators=[validators.MaxLengthValidator(60)])
description = forms.CharField(label=_(u"Precise description"),
widget=forms.Textarea)
material_type = forms.ChoiceField(label=_(u"Material type"), choices=[])
@@ -221,6 +254,7 @@ ResultFindFormSet = formset_factory(ResultFindForm, can_delete=True,
formset=FormSet)
ResultFindFormSet.form_label = _(u"Resulting finds")
+
class UpstreamFindFormSelection(FindFormSelection):
form_label = _(u"Upstream find")
@@ -233,24 +267,25 @@ SourceFindFormSelection = get_form_selection(
models.Find, FindSelect, 'get-find',
_(u"You should select an archaeological find."))
+
class FindSourceSelect(SourceSelect):
find__base_finds__context_record__operation__year = forms.IntegerField(
- label=_(u"Year of the operation"))
+ label=_(u"Year of the operation"))
find__dating__period = forms.ChoiceField(
- label=_(u"Period of the archaelogical find"), choices=[])
+ label=_(u"Period of the archaelogical find"), choices=[])
find__material_type = forms.ChoiceField(
- label=_("Material type of the archaelogical find"), choices=[])
+ label=_("Material type of the archaelogical find"), choices=[])
find__description = forms.CharField(
- label=_(u"Description of the archaelogical find"))
+ label=_(u"Description of the archaelogical find"))
def __init__(self, *args, **kwargs):
super(FindSourceSelect, self).__init__(*args, **kwargs)
self.fields['find__dating__period'].choices = Period.get_types()
self.fields['find__dating__period'].help_text = Period.get_help()
self.fields['find__material_type'].choices = \
- models.MaterialType.get_types()
+ models.MaterialType.get_types()
self.fields['find__material_type'].help_text = \
- models.MaterialType.get_help()
+ models.MaterialType.get_help()
FindSourceFormSelection = get_form_selection(
'FindSourceFormSelection', _(u"Documentation search"), 'pk',