From 12e9870e2aa0659de98a9122fbc4ab16b0877449 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 16 Sep 2024 12:45:00 +0200 Subject: ✨ Context records relations: remove form from the wizard to put in a specific form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- archaeological_operations/forms.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'archaeological_operations/forms.py') diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index cf9df8594..d3c797ff2 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -371,10 +371,13 @@ class ParcelFormSet(FormSet): class RecordRelationsForm(ManageOldType): base_model = 'right_relation' + ERROR_MISSING = _("You should select an operation.") current_model = models.RelationType current_related_model = models.Operation + associated_models = {'right_record': models.Operation, 'relation_type': models.RelationType} + pk = forms.IntegerField(required=False, widget=forms.HiddenInput) relation_type = forms.ChoiceField(label=_("Relation type"), choices=[], required=False) right_record = forms.IntegerField( @@ -388,9 +391,9 @@ class RecordRelationsForm(ManageOldType): self.left_record = None if 'left_record' in kwargs: self.left_record = kwargs.pop('left_record') - super(RecordRelationsForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.fields['relation_type'].choices = \ - models.RelationType.get_types( + self.current_model.get_types( initial=self.init_data.get('relation_type')) @classmethod @@ -409,7 +412,7 @@ class RecordRelationsForm(ManageOldType): cleaned_data = self.cleaned_data if (cleaned_data.get('relation_type', None) and not cleaned_data.get('right_record', None)): - raise forms.ValidationError(_("You should select an operation.")) + raise forms.ValidationError(self.ERROR_MISSING) if (not cleaned_data.get('relation_type', None) and cleaned_data.get('right_record', None)): raise forms.ValidationError( @@ -455,6 +458,7 @@ class RecordRelationsForm(ManageOldType): class RecordRelationsFormSetBase(FormSet): + delete_widget = forms.CheckboxInput # passing left_record should be nicely done with form_kwargs with Django 1.9 # with no need of all these complications @@ -462,7 +466,7 @@ class RecordRelationsFormSetBase(FormSet): self.left_record = None if 'left_record' in kwargs: self.left_record = kwargs.pop('left_record') - super(RecordRelationsFormSetBase, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def _construct_forms(self): # instantiate all the forms and put them in self.forms -- cgit v1.2.3