summaryrefslogtreecommitdiff
path: root/archaeological_finds
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 /archaeological_finds
parent7eba12011665ebb62c15a7b54c45237dc4f71e86 (diff)
downloadIshtar-9f577da421b5b909fea2caff3049aea1cd7acf30.tar.bz2
Ishtar-9f577da421b5b909fea2caff3049aea1cd7acf30.zip
Document templates: manage finds, base finds, baskets relations
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/models_finds.py40
-rw-r--r--archaeological_finds/models_treatments.py9
2 files changed, 26 insertions, 23 deletions
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)