diff options
| -rw-r--r-- | archaeological_finds/forms.py | 166 | ||||
| -rw-r--r-- | archaeological_finds/models_finds.py | 9 | ||||
| -rw-r--r-- | archaeological_finds/templates/ishtar/wizard/wizard_simplefind.html | 13 | ||||
| -rw-r--r-- | archaeological_finds/views.py | 26 | ||||
| -rw-r--r-- | archaeological_finds/wizards.py | 16 | 
5 files changed, 172 insertions, 58 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index 958b1896c..970b35f92 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -72,11 +72,12 @@ __all__ = [      'AdministrativeActTreatmentFormSelection',      'AdministrativeActTreatmentFileModifForm',      'DashboardTreatmentForm', 'DashboardTreatmentFileForm', -    'RecordFormSelection', 'FindForm', 'DateForm', 'DatingFormSet', -    'PreservationForm', 'FindBasketFormSelection', 'FindBasketForm', -    'FindSelect', 'FindFormSelection', 'FindFormSelectionWarehouseModule', -    'MultipleFindFormSelection', 'MultipleFindFormSelectionWarehouseModule', -    'FindMultipleFormSelection', 'check_form', 'check_exist', 'check_not_exist', +    'RecordFormSelection', 'FindForm', 'SimpleFindForm', 'DateForm', +    'DatingFormSet', 'PreservationForm', 'FindBasketFormSelection', +    'FindBasketForm', 'FindSelect', 'FindFormSelection', +    'FindFormSelectionWarehouseModule', 'MultipleFindFormSelection', +    'MultipleFindFormSelectionWarehouseModule', 'FindMultipleFormSelection', +    'check_form', 'check_exist', 'check_not_exist',      'check_value', 'check_type_field', 'check_type_not_field',      'check_treatment', 'ResultFindForm', 'ResultFindFormSet',      'FindDeletionForm', 'UpstreamFindFormSelection', 'NewFindBasketForm', @@ -123,23 +124,33 @@ class RecordFormSelection(CustomForm, forms.Form):              cr.operation.pk) -class FindForm(CustomForm, ManageOldType): +class BaseFindForm(CustomForm, ManageOldType): +    """ +    Base find form with no field related to base_find +    """      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', -                   'communicabilitie'] +    form_admin_name = _(u"Simple find - 020 - General") +    form_slug = "simplefind-020-general" +    base_models = ['object_type', 'material_type', 'communicabilitie']      associated_models = {          'material_type': models.MaterialType,          'object_type': models.ObjectType,          'communicabilitie': models.CommunicabilityType, -        'get_first_base_find__batch': models.BatchType, -        'get_first_base_find__spatial_reference_system': SpatialReferenceSystem,          'material_type_quality': models.MaterialTypeQualityType,          'object_type_quality': models.ObjectTypeQualityType,          'checked_type': models.CheckedType,      } +    field_order = [ +        'label', 'denomination', 'previous_id', 'museum_id', 'seal_number', +        'mark', 'description', 'is_complete', 'material_type', +        'material_type_quality', 'object_type', 'object_type_quality', +        'find_number', 'min_number_of_individuals', 'inscription', +        'manufacturing_place', 'communicabilitie', 'comment', 'dating_comment', +        'length', 'width', 'height', 'diameter', 'thickness', 'volume', +        'weight', 'clutter_long_side', 'clutter_short_side', 'clutter_height', +        'dimensions_comment', 'checked_type', 'check_date' +    ]      HEADERS = {}      HEADERS['label'] = FormHeader(_(u"Identification")) @@ -148,8 +159,6 @@ class FindForm(CustomForm, ManageOldType):          validators=[validators.MaxLengthValidator(60)])      denomination = forms.CharField(label=_(u"Denomination"), required=False)      previous_id = forms.CharField(label=_("Previous ID"), required=False) -    get_first_base_find__excavation_id = forms.CharField( -        label=_(u"Excavation ID"), required=False)      museum_id = forms.CharField(label=_(u"Museum ID"), required=False)      seal_number = forms.CharField(label=_(u"Seal number"), required=False)      mark = forms.CharField(label=_(u"Mark"), required=False) @@ -157,14 +166,6 @@ class FindForm(CustomForm, ManageOldType):      HEADERS['description'] = FormHeader(_(u"Description"))      description = forms.CharField(label=_(u"Description"),                                    widget=forms.Textarea, required=False) -    get_first_base_find__discovery_date = forms.DateField( -        label=_(u"Discovery date (exact or TPQ)"), widget=DatePicker, -        required=False) -    get_first_base_find__discovery_date_taq = forms.DateField( -        label=_(u"Discovery date (TAQ)"), widget=DatePicker, required=False) -    get_first_base_find__batch = forms.ChoiceField( -        label=_(u"Batch/object"), choices=[], -        required=False)      is_complete = forms.NullBooleanField(label=_(u"Is complete?"),                                           required=False)      material_type = widgets.Select2MultipleField( @@ -212,8 +213,86 @@ class FindForm(CustomForm, ManageOldType):      dimensions_comment = forms.CharField(          label=_(u"Dimensions comment"), required=False, widget=forms.Textarea) -    HEADERS['get_first_base_find__x'] = FormHeader( -        _(u"Coordinates")) +    HEADERS['checked_type'] = FormHeader(_(u"Sheet")) +    checked_type = forms.ChoiceField(label=_(u"Check"), required=False) +    check_date = forms.DateField( +        initial=get_now, label=_(u"Check date"), widget=DatePicker) + +    TYPES = [ +        FieldType('material_type', models.MaterialType, is_multiple=True), +        FieldType('material_type_quality', models.MaterialTypeQualityType), +        FieldType('object_type', models.ObjectType, is_multiple=True), +        FieldType('object_type_quality', models.ObjectTypeQualityType), +        FieldType('communicabilitie', models.CommunicabilityType, +                  is_multiple=True), +        FieldType('checked_type', models.CheckedType, is_multiple=True), +    ] + +    def __init__(self, *args, **kwargs): +        context_record = kwargs.pop('context_record') +        super(BaseFindForm, self).__init__(*args, **kwargs) +        if not context_record or \ +                not context_record.operation.operation_type.judiciary: +            self.fields.pop('seal_number') + +    def clean(self): +        clutter_long_side = self.cleaned_data.get('clutter_long_side', None) +        clutter_short_side = self.cleaned_data.get('clutter_short_side', None) + +        if clutter_long_side and clutter_short_side and \ +                clutter_short_side > clutter_long_side: +            raise forms.ValidationError( +                unicode(_( +                    u"Clutter: short side cannot be bigger than the long side." +                )) +            ) +        return self.cleaned_data + + +class FindForm(BaseFindForm): +    file_upload = True +    form_label = _("Find") +    form_admin_name = _(u"Find - 020 - General") +    form_slug = "find-020-general" +    base_models = ['get_first_base_find'] + BaseFindForm.base_models +    associated_models = BaseFindForm.associated_models.copy() +    associated_models.update({ +        'get_first_base_find__batch': models.BatchType, +        'get_first_base_find__spatial_reference_system': SpatialReferenceSystem, +    }) +    field_order = [ +        'label', 'denomination', 'previous_id', +        'get_first_base_find__excavation_id', 'museum_id', 'seal_number', +        'mark', 'description', 'get_first_base_find__discovery_date', +        'get_first_base_find__discovery_date_taq', 'get_first_base_find__batch', +        'is_complete', 'material_type', 'material_type_quality', 'object_type', +        'object_type_quality', 'find_number', 'min_number_of_individuals', +        'inscription', 'manufacturing_place', 'communicabilitie', 'comment', +        'dating_comment', 'length', 'width', 'height', 'diameter', 'thickness', +        'volume', 'weight', 'clutter_long_side', 'clutter_short_side', +        'clutter_height', 'dimensions_comment', 'get_first_base_find__x', +        'get_first_base_find__estimated_error_x', 'get_first_base_find__y', +        'get_first_base_find__estimated_error_y', 'get_first_base_find__z', +        'get_first_base_find__estimated_error_z', +        'get_first_base_find__spatial_reference_system', +        'get_first_base_find__topographic_localisation', 'checked_type', +        'check_date', +    ] + +    HEADERS = BaseFindForm.HEADERS.copy() +    get_first_base_find__excavation_id = forms.CharField( +        label=_(u"Excavation ID"), required=False) + +    get_first_base_find__discovery_date = forms.DateField( +        label=_(u"Discovery date (exact or TPQ)"), widget=DatePicker, +        required=False) +    get_first_base_find__discovery_date_taq = forms.DateField( +        label=_(u"Discovery date (TAQ)"), widget=DatePicker, required=False) +    get_first_base_find__batch = forms.ChoiceField( +        label=_(u"Batch/object"), choices=[], +        required=False) + +    HEADERS['get_first_base_find__x'] = FormHeader(_(u"Coordinates"))      get_first_base_find__x = forms.FloatField(label=_(u"X"), required=False)      get_first_base_find__estimated_error_x = \          forms.FloatField(label=_(u"Estimated error for X"), required=False) @@ -231,22 +310,10 @@ class FindForm(CustomForm, ManageOldType):          required=False, max_length=120      ) -    HEADERS['checked_type'] = FormHeader(_(u"Sheet")) -    checked_type = forms.ChoiceField(label=_(u"Check"), required=False) -    check_date = forms.DateField( -        initial=get_now, label=_(u"Check date"), widget=DatePicker) - -    TYPES = [ -        FieldType('material_type', models.MaterialType, is_multiple=True), -        FieldType('material_type_quality', models.MaterialTypeQualityType), -        FieldType('object_type', models.ObjectType, is_multiple=True), -        FieldType('object_type_quality', models.ObjectTypeQualityType), -        FieldType('communicabilitie', models.CommunicabilityType, -                  is_multiple=True), +    TYPES = BaseFindForm.TYPES + [          FieldType('get_first_base_find__batch', models.BatchType),          FieldType('get_first_base_find__spatial_reference_system',                    SpatialReferenceSystem), -        FieldType('checked_type', models.CheckedType, is_multiple=True),      ]      PROFILE_FILTER = {          'mapping': [ @@ -258,14 +325,8 @@ class FindForm(CustomForm, ManageOldType):          ],      } -    def __init__(self, *args, **kwargs): -        context_record = kwargs.pop('context_record') -        super(FindForm, self).__init__(*args, **kwargs) -        if not context_record or \ -                not context_record.operation.operation_type.judiciary: -            self.fields.pop('seal_number') -      def clean(self): +        self.cleaned_data = super(FindForm, self).clean()          taq = self.cleaned_data.get('get_first_base_find__discovery_date_taq',                                      None)          tpq = self.cleaned_data.get('get_first_base_find__discovery_date', @@ -282,17 +343,6 @@ class FindForm(CustomForm, ManageOldType):                  unicode(_(u"Discovery date: TAQ date must be older than TPQ "                            u"date."))) -        clutter_long_side = self.cleaned_data.get('clutter_long_side', None) -        clutter_short_side = self.cleaned_data.get('clutter_short_side', None) - -        if clutter_long_side and clutter_short_side and \ -                clutter_short_side > clutter_long_side: -            raise forms.ValidationError( -                unicode(_( -                    u"Clutter: short side cannot be bigger than the long side." -                )) -            ) -          if not get_current_profile().mapping:              return self.cleaned_data          x = self.cleaned_data.get('get_first_base_find__x', None) @@ -320,6 +370,12 @@ class FindForm(CustomForm, ManageOldType):          return self.cleaned_data +class SimpleFindForm(BaseFindForm): +    def __init__(self, *args, **kwargs): +        self.base_finds = kwargs.pop('base_finds') +        super(SimpleFindForm, self).__init__(*args, **kwargs) + +  class ResultingFindForm(CustomForm, ManageOldType):      file_upload = True      form_label = _("Resulting find") diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 3483113d7..1fb4f6132 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -327,6 +327,15 @@ class BaseFind(BulkUpdatedItem, BaseHistorizedItem, OwnPerms):          finds = self.find.filter().order_by("-order").all()          return finds and finds[0] +    def get_main_find(self): +        """ +        Get the last find which is not related to many base_find +        """ +        for find in self.find.order_by('-pk'): +            if find.base_finds.count() == 1: +                return find +        return +      def generate_index(self):          """          Generate index based on operation or context record (based on diff --git a/archaeological_finds/templates/ishtar/wizard/wizard_simplefind.html b/archaeological_finds/templates/ishtar/wizard/wizard_simplefind.html new file mode 100644 index 000000000..b1d77ba81 --- /dev/null +++ b/archaeological_finds/templates/ishtar/wizard/wizard_simplefind.html @@ -0,0 +1,13 @@ +{% extends "ishtar/wizard/default_wizard.html" %} +{% load i18n %} +{% block form_head %} +<div class="alert alert-warning"> +    <i class="fa fa-exclamation-triangle"></i> +    {% trans 'This find is related to many base finds. To edit field related to base finds edit the corresponding find between theses:' %} +    <ul>{% for base_find in wizard.form.base_finds %} +    {% with find=base_find.get_main_find %}<li> +        {{find.short_label }} +        <a href="{% url 'find_modify' find.pk  %}"><i class="fa fa-pencil"></i></a> +    </li>{% endwith %}{% endfor %}</ul> +</div> +{% endblock %} diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py index d6924257f..ceb00d432 100644 --- a/archaeological_finds/views.py +++ b/archaeological_finds/views.py @@ -187,10 +187,25 @@ find_search_wizard = FindSearch.as_view([      condition_dict=find_search_condition_dict  ) + +def has_many_base_find(wizard): +    find = wizard.get_current_object() +    if not find: +        return False +    return find.base_finds.count() > 1 + + +def has_only_one_base_find(wizard): +    return not has_many_base_find(wizard) + +  find_modification_condition_dict = {      'selec-find_modification': check_not_warehouse_module,      'selecw-find_modification': check_warehouse_module,      'preservation-find_modification': check_preservation_module, +    'selecrecord-find_modification': has_only_one_base_find, +    'find-find_modification': has_only_one_base_find, +    'simplefind-find_modification': has_many_base_find,  }  find_modification_steps = [ @@ -198,6 +213,7 @@ find_modification_steps = [      ('selecw-find_modification', FindFormSelectionWarehouseModule),      ('selecrecord-find_modification', RecordFormSelection),      ('find-find_modification', FindForm), +    ('simplefind-find_modification', SimpleFindForm),      ('preservation-find_modification', PreservationForm),      ('dating-find_modification', DatingFormSet),      ('final-find_modification', FinalForm) @@ -218,9 +234,15 @@ def find_modify(request, pk):          key = 'selecw-find_modification'      FindModificationWizard.session_set_value(          request, key, 'pk', pk, reset=True) +    q = models.Find.objects.filter(pk=pk) +    if not q.count(): +        raise Http404() +    step = 'find-find_modification' +    find = q.all()[0] +    if find.base_finds.count() > 1: +        step = 'simplefind-find_modification'      return redirect( -        reverse('find_modification', -                kwargs={'step': 'selecrecord-find_modification'})) +        reverse('find_modification', kwargs={'step': step}))  find_deletion_condition_dict = {      'selec-find_deletion': check_not_warehouse_module, diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py index 3043d22aa..3c25258a6 100644 --- a/archaeological_finds/wizards.py +++ b/archaeological_finds/wizards.py @@ -55,11 +55,21 @@ class FindWizard(Wizard):              if base_finds:                  return base_finds[0].context_record +    def get_current_basefinds(self): +        find = self.get_current_object() +        if not find: +            return [] +        return find.base_finds.all() +      def get_form_kwargs(self, step=None):          kwargs = super(FindWizard, self).get_form_kwargs(step) -        if step not in ('find-find_creation', 'find-find_modification'): +        if step not in ( +                'find-find_creation', 'find-find_modification', +                'simplefind-find_modification',):              return kwargs          kwargs['context_record'] = self.get_current_contextrecord() +        if step == 'simplefind-find_modification': +            kwargs['base_finds'] = self.get_current_basefinds()          return kwargs      def get_context_data(self, form, **kwargs): @@ -90,6 +100,10 @@ class FindModificationWizard(FindWizard):          'selec-find_modification': ['pk'],          'selecw-find_modification': ['pk'],      } +    wizard_templates = { +        'simplefind-find_modification': +            'ishtar/wizard/wizard_simplefind.html', +    }  class FindDeletionWizard(DeletionWizard):  | 
