summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/forms.py91
-rw-r--r--archaeological_finds/forms_treatments.py58
-rw-r--r--archaeological_finds/migrations/0014_auto_20171110_1717.py26
-rw-r--r--archaeological_finds/models_finds.py5
-rw-r--r--archaeological_finds/models_treatments.py4
5 files changed, 93 insertions, 91 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index b88ee164e..eca12f6e9 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -41,9 +41,9 @@ import models
from ishtar_common.forms import FormSet, FloatField, \
get_form_selection, reverse_lazy, TableSelect, get_now, FinalForm, \
- ManageOldType
+ ManageOldType, FieldType
-from ishtar_common.forms_common import get_town_field, SourceSelect
+from ishtar_common.forms_common import get_town_field, SourceSelect, CustomForm
from ishtar_common.utils import convert_coordinates_to_point
from ishtar_common import widgets
from archaeological_operations.widgets import OAWidget
@@ -92,8 +92,10 @@ __all__ = [
logger = logging.getLogger(__name__)
-class RecordFormSelection(forms.Form):
+class RecordFormSelection(CustomForm, forms.Form):
form_label = _("Context record")
+ form_admin_name = _(u"Find - 010 - Context record choice")
+ form_slug = "find-010-contextrecord"
base_models = ['get_first_base_find']
associated_models = {'get_first_base_find__context_record': ContextRecord}
get_first_base_find__context_record = forms.IntegerField(
@@ -124,9 +126,11 @@ class RecordFormSelection(forms.Form):
cr.operation.pk)
-class FindForm(ManageOldType, forms.Form):
+class FindForm(CustomForm, ManageOldType, forms.Form):
file_upload = True
form_label = _("Find")
+ form_admin_name = _(u"Find - 020 - General")
+ form_slug = "find-020-general"
base_models = ['get_first_base_find', 'object_type', 'material_type',
'integritie', 'remarkabilitie']
associated_models = {'material_type': models.MaterialType,
@@ -206,6 +210,14 @@ class FindForm(ManageOldType, forms.Form):
'height': settings.IMAGE_MAX_SIZE[1]}),
max_length=255, required=False, widget=widgets.ImageFileInput())
+ TYPES = [
+ FieldType('material_type', models.MaterialType, is_multiple=True),
+ FieldType('object_type', models.ObjectType, is_multiple=True),
+ FieldType('get_first_base_find__batch', models.BatchType),
+ FieldType('integritie', models.IntegrityType, is_multiple=True),
+ FieldType('remarkabilitie', models.RemarkabilityType, is_multiple=True)
+ ]
+
def __init__(self, *args, **kwargs):
super(FindForm, self).__init__(*args, **kwargs)
if not get_current_profile().mapping:
@@ -224,35 +236,6 @@ class FindForm(ManageOldType, forms.Form):
self.fields[srs].help_text = \
SpatialReferenceSystem.get_help()
self.fields['checked'].choices = models.CHECK_CHOICES
- self.fields['material_type'].choices = models.MaterialType.get_types(
- initial=self.init_data.get('material_type'),
- empty_first=False
- )
- self.fields['material_type'].help_text = models.MaterialType.get_help()
-
- self.fields['object_type'].choices = models.ObjectType.get_types(
- initial=self.init_data.get('object_type'),
- empty_first=False
- )
- self.fields['object_type'].help_text = models.ObjectType.get_help()
-
- self.fields['get_first_base_find__batch'].choices = \
- models.BatchType.get_types(
- initial=self.init_data.get('get_first_base_find__batch'))
- self.fields['get_first_base_find__batch'].help_text = \
- models.BatchType.get_help()
- self.fields['integritie'].choices = \
- models.IntegrityType.get_types(
- empty_first=False,
- initial=self.init_data.get('integritie'))
- self.fields['integritie'].help_text = \
- models.IntegrityType.get_help()
- self.fields['remarkabilitie'].choices = \
- models.RemarkabilityType.get_types(
- empty_first=False,
- initial=self.init_data.get('remarkabilitie'))
- self.fields['remarkabilitie'].help_text = \
- models.RemarkabilityType.get_help()
self.fields['estimated_value'].label = u"{} ({})".format(
unicode(self.fields['estimated_value'].label),
get_current_profile().currency)
@@ -285,8 +268,10 @@ class FindForm(ManageOldType, forms.Form):
return self.cleaned_data
-class PreservationForm(ManageOldType, forms.Form):
+class PreservationForm(CustomForm, ManageOldType, forms.Form):
form_label = _("Preservation")
+ form_admin_name = _(u"Find - 030 - Preservation")
+ form_slug = "find-030-preservation"
base_models = ['alteration', 'alteration_cause',
'preservation_to_consider']
associated_models = {'alteration': models.AlterationType,
@@ -316,11 +301,11 @@ class PreservationForm(ManageOldType, forms.Form):
widget=forms.Textarea)
TYPES = [
- ('conservatory_state', models.ConservatoryState, False),
- ('treatment_emergency', models.TreatmentEmergencyType, False),
- ('preservation_to_consider', models.TreatmentType, True),
- ('alteration', models.AlterationType, True),
- ('alteration_cause', models.AlterationCauseType, True),
+ FieldType('conservatory_state', models.ConservatoryState),
+ FieldType('treatment_emergency', models.TreatmentEmergencyType),
+ FieldType('preservation_to_consider', models.TreatmentType, True),
+ FieldType('alteration', models.AlterationType, True),
+ FieldType('alteration_cause', models.AlterationCauseType, True),
]
def __init__(self, *args, **kwargs):
@@ -346,23 +331,18 @@ class DateForm(ManageOldType, forms.Form):
required=False, choices=[])
precise_dating = forms.CharField(label=_("Precise dating"),
required=False)
-
- def __init__(self, *args, **kwargs):
- super(DateForm, self).__init__(*args, **kwargs)
- self.fields['dating_type'].choices = DatingType.get_types(
- initial=self.init_data.get('dating_type'))
- self.fields['dating_type'].help_text = DatingType.get_help()
- self.fields['period'].choices = Period.get_types(
- initial=self.init_data.get('period'))
- self.fields['period'].help_text = Period.get_help()
- self.fields['quality'].choices = DatingQuality.get_types(
- initial=self.init_data.get('quality'))
- self.fields['quality'].help_text = DatingQuality.get_help()
+ TYPES = [
+ FieldType('dating_type', DatingType),
+ FieldType('period', Period),
+ FieldType('quality', DatingQuality),
+ ]
DatingFormSet = formset_factory(DateForm, can_delete=True,
formset=FormSet)
DatingFormSet.form_label = _("Dating")
+DatingFormSet.form_admin_name = _(u"Find - 040 - Dating")
+DatingFormSet.form_slug = "find-040-dating"
class FindSelect(TableSelect):
@@ -660,11 +640,10 @@ class ResultFindForm(ManageOldType, forms.Form):
weight = forms.IntegerField(label=_(u"Weight (g)"))
find_number = forms.IntegerField(label=_(u"Find number"))
- def __init__(self, *args, **kwargs):
- super(ResultFindForm, self).__init__(*args, **kwargs)
- self.fields['material_type'].choices = models.MaterialType.get_types(
- initial=self.init_data.get('material_type'))
- self.fields['material_type'].help_text = models.MaterialType.get_help()
+ TYPES = [
+ FieldType('material_type', models.MaterialType)
+ ]
+
ResultFindFormSet = formset_factory(ResultFindForm, can_delete=True,
formset=FormSet)
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py
index 99813ea31..4e5994ca9 100644
--- a/archaeological_finds/forms_treatments.py
+++ b/archaeological_finds/forms_treatments.py
@@ -37,7 +37,7 @@ from archaeological_operations.forms import AdministrativeActOpeForm, \
AdministrativeActOpeFormSelection, AdministrativeActModifForm
from ishtar_common.forms import reverse_lazy, TableSelect, FinalForm, \
- ManageOldType, get_form_selection
+ ManageOldType, get_form_selection, CustomForm, FieldType
from ishtar_common.forms_common import SourceSelect
from ishtar_common import widgets
@@ -75,8 +75,10 @@ class TreatmentFormSelection(forms.Form):
validators=[valid_id(models.Treatment)])
-class BaseTreatmentForm(ManageOldType, forms.Form):
+class BaseTreatmentForm(CustomForm, ManageOldType, forms.Form):
form_label = _(u"Base treatment")
+ form_admin_name = _(u"Treatment - 020 - General")
+ form_slug = "treatment-020-general"
base_models = ['treatment_type']
associated_models = {'treatment_type': models.TreatmentType,
'person': Person,
@@ -154,6 +156,13 @@ class BaseTreatmentForm(ManageOldType, forms.Form):
'height': settings.IMAGE_MAX_SIZE[1]}),
max_length=255, required=False, widget=widgets.ImageFileInput())
+ TYPES = [
+ FieldType('treatment_state', models.TreatmentState),
+ FieldType('treatment_type', models.TreatmentType, is_multiple=True,
+ extra_args={'dct': {'upstream_is_many': False,
+ 'downstream_is_many': False}})
+ ]
+
def __init__(self, *args, **kwargs):
user = kwargs.pop('user')
super(BaseTreatmentForm, self).__init__(*args, **kwargs)
@@ -172,20 +181,6 @@ class BaseTreatmentForm(ManageOldType, forms.Form):
self.fields['organization'].initial = person.attached_to.pk
self.fields['target_is_basket'].widget.choices = \
((False, _(u"Single find")), (True, _(u"Basket")))
- self.fields['treatment_type'].choices = models.TreatmentType.get_types(
- initial=self.init_data.get('treatment_type'),
- dct={'upstream_is_many': False, 'downstream_is_many': False},
- empty_first=False
- )
- self.fields['treatment_type'].help_text = \
- models.TreatmentType.get_help(
- dct={'upstream_is_many': False, 'downstream_is_many': False})
- self.fields['treatment_state'].choices = \
- models.TreatmentState.get_types(
- initial=self.init_data.get('treatment_state'),
- )
- self.fields['treatment_state'].help_text = \
- models.TreatmentState.get_help()
# TODO
"""
self.fields['basket'].required = False
@@ -266,8 +261,10 @@ class TreatmentModifyForm(BaseTreatmentForm):
return cleaned_data
-class TreatmentFormFileChoice(forms.Form):
+class TreatmentFormFileChoice(CustomForm, forms.Form):
form_label = _(u"Associated request")
+ form_admin_name = _(u"Treatment - 010 - Request choice")
+ form_slug = "treatment-010-requestchoice"
associated_models = {'file': models.TreatmentFile, }
currents = {'file': models.TreatmentFile}
file = forms.IntegerField(
@@ -383,15 +380,14 @@ class AdministrativeActTreatmentFormSelection(
class AdministrativeActTreatmentForm(AdministrativeActOpeForm):
+ form_admin_name = _(u"Treatment - Administrative act - General")
+ form_slug = "treatment-adminact-general"
act_type = forms.ChoiceField(label=_(u"Act type"), choices=[])
- def __init__(self, *args, **kwargs):
- super(AdministrativeActTreatmentForm, self).__init__(*args, **kwargs)
- self.fields['act_type'].choices = ActType.get_types(
- initial=self.init_data.get('act_type'),
- dct={'intented_to': 'T'})
- self.fields['act_type'].help_text = ActType.get_help(
- dct={'intented_to': 'T'})
+ TYPES = [
+ FieldType('act_type', ActType,
+ extra_args={"dct": {'intented_to': 'T'}}),
+ ]
class AdministrativeActTreatmentModifForm(
@@ -640,16 +636,14 @@ class AdministrativeActTreatmentFileFormSelection(
class AdministrativeActTreatmentFileForm(AdministrativeActOpeForm):
+ form_admin_name = _(u"Treatment request - Administrative act - General")
+ form_slug = "treatmentfile-adminact-general"
act_type = forms.ChoiceField(label=_(u"Act type"), choices=[])
- def __init__(self, *args, **kwargs):
- super(AdministrativeActTreatmentFileForm, self).__init__(*args,
- **kwargs)
- self.fields['act_type'].choices = ActType.get_types(
- initial=self.init_data.get('act_type'),
- dct={'intented_to': 'TF'})
- self.fields['act_type'].help_text = ActType.get_help(
- dct={'intented_to': 'TF'})
+ TYPES = [
+ FieldType('act_type', ActType,
+ extra_args={"dct": {'intented_to': 'TF'}}),
+ ]
class AdministrativeActTreatmentFileModifForm(
diff --git a/archaeological_finds/migrations/0014_auto_20171110_1717.py b/archaeological_finds/migrations/0014_auto_20171110_1717.py
new file mode 100644
index 000000000..63458bd9b
--- /dev/null
+++ b/archaeological_finds/migrations/0014_auto_20171110_1717.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11 on 2017-11-10 17:17
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ishtar_common', '0021_auto_20171110_1717'),
+ ('archaeological_finds', '0013_auto_20171026_1828'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='find',
+ name='images',
+ field=models.ManyToManyField(blank=True, to='ishtar_common.IshtarImage', verbose_name='Images'),
+ ),
+ migrations.AddField(
+ model_name='treatment',
+ name='images',
+ field=models.ManyToManyField(blank=True, to='ishtar_common.IshtarImage', verbose_name='Images'),
+ ),
+ ]
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 8be440181..2b782c614 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -34,7 +34,7 @@ from ishtar_common.utils import cached_label_changed, post_save_point
from ishtar_common.models import GeneralType, HierarchicalType, ImageModel, \
BaseHistorizedItem, ShortMenuItem, LightHistorizedItem, \
HistoricalRecords, OwnPerms, Source, Person, Basket, post_save_cache, \
- ValueGetter, get_current_profile
+ ValueGetter, get_current_profile, IshtarImage
from archaeological_operations.models import AdministrativeAct
from archaeological_context_records.models import ContextRecord, Dating
@@ -750,7 +750,8 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel,
null=True)
appraisal_date = models.DateField(_(u"Appraisal date"), blank=True,
null=True)
-
+ images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"),
+ blank=True)
cached_label = models.TextField(_(u"Cached name"), null=True, blank=True,
db_index=True)
history = HistoricalRecords()
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index 03eeed452..6c173959a 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -30,7 +30,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext
from ishtar_common.utils import cached_label_changed, get_current_year
from ishtar_common.models import GeneralType, ImageModel, BaseHistorizedItem, \
OwnPerms, HistoricalRecords, Person, Organization, Source, \
- ValueGetter, post_save_cache, ShortMenuItem, DashboardFormItem
+ ValueGetter, post_save_cache, ShortMenuItem, DashboardFormItem, IshtarImage
from archaeological_warehouse.models import Warehouse, Container
from archaeological_finds.models_finds import Find, FindBasket, TreatmentType
from archaeological_operations.models import ClosedItem, Operation
@@ -115,6 +115,8 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem,
blank=True, null=True)
target_is_basket = models.BooleanField(_(u"Target a basket"),
default=False)
+ images = models.ManyToManyField(IshtarImage, verbose_name=_(u"Images"),
+ blank=True)
cached_label = models.TextField(_(u"Cached name"), null=True, blank=True,
db_index=True)
history = HistoricalRecords()