summaryrefslogtreecommitdiff
path: root/archaeological_operations/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-09-16 12:45:00 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2024-09-16 12:46:09 +0200
commit12e9870e2aa0659de98a9122fbc4ab16b0877449 (patch)
tree36d375089b787fbc3649ad54bb9e7e3b2b5741e0 /archaeological_operations/forms.py
parentdb5ecbb7b69ff668ca005bd9535bf595b79e649e (diff)
downloadIshtar-12e9870e2aa0659de98a9122fbc4ab16b0877449.tar.bz2
Ishtar-12e9870e2aa0659de98a9122fbc4ab16b0877449.zip
✨ Context records relations: remove form from the wizard to put in a specific form
Diffstat (limited to 'archaeological_operations/forms.py')
-rw-r--r--archaeological_operations/forms.py12
1 files changed, 8 insertions, 4 deletions
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