From a69028c181e43deb86766019a100c5dcd0814502 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 10 Jul 2015 21:51:54 +0200 Subject: Parcels: display a warning when automatically adding parcel to a file from an operation --- archaeological_operations/wizards.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'archaeological_operations/wizards.py') diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index 081281d8a..707f4f96f 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -85,6 +85,10 @@ class OperationWizard(Wizard): elif step.startswith('parcels-') and self.get_current_file(): # if a file is acciated to the operation add the button "Add all" context['add_all'] = True + if step.startswith('parcels') and\ + hasattr(self, 'automatic_parcel_association'): + context['automatic_parcel_association'] = \ + self.automatic_parcel_association # reminder of the current file reminder = self.get_reminder() if reminder: @@ -108,6 +112,7 @@ class OperationWizard(Wizard): return sorted(towns, key=lambda x:x[1]) def get_available_parcels(self, file): + self.automatic_parcel_association = False parcels = [] current_parcels = [] operation = self.get_current_object() @@ -118,10 +123,14 @@ class OperationWizard(Wizard): parcels.append((parcel.pk, parcel.short_label)) try: for parcel in file.parcels.all(): - if (parcel.town, parcel.section, parcel.parcel_number) \ - in current_parcels: + key = (parcel.town, parcel.section, parcel.parcel_number) + if key in current_parcels: + current_parcels.pop(current_parcels.index(key)) continue parcels.append((parcel.pk, parcel.short_label)) + if current_parcels: + # not all operation parcel exist for the file + self.automatic_parcel_association = True except (ValueError, ObjectDoesNotExist): pass return sorted(parcels, key=lambda x:x[1]) -- cgit v1.2.3