From 9f9ef1c26fcc0a22545b0795a3978943f30241a3 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 14 Mar 2022 12:15:41 +0100 Subject: QA context record bulk-update: small refactoring --- archaeological_context_records/forms.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 8993675e6..9b2ae129c 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -753,16 +753,16 @@ class QAContextRecordFormMulti(QAForm): def __init__(self, *args, **kwargs): super(QAContextRecordFormMulti, self).__init__(*args, **kwargs) self.items = kwargs.pop("items") - op_pk = 0 disable = False - for cr in self.items: - if op_pk != cr.operation.pk and op_pk > 0: - disable = self.fields["qa_parcel"].disabled = True - self.fields["qa_parcel"].choices = [ - (1, _("Parcel can be modified only if operations are the same")) - ] - break - op_pk = cr.operation.pk + if self.items > 1: + op_pk = self.items[0].pk + for cr in self.items[1:]: + if op_pk != cr.operation.pk: + disable = self.fields["qa_parcel"].disabled = True + self.fields["qa_parcel"].choices = [ + (1, _("Parcel can be modified only if operations are the same")) + ] + break if not disable: self.fields["qa_parcel"].choices += [ (p.pk, str(p)) for p in Parcel.objects.filter( @@ -770,7 +770,6 @@ class QAContextRecordFormMulti(QAForm): ).all() ] - def clean(self): cleaned_data = super().clean() r_type = cleaned_data.get("qa_relation_type") -- cgit v1.2.3