summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-10-05 11:57:12 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-11-16 17:04:41 +0100
commit3f96296a443bb0b211cb258b9d2168fa981e8dd3 (patch)
tree7186df87174cfa9141995524e415ff5802ef486b
parent7392510c325410f3cf34176e7256ed8b7430ed34 (diff)
downloadIshtar-3f96296a443bb0b211cb258b9d2168fa981e8dd3.tar.bz2
Ishtar-3f96296a443bb0b211cb258b9d2168fa981e8dd3.zip
Optimize context record wizard
-rw-r--r--archaeological_context_records/wizards.py11
-rw-r--r--archaeological_warehouse/tests.py4
-rw-r--r--ishtar_common/wizards.py4
3 files changed, 16 insertions, 3 deletions
diff --git a/archaeological_context_records/wizards.py b/archaeological_context_records/wizards.py
index da1364b28..e92d9587e 100644
--- a/archaeological_context_records/wizards.py
+++ b/archaeological_context_records/wizards.py
@@ -44,15 +44,18 @@ class RecordWizard(Wizard):
return templates
def get_current_operation(self):
+ if hasattr(self, "_current_operation"):
+ return self._current_operation
step = self.steps.current
if not step:
return
- # manage manualy on creation
+ # manage manually on creation
if step.endswith("_creation"): # an operation has been selected
main_form_key = "selec-" + self.url_name
try:
idx = int(self.session_get_value(main_form_key, "operation_id"))
current_ope = models.Operation.objects.get(pk=idx)
+ self._current_operation = current_ope
return current_ope
except (TypeError, ValueError, ObjectDoesNotExist):
pass
@@ -61,11 +64,13 @@ class RecordWizard(Wizard):
try:
idx = int(self.session_get_value(ope_form_key, "operation"))
current_ope = models.Operation.objects.get(pk=idx)
+ self._current_operation = current_ope
return current_ope
except (TypeError, ValueError, ObjectDoesNotExist):
pass
current_cr = self.get_current_object()
if current_cr:
+ self._current_operation = current_cr.operation
return current_cr.operation
def get_context_data(self, form, **kwargs):
@@ -123,11 +128,11 @@ class RecordWizard(Wizard):
operation = self.get_current_operation()
if not operation:
return []
- q = models.ContextRecord.objects.filter(operation=operation)
+ q = models.ContextRecord.objects.filter(operation_id=operation.pk)
obj = self.get_current_object()
if obj and obj.pk:
q = q.exclude(pk=obj.pk)
- return [(cr.pk, str(cr)) for cr in q.all()]
+ return [(cr.pk, cr.cached_label) for cr in q.all()]
class RecordModifWizard(RecordWizard):
diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py
index 7cd5af848..2aa45d806 100644
--- a/archaeological_warehouse/tests.py
+++ b/archaeological_warehouse/tests.py
@@ -269,6 +269,10 @@ class SerializationTest(GenericSerializationTest, FindInit, TestCase):
res[("operations", "archaeological_operations__Operation")]
)
self.assertEqual(len(ope_json), 1)
+ # force clean
+ for f in Find.objects.all():
+ for h in f.history.all():
+ h.delete()
def test_cr_serialization_with_warehouse_filter(self):
res = self.generic_serialization_test(
diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py
index 7b636538d..2b0a47a72 100644
--- a/ishtar_common/wizards.py
+++ b/ishtar_common/wizards.py
@@ -1330,6 +1330,8 @@ class Wizard(IshtarWizard):
def get_current_object(self):
"""Get the current object for an instanced wizard"""
+ if hasattr(self, "_current_object"):
+ return self._current_object
current_obj = None
for key in self.main_item_select_keys:
main_form_key = key + self.url_name
@@ -1341,6 +1343,8 @@ class Wizard(IshtarWizard):
break
except (TypeError, ValueError, ObjectDoesNotExist):
pass
+ if current_obj:
+ self._current_object = current_obj
return current_obj
def get_form_initial(self, step, data=None):