diff options
Diffstat (limited to 'archaeological_operations/wizards.py')
| -rw-r--r-- | archaeological_operations/wizards.py | 103 | 
1 files changed, 2 insertions, 101 deletions
diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index 7afe73442..44b3988eb 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -48,8 +48,6 @@ class OperationSearch(SearchWizard):  class OperationWizard(Wizard):      model = models.Operation -    object_parcel_type = "operation" -    parcel_step_key = "parcels"      relations_step_key = "relations"      # step including the current(s) town(s)      town_step_keys = ["towns-", "townsgeneral-"] @@ -62,9 +60,7 @@ class OperationWizard(Wizard):      def get_template_names(self):          templates = super(OperationWizard, self).get_template_names()          current_step = self.steps.current -        if current_step.startswith(self.parcel_step_key): -            templates = ["ishtar/wizard/parcels_wizard.html"] + templates -        elif current_step.startswith(self.relations_step_key): +        if current_step.startswith(self.relations_step_key):              templates = ["ishtar/wizard/relations_wizard.html"] + templates          return templates @@ -94,13 +90,8 @@ class OperationWizard(Wizard):          """          context = super(OperationWizard, self).get_context_data(form, **kwargs)          step = self.steps.current -        if step.startswith("towns"): +        if step.startswith("general"):              context["TOWNS"] = self.get_towns() -        elif step.startswith("parcels-") and self.get_current_file(): -            # if a file is associated 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: @@ -121,31 +112,6 @@ class OperationWizard(Wizard):              pass          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() -        if operation: -            for parcel in operation.parcels.all(): -                current_parcels.append( -                    (parcel.town, parcel.section, parcel.parcel_number) -                ) -                parcels.append((parcel.pk, parcel.short_label)) -        try: -            for parcel in file.parcels.all(): -                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]) -      def get_form(self, step=None, data=None, files=None):          """          Manage specifics fields @@ -163,43 +129,6 @@ class OperationWizard(Wizard):          # manage the dynamic choice of towns          if step.startswith("towns") and hasattr(form, "management_form"):              data["TOWNS"] = self.get_towns() -        elif step.startswith(self.parcel_step_key) and hasattr(form, "management_form"): -            file = self.get_current_file() -            if file: -                data["PARCELS"] = self.get_available_parcels(file) -            else: -                town_ids = [] -                for town_step_key in self.town_step_keys: -                    town_form_key = town_step_key + self.url_name -                    town_ids = ( -                        self.session_get_value( -                            town_form_key, -                            self.town_input_id, -                            multi=self.towns_formset, -                            multi_value=self.multi_towns, -                        ) -                        or [] -                    ) -                    if town_ids: -                        towns = [] -                        if type(town_ids) == str: -                            town_ids = [town_ids] -                        for ids in town_ids: -                            for d in ids.split(","): -                                if d: -                                    towns.append(d) -                        town_ids = towns -                        break -                if type(town_ids) not in (list, tuple): -                    town_ids = [town_ids] -                towns = [] -                for town_id in town_ids: -                    try: -                        town = models.Town.objects.get(pk=int(town_id)) -                        towns.append((town.pk, str(town))) -                    except (ValueError, ObjectDoesNotExist): -                        pass -                data["TOWNS"] = sorted(towns, key=lambda x: x[1])          data = data or None          form = super(OperationWizard, self).get_form(step, data, files)          return form @@ -267,34 +196,6 @@ class OperationWizard(Wizard):          initial.update(self.__copy_fields(file, keys))          return initial -    def post(self, *args, **kwargs): -        request = self.request -        post_data = request.POST.copy() - -        # add all parcel from available in the archaeological file -        if not post_data.get("add_all_parcels", None): -            return super(OperationWizard, self).post(*args, **kwargs) - -        file = self.get_current_file() -        if not file: -            return super(OperationWizard, self).post(*args, **kwargs) -        parcel_form_key = self.steps.current -        # parcel_form_key = "parcels-" + self.url_name -        idx = -1 -        # remove non relevant deleted keys -        for k in post_data.keys(): -            if k.startswith(parcel_form_key) and k.endswith("-DELETE"): -                post_data.pop(k) -        for idx, parcel in enumerate(self.get_available_parcels(file)): -            parcel_pk, parcel_name = parcel -            post_data["%s-%d-parcel" % (parcel_form_key, idx)] = parcel_pk -        post_data[parcel_form_key + "-TOTAL_FORMS"] = idx + 2 -        request.POST = post_data -        return super(OperationWizard, self).post(*args, **kwargs) - -    def post_save(self): -        self.current_object.clean_parcel_duplicates() -  class OperationModificationWizard(OperationWizard):      modification = True  | 
