summaryrefslogtreecommitdiff
path: root/archaeological_context_records/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_context_records/forms.py')
-rw-r--r--archaeological_context_records/forms.py42
1 files changed, 20 insertions, 22 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
index 70e632af1..11d4cbbb1 100644
--- a/archaeological_context_records/forms.py
+++ b/archaeological_context_records/forms.py
@@ -677,7 +677,7 @@ class QAOperationCR(IshtarForm):
]
if self.profil.parcel_mandatory:
self.fields["parcel"].choices += [("", "--")] + [
- (str(parcel.pk), "{} - {}".format(parcel.short_label, parcel.town))
+ (str(parcel.pk), "{} - {}".format(parcel.town, parcel.short_label))
for parcel in operation.parcels.all()
]
@@ -848,31 +848,29 @@ class QAContextRecordFormMulti(QAForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.items = kwargs.pop("items")
- disable = False
+ # manage parcel field
if "qa_parcel" not in self.fields or not self.items:
return
op_pk = self.items[0].operation_id
- if len(self.items) > 1:
- for cr in self.items[1:]:
- if op_pk != cr.operation_id:
- disable = self.fields["qa_parcel"].disabled = True
-
- self.fields["qa_parcel"].widget = forms.TextInput(
- attrs={
- "class": 'w-100',
- "placeholder": _(
- "Parcel can be modified only if operations are the same"
- )}
- )
- break
- if not disable:
- choices = [
- (p.pk, str(p)) for p in Parcel.objects.filter(operation_id=op_pk).all()
- ]
- self.fields["qa_parcel"].choices = choices
- if len(choices) == 1:
- self.fields["qa_parcel"].disabled = True
+ if len(self.items) > 1 and any(
+ (1 for cr in self.items[1:] if op_pk != cr.operation_id)):
+ self.fields["qa_parcel"].disabled = True
+
+ self.fields["qa_parcel"].widget = forms.TextInput(
+ attrs={
+ "class": 'w-100',
+ "placeholder": _(
+ "Parcel can be modified only if operations are the same"
+ )}
+ )
+ return
+ choices = [("", "--")]
+ choices += [
+ (p.pk, "{} - {}".format(p.town, p.short_label))
+ for p in Parcel.objects.filter(operation_id=op_pk).all()
+ ]
+ self.fields["qa_parcel"].choices = choices
def clean(self):
cleaned_data = super().clean()