summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-05-23 10:53:43 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-05-23 10:53:43 +0200
commit1eaa2257d7cc72ed6c25df393c591da544a12f53 (patch)
treefd85fae64a1a0c00c8efb9afb98614fe1c8fa8c7
parent1351334e7914608fc2de87b806846bc37f671097 (diff)
downloadIshtar-1eaa2257d7cc72ed6c25df393c591da544a12f53.tar.bz2
Ishtar-1eaa2257d7cc72ed6c25df393c591da544a12f53.zip
Document generation: better layout for VALUES
-rw-r--r--archaeological_context_records/models.py7
-rw-r--r--archaeological_files/models.py5
-rw-r--r--archaeological_finds/models_finds.py22
-rw-r--r--archaeological_finds/models_treatments.py8
-rw-r--r--archaeological_operations/models.py7
-rw-r--r--ishtar_common/models.py29
-rw-r--r--ishtar_common/utils_secretary.py4
7 files changed, 49 insertions, 33 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index f728aef57..b3e4be9f0 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -520,12 +520,13 @@ 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)
+ def get_values(self, prefix='', no_values=False, no_base_finds=True):
+ values = super(ContextRecord, self).get_values(prefix=prefix,
+ no_values=no_values)
if prefix and no_base_finds:
return values
values[prefix + 'base_finds'] = [
- bf.get_values(prefix=prefix)
+ bf.get_values(prefix=prefix, no_values=True)
for bf in self.base_finds.distinct().all()
]
return values
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index a2cac6b15..7d86bcff8 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -523,8 +523,9 @@ class File(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
get_short_menu_class=get_short_menu_class)
return cls._return_get_owns(owns, values, get_short_menu_class)
- def get_values(self, prefix=''):
- values = super(File, self).get_values(prefix=prefix)
+ def get_values(self, prefix='', no_values=False):
+ values = super(File, self).get_values(prefix=prefix,
+ no_values=no_values)
return get_values_town_related(self, prefix, values)
def render_parcels(self):
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index d3abd2c8a..e62c41887 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -333,12 +333,13 @@ 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)
+ def get_values(self, prefix='', no_values=False, no_find=False):
+ values = super(BaseFind, self).get_values(prefix=prefix,
+ no_values=no_values)
if no_find:
return values
values[prefix + "finds"] = [
- find.get_values(prefix=prefix, no_base_finds=True)
+ find.get_values(no_values=True, no_base_finds=True)
for find in self.find.order_by('pk').all()
]
return values
@@ -640,10 +641,12 @@ class FindBasket(Basket, MainItem, ValueGetter):
("view_own_find", u"Can view own Find"),
)
- def get_values(self, prefix=''):
- values = super(FindBasket, self).get_values(prefix=prefix)
+ def get_values(self, prefix='', no_values=False):
+ values = super(FindBasket, self).get_values(prefix=prefix,
+ no_values=no_values)
values[prefix + "items"] = [
- item.get_values() for item in self.items.distinct().all()
+ item.get_values(no_values=True)
+ for item in self.items.distinct().all()
]
return values
@@ -1597,12 +1600,13 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, QRCodeItem,
return
return self.base_finds.order_by('-pk').all()[0]
- def get_values(self, prefix='', no_base_finds=False):
- values = super(Find, self).get_values(prefix=prefix)
+ def get_values(self, prefix='', no_values=False, no_base_finds=False):
+ values = super(Find, self).get_values(prefix=prefix,
+ no_values=no_values)
if no_base_finds:
return values
values[prefix + "base_finds"] = [
- base_find.get_values(prefix=prefix, no_find=True)
+ base_find.get_values(no_values=True, no_find=True)
for base_find in self.base_finds.distinct().order_by('-pk').all()
]
return values
diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py
index 6f24e1474..c35d3710c 100644
--- a/archaeological_finds/models_treatments.py
+++ b/archaeological_finds/models_treatments.py
@@ -312,8 +312,9 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem,
]
return actions
- def get_values(self, prefix=''):
- values = super(Treatment, self).get_values(prefix=prefix)
+ def get_values(self, prefix='', no_values=False):
+ values = super(Treatment, self).get_values(prefix=prefix,
+ no_values=no_values)
values[prefix + "upstream_finds"] = u" ; ".join(
[unicode(up) for up in self.upstream.all()])
values[prefix + "downstream_finds"] = u" ; ".join(
@@ -324,7 +325,8 @@ class Treatment(DashboardFormItem, ValueGetter, BaseHistorizedItem,
find = self.upstream.all()[0]
if 'associatedfind_' not in prefix:
values.update(
- find.get_values(prefix=prefix + 'associatedfind_'))
+ find.get_values(prefix=prefix + 'associatedfind_',
+ no_values=True))
return values
def pre_save(self):
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 6ae219461..9ab3b317b 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -973,13 +973,14 @@ class Operation(ClosedItem, BaseHistorizedItem, QRCodeItem, GeoItem, OwnPerms,\
self.save()
return self.cached_label
- def get_values(self, prefix=''):
- values = super(Operation, self).get_values(prefix=prefix)
+ def get_values(self, prefix='', no_values=False):
+ values = super(Operation, self).get_values(prefix=prefix,
+ no_values=no_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)
+ cr.get_values(prefix=prefix, no_values=True, no_base_finds=False)
for cr in self.context_record.all()
]
return values
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index e78e18704..612b57b03 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -120,14 +120,16 @@ class ValueGetter(object):
if not hasattr(self, 'documents'):
return values
values[prefix + "documents"] = [
- doc.get_values(prefix=prefix) for doc in self.documents.all()
+ doc.get_values(no_values=True)
+ for doc in self.documents.all()
]
if hasattr(self, "main_image") and self.main_image and hasattr(
self.main_image, "get_values"):
- values[prefix + "main_image"] = self.main_image.get_values()
+ values[prefix + "main_image"] = self.main_image.get_values(
+ no_values=True)
return values
- def get_values(self, prefix=''):
+ def get_values(self, prefix='', no_values=False):
if not prefix:
prefix = self._prefix
values = {}
@@ -154,20 +156,27 @@ class ValueGetter(object):
if val.endswith('.None'):
val = ''
values[key] = val
- if prefix and prefix != self._prefix:
+ if (prefix and prefix != self._prefix) or no_values:
# do not provide KEYS and VALUES for sub-items
return values
- values['KEYS'] = u'\n'.join(values.keys())
value_list = []
for key in values.keys():
if key in ('KEYS', 'VALUES'):
continue
value_list.append((key, unicode(values[key])))
+ """
values['VALUES'] = u'\n'.join(
[u"%s: %s" % (k, v) for k, v in sorted(value_list,
key=lambda x: x[0])])
+ """
for global_var in GlobalVar.objects.all():
values[global_var.slug] = global_var.value or ""
+ values['VALUES'] = json.dumps(
+ values, indent=4, sort_keys=True,
+ skipkeys=True, ensure_ascii=False,
+ separators=("", " : "),
+ ).replace(" " * 4, "\t")
+
return values
@classmethod
@@ -3780,8 +3789,9 @@ class Person(Address, Merge, OwnPerms, ValueGetter):
values.append(attached_to)
return u" ".join(values)
- def get_values(self, prefix=''):
- values = super(Person, self).get_values(prefix=prefix)
+ def get_values(self, prefix='', no_values=False):
+ values = super(Person, self).get_values(prefix=prefix,
+ no_values=no_values)
if not self.attached_to:
values.update(
Person.get_empty_values(prefix=prefix + 'attached_to_'))
@@ -4629,8 +4639,9 @@ class Document(BaseHistorizedItem, OwnPerms, ImageModel, ValueGetter):
return ""
return self.image.path
- def get_values(self, prefix=""):
- values = super(Document, self).get_values(prefix=prefix)
+ def get_values(self, prefix="", no_values=False):
+ values = super(Document, self).get_values(prefix=prefix,
+ no_values=no_values)
values[prefix + "image_path"] = self.image_path
return values
diff --git a/ishtar_common/utils_secretary.py b/ishtar_common/utils_secretary.py
index 6f605590e..15fb69a2d 100644
--- a/ishtar_common/utils_secretary.py
+++ b/ishtar_common/utils_secretary.py
@@ -25,10 +25,6 @@ class IshtarSecretaryRenderer(Renderer):
# self.environment.filters['pad'] = pad_string
def ishtar_media_loader(self, media, *args, **kwargs):
- """Loads a file from the file system.
- :param media: A file object or a relative or absolute path of a file.
- :type media: unicode
- """
image_file, mime = self.fs_loader(media, *args, **kwargs)
if "width" in kwargs:
kwargs['frame_attrs']['svg:width'] = kwargs["width"]