summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-01-05 16:57:05 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-02-28 12:15:23 +0100
commitd319e01c50deeba74674b9e0a6389f3637ce154a (patch)
tree8b84cd2075d6d78144126b73febe7cb0e0f9792c
parent5a4747a863ee926223148bad3163b4b7135328d3 (diff)
downloadIshtar-d319e01c50deeba74674b9e0a6389f3637ce154a.tar.bz2
Ishtar-d319e01c50deeba74674b9e0a6389f3637ce154a.zip
Labels: quick access to operation on the container
-rw-r--r--archaeological_operations/models.py4
-rw-r--r--archaeological_warehouse/models.py20
-rw-r--r--ishtar_common/models.py8
3 files changed, 29 insertions, 3 deletions
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 8436121a4..246934d91 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -1238,9 +1238,11 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem,
values = super(Operation, self).get_values(
prefix=prefix, no_values=no_values, filtr=filtr, **kwargs)
values = get_values_town_related(self, prefix, values, filtr=filtr)
+ exclude = kwargs.get("exclude", [])
if prefix:
return values
- if not filtr or prefix + 'context_records' in filtr:
+ if (not filtr or prefix + 'context_records' in filtr) and \
+ prefix + "context_records" not in exclude:
kwargs["no_base_finds"] = False
values[prefix + 'context_records'] = [
cr.get_values(prefix=prefix, no_values=True, filtr=None,
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 06944fa38..efbdd922d 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -1311,10 +1311,30 @@ class Container(DocumentItem, Merge, LightHistorizedItem,
prefix=prefix, no_values=no_values, filtr=filtr, **kwargs)
if not filtr or prefix + 'finds' in filtr:
+ kwargs["exclude"] = [prefix + "container", prefix + "container_ref"]
+ # prevent recursive call
values[prefix + 'finds'] = [
f.get_values(
prefix=prefix, no_values=True, filtr=None, **kwargs)
for f in self.finds.distinct().all()]
+ if (not filtr or prefix + 'operation' in filtr or
+ prefix + "context_record" in filtr) and self.finds.count():
+ # assume that only one operation is in this container
+ # you should know what you are doing when using theses variables
+ f = self.finds.all()[0]
+ bf = f.get_first_base_find()
+ if bf:
+ cr = bf.context_record
+ if not filtr or prefix + "context_record" in filtr:
+ kwargs["exclude"] = [prefix + "operation"]
+ values[prefix + 'context_record'] = \
+ cr.get_values(
+ prefix=prefix, no_values=True, filtr=None, **kwargs)
+ if not filtr or prefix + "operation" in filtr:
+ kwargs["exclude"] = [prefix + "context_records"]
+ values[prefix + 'operation'] = \
+ cr.operation.get_values(
+ prefix=prefix, no_values=True, filtr=None, **kwargs)
return values
def get_extra_actions(self, request):
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 32ae95594..9adba889b 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -161,9 +161,11 @@ class ValueGetter(object):
def get_values(self, prefix='', no_values=False, filtr=None, **kwargs):
if not prefix:
prefix = self._prefix
+ exclude = kwargs.get("exclude", [])
values = {}
- if hasattr(self, "qrcode") and (not filtr
- or 'qrcode_path' in filtr):
+ if hasattr(self, "qrcode") and (
+ not filtr or prefix + 'qrcode_path' in filtr) and \
+ prefix + 'qrcode_path' not in exclude:
values[prefix + 'qrcode_path'] = self.qrcode_path
for field_name in get_all_field_names(self):
try:
@@ -172,6 +174,8 @@ class ValueGetter(object):
continue
if field_name in self.GET_VALUES_EXCLUDE_FIELDS:
continue
+ if prefix + field_name in exclude:
+ continue
if hasattr(value, 'get_values'):
new_prefix = prefix + field_name + '_'
values.update(