diff options
Diffstat (limited to 'archaeological_finds')
-rw-r--r-- | archaeological_finds/forms.py | 79 | ||||
-rw-r--r-- | archaeological_finds/forms_treatments.py | 58 |
2 files changed, 55 insertions, 82 deletions
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index bf5c579f2..001c10052 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -43,7 +43,7 @@ from ishtar_common.forms import FormSet, FloatField, \ get_form_selection, reverse_lazy, TableSelect, get_now, FinalForm, \ 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, @@ -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 947b4f20f..a1cb4a8b5 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( |