diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-24 19:14:37 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:25 +0100 | 
| commit | 16a47f887447ecccd56fc848aee95fa56af92548 (patch) | |
| tree | f96e518b2766d2a300829d0e5f9fac491d6d065d /archaeological_operations/models.py | |
| parent | 0eab67538b8f2af9283bf1e77438763914e355b7 (diff) | |
| download | Ishtar-16a47f887447ecccd56fc848aee95fa56af92548.tar.bz2 Ishtar-16a47f887447ecccd56fc848aee95fa56af92548.zip | |
get_values: get containers from operation - material_types_code from finds
Diffstat (limited to 'archaeological_operations/models.py')
| -rw-r--r-- | archaeological_operations/models.py | 26 | 
1 files changed, 23 insertions, 3 deletions
| diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index b7841450c..240283d1a 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -22,6 +22,7 @@ import datetime  from itertools import groupby  import uuid +from django.apps import apps  from django.conf import settings  from django.contrib.gis.db import models  from django.contrib.gis.db.models.aggregates import Union @@ -1234,6 +1235,22 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem,      def __str__(self):          return self.cached_label or "" +    DOC_VALUES = [ +        ("context_records.", _("List of associated context records")), +        ("containers.", _("List of associated containers")), +    ] + +    def get_containers_values(self, filtr, exclude) -> list:  # Container value +        # list +        Container = apps.get_model("archaeological_warehouse", "Container") +        containers = [] +        q = Container.objects.filter( +            finds__base_finds__context_record__operation=self).distinct("index") +        exclude += ["operation", "context_record"] +        for c in q.order_by("index").all(): +            containers.append(c.get_values(filtr=filtr, exclude=exclude)) +        return containers +      def get_values(self, prefix='', no_values=False, filtr=None, **kwargs):          values = super(Operation, self).get_values(              prefix=prefix, no_values=no_values, filtr=filtr, **kwargs) @@ -1241,14 +1258,17 @@ class Operation(ClosedItem, DocumentItem, BaseHistorizedItem,          exclude = kwargs.get("exclude", [])          if prefix:              return values -        if (not filtr or prefix + 'context_records' in filtr) and \ -                prefix + "context_records" not in exclude: +        if (not filtr or 'context_records' in filtr) and \ +                "context_records" not in exclude:              kwargs["no_base_finds"] = False -            values[prefix + 'context_records'] = [ +            values['context_records'] = [                  cr.get_values(prefix=prefix, no_values=True, filtr=None,                                **kwargs)                  for cr in self.context_record.all()              ] +        if (not filtr or "containers" in filtr) \ +                and "context_records" not in exclude: +            values["containers"] = self.get_containers_values(filtr, exclude)          return values      def public_representation(self): | 
