summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-05-22 11:07:10 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-05-22 11:07:10 +0200
commit9f577da421b5b909fea2caff3049aea1cd7acf30 (patch)
tree87e2fa2dee181df10b10441d19b97b8b934c727f
parent7eba12011665ebb62c15a7b54c45237dc4f71e86 (diff)
downloadIshtar-9f577da421b5b909fea2caff3049aea1cd7acf30.tar.bz2
Ishtar-9f577da421b5b909fea2caff3049aea1cd7acf30.zip
Document templates: manage finds, base finds, baskets relations
-rw-r--r--archaeological_context_records/models.py10
-rw-r--r--archaeological_finds/models_finds.py40
-rw-r--r--archaeological_finds/models_treatments.py9
-rw-r--r--archaeological_operations/models.py9
-rw-r--r--ishtar_common/models.py4
5 files changed, 47 insertions, 25 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 01595feed..f728aef57 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -520,6 +520,16 @@ class ContextRecord(BulkUpdatedItem, BaseHistorizedItem, QRCodeItem, GeoItem,
def __unicode__(self):
return self.short_label
+ def get_values(self, prefix='', no_base_finds=True):
+ values = super(ContextRecord, self).get_values(prefix=prefix)
+ if prefix and no_base_finds:
+ return values
+ values[prefix + 'base_finds'] = [
+ bf.get_values(prefix=prefix)
+ for bf in self.base_finds.distinct().all()
+ ]
+ return values
+
def get_town_centroid(self):
if self.town:
return self.town.center, self._meta.verbose_name
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 3dbda8472..d3abd2c8a 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -265,7 +265,8 @@ class BFBulkView(object):
"""
-class BaseFind(BulkUpdatedItem, BaseHistorizedItem, GeoItem, OwnPerms):
+class BaseFind(BulkUpdatedItem, BaseHistorizedItem, GeoItem, OwnPerms,
+ ValueGetter):
EXTERNAL_ID_KEY = 'base_find_external_id'
EXTERNAL_ID_DEPENDENCIES = ['find']
SLUG = 'basefind'
@@ -332,6 +333,16 @@ class BaseFind(BulkUpdatedItem, BaseHistorizedItem, GeoItem, OwnPerms):
def natural_key(self):
return (self.external_id, )
+ def get_values(self, prefix='', no_find=False):
+ values = super(BaseFind, self).get_values(prefix=prefix)
+ if no_find:
+ return values
+ values[prefix + "finds"] = [
+ find.get_values(prefix=prefix, no_base_finds=True)
+ for find in self.find.order_by('pk').all()
+ ]
+ return values
+
def get_last_find(self):
# TODO: manage virtuals - property(last_find) ?
finds = self.find.filter().order_by("-order").all()
@@ -609,7 +620,7 @@ WEIGHT_UNIT = (('g', _(u"g")),
('kg', _(u"kg")),)
-class FindBasket(Basket, MainItem):
+class FindBasket(Basket, MainItem, ValueGetter):
SHOW_URL = 'show-findbasket'
SLUG = "findbasket"
items = models.ManyToManyField('Find', blank=True, related_name='basket')
@@ -629,6 +640,13 @@ class FindBasket(Basket, MainItem):
("view_own_find", u"Can view own Find"),
)
+ def get_values(self, prefix=''):
+ values = super(FindBasket, self).get_values(prefix=prefix)
+ values[prefix + "items"] = [
+ item.get_values() for item in self.items.distinct().all()
+ ]
+ return values
+
def get_extra_actions(self, request):
"""
For sheet template: return "Manage basket" action
@@ -1579,21 +1597,15 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, QRCodeItem,
return
return self.base_finds.order_by('-pk').all()[0]
- def get_values(self, prefix=''):
+ def get_values(self, prefix='', no_base_finds=False):
values = super(Find, self).get_values(prefix=prefix)
- return values
- # TODO
- bf = self.get_first_base_find()
- if not bf:
+ if no_base_finds:
return values
- operation = bf.context_record.operation
- values[prefix + "operation"] = [
- {
- "common_name": operation.common_name,
- "code_patriarche": operation.code_patriarche,
- "address": operation.address
- }
+ values[prefix + "base_finds"] = [
+ base_find.get_values(prefix=prefix, no_find=True)
+ for base_find in self.base_finds.distinct().order_by('-pk').all()
]
+ return values
@property
def reference(self):
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index e8d6256ef..6f24e1474 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -1008,15 +1008,6 @@ class TreatmentFile(DashboardFormItem, ClosedItem, BaseHistorizedItem,
for attr in ('year', 'index', 'internal_reference',
'name') if getattr(self, attr)])
- def get_values(self, prefix=''):
- values = super(TreatmentFile, self).get_values(prefix=prefix)
- if not self.associated_basket:
- return values
- values[prefix + "basket"] = [
- find.get_values() for find in self.associated_basket.items.all()
- ]
- return values
-
def get_extra_actions(self, request):
# url, base_text, icon, extra_text, extra css class, is a quick action
actions = super(TreatmentFile, self).get_extra_actions(request)
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 860422980..6ae219461 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -975,7 +975,14 @@ class Operation(ClosedItem, BaseHistorizedItem, QRCodeItem, GeoItem, OwnPerms,\
def get_values(self, prefix=''):
values = super(Operation, self).get_values(prefix=prefix)
- return get_values_town_related(self, prefix, values)
+ values = get_values_town_related(self, prefix, values)
+ if prefix:
+ return values
+ values[prefix + 'context_records'] = [
+ cr.get_values(prefix=prefix, no_base_finds=False)
+ for cr in self.context_record.all()
+ ]
+ return values
@classmethod
def _get_department_code(cls, value):
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 8774ed951..d4a6d4c5c 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -111,7 +111,9 @@ class ValueGetter(object):
_prefix = ""
GET_VALUES_EXTRA = []
COL_LABELS = {}
- GET_VALUE_EXCLUDE_FIELDS = ['search_vector', 'id']
+ GET_VALUE_EXCLUDE_FIELDS = [
+ 'search_vector', 'id', 'multi_polygon', 'point_2d', 'point',
+ 'history_m2m']
def get_values(self, prefix=''):
if not prefix: