From 87b2c52f3d32d32187cf318a39078acf58041ab8 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 14 Nov 2018 18:02:04 +0100 Subject: Reorganize treatment actions - add a direct to treatements --- archaeological_finds/wizards.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'archaeological_finds/wizards.py') diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py index 0e0fe80e1..e90fa745c 100644 --- a/archaeological_finds/wizards.py +++ b/archaeological_finds/wizards.py @@ -119,6 +119,29 @@ class TreatmentWizard(Wizard): kwargs['user'] = self.request.user return kwargs + def get_current_find(self): + step = self.steps.current + if not step: + return + find_form_key = 'selecfind-treatment_creation' + find_id = self.session_get_value(find_form_key, "resulting_pk") + try: + return models.Find.objects.get(pk=int(find_id)) + except(TypeError, ValueError, ObjectDoesNotExist): + pass + + def get_form_initial(self, step, data=None): + initial = super(TreatmentWizard, self).get_form_initial(step) + if step != 'basetreatment-treatment_creation': + return initial + find = self.get_current_find() + if not find or not find.container: + return initial + if not initial: + initial = {} + initial['location'] = find.container.location.pk + return initial + def get_extra_model(self, dct, form_list): """ Get items concerned by the treatment -- cgit v1.2.3