diff options
Diffstat (limited to 'archaeological_context_records')
| -rw-r--r-- | archaeological_context_records/forms.py | 72 | ||||
| -rw-r--r-- | archaeological_context_records/migrations/0014_contextrecord_images.py | 21 | ||||
| -rw-r--r-- | archaeological_context_records/models.py | 4 | 
3 files changed, 58 insertions, 39 deletions
| diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index c310e98fa..7cc94bb9a 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -37,14 +37,17 @@ import models  from ishtar_common import widgets  from archaeological_operations.widgets import OAWidget  from ishtar_common.forms import FinalForm, FormSet, \ -    reverse_lazy, get_form_selection, TableSelect, ManageOldType +    reverse_lazy, get_form_selection, TableSelect, ManageOldType, CustomForm,\ +    FieldType  from ishtar_common.forms_common import get_town_field, SourceSelect  from archaeological_operations.forms import OperationSelect, ParcelField,\      RecordRelationsForm as OpeRecordRelationsForm, RecordRelationsFormSetBase -class OperationFormSelection(forms.Form): +class OperationFormSelection(CustomForm, forms.Form):      form_label = _("Operation") +    form_admin_name = _(u"Context record - 010 - Operation choice") +    form_slug = "contextrecord-010-operationchoice"      associated_models = {'operation': Operation}      currents = {'operation': Operation}      operation = forms.IntegerField( @@ -129,8 +132,10 @@ class RecordFormSelection(forms.Form):          return cleaned_data -class RecordFormGeneral(ManageOldType, forms.Form): +class RecordFormGeneral(CustomForm, ManageOldType, forms.Form):      form_label = _("General") +    form_admin_name = _(u"Context record - 020 - General") +    form_slug = "contextrecord-020-general"      file_upload = True      base_models = ["documentation"]      associated_models = { @@ -175,6 +180,12 @@ class RecordFormGeneral(ManageOldType, forms.Form):                  'height': settings.IMAGE_MAX_SIZE[1]}),          max_length=255, required=False, widget=widgets.ImageFileInput()) +    TYPES = [ +        FieldType('unit', models.Unit), +        FieldType('excavation_technic', models.ExcavationTechnicType), +        FieldType('documentation', models.DocumentationType, is_multiple=True) +    ] +      def __init__(self, *args, **kwargs):          # TODO: simplify          operation = None @@ -222,19 +233,6 @@ class RecordFormGeneral(ManageOldType, forms.Form):                      (" - ".join([k for k in key if k]),                       [(parcel.pk, parcel.short_label) for parcel in gparcels])                  ) -        self.fields['unit'].choices = models.Unit.get_types( -            initial=self.init_data.get('unit')) -        self.fields['unit'].help_text = models.Unit.get_help() -        self.fields['excavation_technic'].choices = \ -            models.ExcavationTechnicType.get_types( -            initial=self.init_data.get('excavation_technic')) -        self.fields['excavation_technic'].help_text = \ -            models.ExcavationTechnicType.get_help() -        self.fields['documentation'].choices = \ -            models.DocumentationType.get_types(empty_first=False, -                initial=self.init_data.get('documentation')) -        self.fields['documentation'].help_text = \ -            models.DocumentationType.get_help()      def clean(self):          # manage unique context record ID @@ -264,22 +262,18 @@ class DatingForm(ManageOldType, forms.Form):      dating_type = forms.ChoiceField(label=_("Dating type"), required=False,                                      choices=[]) -    def __init__(self, *args, **kwargs): -        super(DatingForm, self).__init__(*args, **kwargs) -        self.fields['dating_type'].choices = models.DatingType.get_types( -            initial=self.init_data.get('dating_type')) -        self.fields['dating_type'].help_text = models.DatingType.get_help() -        self.fields['quality'].choices = models.DatingQuality.get_types( -            initial=self.init_data.get('quality')) -        self.fields['quality'].help_text = models.DatingQuality.get_help() -        self.fields['period'].choices = Period.get_types( -            initial=self.init_data.get('period')) -        self.fields['period'].help_text = Period.get_help() +    TYPES = [ +        FieldType('dating_type', models.DatingType), +        FieldType('quality', models.DatingQuality), +        FieldType('period', models.Period) +    ]  DatingFormSet = formset_factory(DatingForm, can_delete=True,                                  formset=FormSet)  DatingFormSet.form_label = _("Dating") +DatingFormSet.form_admin_name = _(u"Context record - 030 - Dating") +DatingFormSet.form_slug = "contextrecord-030-datings"  class RecordRelationsForm(OpeRecordRelationsForm): @@ -301,13 +295,19 @@ class RecordRelationsForm(OpeRecordRelationsForm):          if crs:              self.fields['right_record'].choices = [('', '-' * 2)] + crs +  RecordRelationsFormSet = formset_factory(      RecordRelationsForm, can_delete=True, formset=RecordRelationsFormSetBase)  RecordRelationsFormSet.form_label = _(u"Relations") +RecordRelationsFormSet.form_admin_name = _(u"Context record - 050 - Relations") +RecordRelationsFormSet.form_slug = "contextrecord-050-recordrelations" -class RecordFormInterpretation(ManageOldType, forms.Form): +class RecordFormInterpretation(CustomForm, ManageOldType, forms.Form):      form_label = _("Interpretation") +    form_admin_name = "Context record - 040 - Interpretation" +    form_slug = "contextrecord-040-interpretation" +      associated_models = {'activity': models.ActivityType,                           'identification': models.IdentificationType}      datings_comment = forms.CharField( @@ -328,16 +328,11 @@ class RecordFormInterpretation(ManageOldType, forms.Form):      tpq_estimated = forms.IntegerField(label=_(u"Estimated TPQ"),                                         required=False) -    def __init__(self, *args, **kwargs): -        super(RecordFormInterpretation, self).__init__(*args, **kwargs) -        self.fields['activity'].choices = models.ActivityType.get_types( -            initial=self.init_data.get('activity')) -        self.fields['activity'].help_text = models.ActivityType.get_help() -        self.fields['identification'].choices = \ -            models.IdentificationType.get_types( -                initial=self.init_data.get('identification')) -        self.fields['identification'].help_text = \ -            models.IdentificationType.get_help() +    TYPES = [ +        FieldType('activity', models.ActivityType), +        FieldType('identification', models.IdentificationType), +    ] +  OperationRecordFormSelection = get_form_selection(      'OperationRecordFormSelection', _(u"Operation search"), 'operation_id', @@ -353,6 +348,7 @@ class RecordDeletionForm(FinalForm):  # Source management for context records #  ######################################### +  SourceRecordFormSelection = get_form_selection(      'SourceRecordFormSelection', _(u"Context record search"),      'context_record', models.ContextRecord, RecordSelect, 'get-contextrecord', diff --git a/archaeological_context_records/migrations/0014_contextrecord_images.py b/archaeological_context_records/migrations/0014_contextrecord_images.py new file mode 100644 index 000000000..641309c97 --- /dev/null +++ b/archaeological_context_records/migrations/0014_contextrecord_images.py @@ -0,0 +1,21 @@ +# -*- 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_context_records', '0013_auto_20171026_1827'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='contextrecord', +            name='images', +            field=models.ManyToManyField(blank=True, to='ishtar_common.IshtarImage', verbose_name='Images'), +        ), +    ] diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 925a48597..dde661ee7 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -33,7 +33,7 @@ from ishtar_common.utils import cached_label_changed  from ishtar_common.models import GeneralType, BaseHistorizedItem, \      HistoricalRecords, OwnPerms, ShortMenuItem, Source, GeneralRelationType,\      GeneralRecordRelations, post_delete_record_relation, \ -    ImageModel, post_save_cache, ValueGetter, BulkUpdatedItem +    ImageModel, post_save_cache, ValueGetter, BulkUpdatedItem, IshtarImage  from archaeological_operations.models import Operation, Period, Parcel @@ -302,6 +302,8 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem,      point_2d = models.PointField(_(u"Point (2D)"), blank=True, null=True)      point = models.PointField(_(u"Point (3D)"), blank=True, null=True, dim=3)      polygon = models.PolygonField(_(u"Polygon"), 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)      PARENT_SEARCH_VECTORS = ['operation'] | 
