From 13b9ef1c26bb89349a15be94db7d01512e270d5a Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 12 Feb 2021 15:43:15 +0100 Subject: Refactor - clean --- archaeological_context_records/forms.py | 135 ++++++++++++++++---------------- 1 file changed, 69 insertions(+), 66 deletions(-) (limited to 'archaeological_context_records/forms.py') diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 357f5ce13..c4fa6f8fe 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -49,12 +49,12 @@ from ishtar_common import widgets class OperationFormSelection(CustomForm, forms.Form): form_label = _("Operation") - form_admin_name = _(u"Context record - 010 - Operation choice") + form_admin_name = _("Context record - 010 - Operation choice") form_slug = "contextrecord-010-operationchoice" associated_models = {'operation': Operation} currents = {'operation': Operation} operation = forms.IntegerField( - label=_(u"Operation"), required=False, + label=_("Operation"), required=False, widget=widgets.JQueryAutoComplete( reverse_lazy('autocomplete-operation'), associated_model=Operation), @@ -200,9 +200,12 @@ def get_init_parcel(form, operation, prefix=""): parcels = sorted(parcels, key=sort) for key, gparcels in groupby(parcels, sort): form.fields[prefix + 'parcel'].choices.append( - (" - ".join([k for k in key if k]), - [(parcel.pk, parcel.short_label) for parcel in gparcels]) + ( + " - ".join(k for k in key if k), + [(parcel.pk, parcel.short_label) for parcel in gparcels], + ) ) + if len(form.fields[prefix + 'parcel'].choices) == 1 and \ (prefix + 'town') in form.fields: # only the empty choice is available @@ -218,7 +221,7 @@ def get_init_parcel(form, operation, prefix=""): class RecordFormGeneral(CustomForm, ManageOldType): HEADERS = {} form_label = _("General") - form_admin_name = _(u"Context record - 020 - General") + form_admin_name = _("Context record - 020 - General") form_slug = "contextrecord-020-general" file_upload = True base_models = ["documentation"] @@ -230,58 +233,58 @@ class RecordFormGeneral(CustomForm, ManageOldType): 'excavation_technic': models.ExcavationTechnicType} pk = forms.IntegerField(required=False, widget=forms.HiddenInput) operation_id = forms.IntegerField(widget=forms.HiddenInput) - parcel = forms.ChoiceField(label=_(u"Parcel"), choices=[]) - town = forms.ChoiceField(label=_(u"Town"), choices=[], required=False) + parcel = forms.ChoiceField(label=_("Parcel"), choices=[]) + town = forms.ChoiceField(label=_("Town"), choices=[], required=False) archaeological_site = forms.ChoiceField( label=" ", choices=[], required=False, - help_text=_(u"Only the items associated to the operation can be " - u"selected.") + help_text=_("Only the items associated to the operation can be " + "selected.") ) - label = forms.CharField(label=_(u"ID"), + label = forms.CharField(label=_("ID"), validators=[validators.MaxLengthValidator(200)]) - unit = forms.ChoiceField(label=_(u"Context record type"), required=False, + unit = forms.ChoiceField(label=_("Context record type"), required=False, choices=[]) - description = forms.CharField(label=_(u"Description"), + description = forms.CharField(label=_("Description"), widget=forms.Textarea, required=False) - comment = forms.CharField(label=_(u"General comment"), + comment = forms.CharField(label=_("General comment"), widget=forms.Textarea, required=False) excavation_technic = forms.ChoiceField( - label=_(u"Excavation technique"), choices=[], required=False) + label=_("Excavation technique"), choices=[], required=False) surface = forms.IntegerField( required=False, widget=widgets.AreaWidget, - label=_(u"Total surface (m2)"), + label=_("Total surface (m2)"), validators=[validators.MinValueValidator(0), validators.MaxValueValidator(999999999)]) - length = forms.FloatField(label=_(u"Length (m)"), required=False) - width = forms.FloatField(label=_(u"Width (m)"), required=False) - thickness = forms.FloatField(label=_(u"Thickness (m)"), required=False) - diameter = forms.FloatField(label=_(u"Diameter (m)"), required=False) - depth = forms.FloatField(label=_(u"Depth (m)"), required=False) + length = forms.FloatField(label=_("Length (m)"), required=False) + width = forms.FloatField(label=_("Width (m)"), required=False) + thickness = forms.FloatField(label=_("Thickness (m)"), required=False) + diameter = forms.FloatField(label=_("Diameter (m)"), required=False) + depth = forms.FloatField(label=_("Depth (m)"), required=False) depth_of_appearance = forms.FloatField( - label=_(u"Depth of appearance (m)"), required=False) - opening_date = forms.DateField(label=_(u"Opening date"), + label=_("Depth of appearance (m)"), required=False) + opening_date = forms.DateField(label=_("Opening date"), widget=DatePicker, required=False) - closing_date = forms.DateField(label=_(u"Closing date"), + closing_date = forms.DateField(label=_("Closing date"), widget=DatePicker, required=False) documentation = forms.MultipleChoiceField( label=_("Documentation"), choices=[], required=False, widget=widgets.Select2Multiple) location = forms.CharField( - label=_(u"Location"), widget=forms.Textarea, + label=_("Location"), widget=forms.Textarea, required=False, validators=[validators.MaxLengthValidator(200)]) - HEADERS['x'] = FormHeader(_(u"Coordinates")) - x = forms.FloatField(label=_(u"X"), required=False) - estimated_error_x = forms.FloatField(label=_(u"Estimated error for X"), + HEADERS['x'] = FormHeader(_("Coordinates")) + x = forms.FloatField(label=_("X"), required=False) + estimated_error_x = forms.FloatField(label=_("Estimated error for X"), required=False) - y = forms.FloatField(label=_(u"Y"), required=False) - estimated_error_y = forms.FloatField(label=_(u"Estimated error for Y"), + y = forms.FloatField(label=_("Y"), required=False) + estimated_error_y = forms.FloatField(label=_("Estimated error for Y"), required=False) - z = forms.FloatField(label=_(u"Z"), required=False) - estimated_error_z = forms.FloatField(label=_(u"Estimated error for Z"), + z = forms.FloatField(label=_("Z"), required=False) + estimated_error_z = forms.FloatField(label=_("Estimated error for Z"), required=False) spatial_reference_system = forms.ChoiceField( - label=_(u"Spatial Reference System"), required=False, choices=[]) + label=_("Spatial Reference System"), required=False, choices=[]) TYPES = [ FieldType('unit', models.Unit), @@ -368,12 +371,12 @@ class RecordFormGeneral(CustomForm, ManageOldType): if 'pk' in cleaned_data and cleaned_data['pk']: cr = cr.exclude(pk=int(cleaned_data['pk'])) if cr.count(): - raise forms.ValidationError(_(u"This ID already exists for " - u"this operation.")) + raise forms.ValidationError(_("This ID already exists for " + "this operation.")) if not self.cleaned_data.get('parcel', None) and not \ self.cleaned_data.get('town', None): - raise forms.ValidationError(_(u"You have to choose a town or a " - u"parcel.")) + raise forms.ValidationError(_("You have to choose a town or a " + "parcel.")) return cleaned_data @@ -384,8 +387,8 @@ class DatingForm(ManageOldType, forms.Form): 'quality': models.DatingQuality, 'period': models.Period} period = forms.ChoiceField(label=_("Period"), choices=[]) - start_date = forms.IntegerField(label=_(u"Start date"), required=False) - end_date = forms.IntegerField(label=_(u"End date"), required=False) + start_date = forms.IntegerField(label=_("Start date"), required=False) + end_date = forms.IntegerField(label=_("End date"), required=False) quality = forms.ChoiceField(label=_("Quality"), required=False, choices=[]) dating_type = forms.ChoiceField(label=_("Dating type"), required=False, choices=[]) @@ -402,7 +405,7 @@ class DatingForm(ManageOldType, forms.Form): DatingFormSet = formset_factory(DatingForm, can_delete=True, formset=FormSet) DatingFormSet.form_label = _("Dating") -DatingFormSet.form_admin_name = _(u"Context record - 030 - Dating") +DatingFormSet.form_admin_name = _("Context record - 030 - Dating") DatingFormSet.form_slug = "contextrecord-030-datings" @@ -412,7 +415,7 @@ class RecordRelationsForm(OpeRecordRelationsForm): associated_models = {'right_record': models.ContextRecord, 'relation_type': models.RelationType} right_record = forms.ChoiceField( - label=_(u"Context record"), choices=[], required=False) + label=_("Context record"), choices=[], required=False) def __init__(self, *args, **kwargs): crs = None @@ -428,34 +431,34 @@ class RecordRelationsForm(OpeRecordRelationsForm): 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_label = _("Relations") +RecordRelationsFormSet.form_admin_name = _("Context record - 050 - Relations") RecordRelationsFormSet.form_slug = "contextrecord-050-recordrelations" class RecordFormInterpretation(CustomForm, ManageOldType, forms.Form): - form_label = _(u"Interpretation") - form_admin_name = _(u"Context record - 040 - Interpretation") + 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( - label=_(u"Comments on dating"), required=False, + label=_("Comments on dating"), required=False, widget=forms.Textarea) - filling = forms.CharField(label=_(u"Filling"), + filling = forms.CharField(label=_("Filling"), widget=forms.Textarea, required=False) - interpretation = forms.CharField(label=_(u"Interpretation"), + interpretation = forms.CharField(label=_("Interpretation"), widget=forms.Textarea, required=False) - activity = forms.ChoiceField(label=_(u"Activity"), required=False, + activity = forms.ChoiceField(label=_("Activity"), required=False, choices=[]) identification = forms.ChoiceField(label=_("Identification"), required=False, choices=[]) - taq = forms.IntegerField(label=_(u"TAQ"), required=False) - taq_estimated = forms.IntegerField(label=_(u"Estimated TAQ"), + taq = forms.IntegerField(label=_("TAQ"), required=False) + taq_estimated = forms.IntegerField(label=_("Estimated TAQ"), required=False) - tpq = forms.IntegerField(label=_(u"TPQ"), required=False) - tpq_estimated = forms.IntegerField(label=_(u"Estimated TPQ"), + tpq = forms.IntegerField(label=_("TPQ"), required=False) + tpq_estimated = forms.IntegerField(label=_("Estimated TPQ"), required=False) TYPES = [ @@ -465,27 +468,27 @@ class RecordFormInterpretation(CustomForm, ManageOldType, forms.Form): OperationRecordFormSelection = get_form_selection( - 'OperationRecordFormSelection', _(u"Operation search"), 'operation_id', + 'OperationRecordFormSelection', _("Operation search"), 'operation_id', Operation, OperationSelect, 'get-operation', - _(u"You should select an operation.")) + _("You should select an operation.")) class RecordDeletionForm(FinalForm): confirm_msg = " " - confirm_end_msg = _(u"Would you like to delete this context record?") + confirm_end_msg = _("Would you like to delete this context record?") class QAOperationCR(IshtarForm): - town = forms.ChoiceField(label=_(u"Town"), choices=[]) + town = forms.ChoiceField(label=_("Town"), choices=[]) archaeological_site = forms.ChoiceField( label=" ", choices=[], required=False, - help_text=_(u"Only the items associated to the operation can be " - u"selected.") + help_text=_("Only the items associated to the operation can be " + "selected.") ) - label = forms.CharField(label=_(u"ID"), + label = forms.CharField(label=_("ID"), validators=[validators.MaxLengthValidator(200)]) - parcel = forms.ChoiceField(label=_(u"Parcel"), choices=[], required=False) - unit = forms.ChoiceField(label=_(u"Context record type"), required=False, + parcel = forms.ChoiceField(label=_("Parcel"), choices=[], required=False) + unit = forms.ChoiceField(label=_("Context record type"), required=False, choices=[]) TYPES = [ @@ -517,8 +520,8 @@ class QAOperationCR(IshtarForm): ] if self.profil.parcel_mandatory: self.fields['parcel'].choices += [('', '--')] + [ - (str(parcel.pk), u"{} - {}".format(parcel.short_label, - parcel.town)) + (str(parcel.pk), "{} - {}".format(parcel.short_label, + parcel.town)) for parcel in operation.parcels.all()] def save(self, items): @@ -539,9 +542,9 @@ class QAOperationCR(IshtarForm): class QAContextRecordDuplicateForm(IshtarForm): qa_label = forms.CharField(label=_("ID"), max_length=None, required=True) - qa_parcel = forms.ChoiceField(label=_(u"Parcel"), choices=[]) - qa_town = forms.ChoiceField(label=_(u"Town"), choices=[], required=False) - qa_unit = forms.ChoiceField(label=_(u"Context record type"), required=False, + qa_parcel = forms.ChoiceField(label=_("Parcel"), choices=[]) + qa_town = forms.ChoiceField(label=_("Town"), choices=[], required=False) + qa_unit = forms.ChoiceField(label=_("Context record type"), required=False, choices=[]) TYPES = [ -- cgit v1.2.3