summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-08-22 09:50:31 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-08-22 09:50:31 +0200
commit3554529456334662f035f41b9b7479c345439238 (patch)
treeaa5970043b874b009ecb9e8f9b9b810b5797248c
parentbc341909666384b666b7ba3ef36c44a4050b2138 (diff)
downloadIshtar-3554529456334662f035f41b9b7479c345439238.tar.bz2
Ishtar-3554529456334662f035f41b9b7479c345439238.zip
More explicit label for operation and files (refs #1324)
-rw-r--r--archaeological_files/models.py6
-rw-r--r--archaeological_operations/models.py4
-rw-r--r--ishtar_common/utils.py8
3 files changed, 14 insertions, 4 deletions
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index ae6ad726e..19fad6b04 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -25,7 +25,7 @@ from django.db.models import Q, Count, Sum
from django.db.models.signals import post_save, m2m_changed
from django.utils.translation import ugettext_lazy as _, ugettext
-from ishtar_common.utils import cached_label_changed
+from ishtar_common.utils import cached_label_changed, shortify
from ishtar_common.models import GeneralType, BaseHistorizedItem, \
HistoricalRecords, OwnPerms, Person, Organization, Department, Town, \
@@ -144,8 +144,8 @@ class File(BaseHistorizedItem, OwnPerms):
items[0] = unicode(self.towns.all()[0])
items.append("-".join((unicode(self.year),
unicode(self.numeric_reference or '0'))))
- items += [unicode(getattr(self, k))[:36]
- for k in ['internal_reference',] if getattr(self, k)]
+ items += [shortify(unicode(getattr(self, k)))
+ for k in ['internal_reference', 'name'] if getattr(self, k)]
return settings.JOINT.join(items)
def grouped_parcels(self):
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 7c57087c5..d51e7a518 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -26,7 +26,7 @@ from django.db.models import Q, Count, Sum, Max, Avg
from django.db.models.signals import post_save, m2m_changed
from django.utils.translation import ugettext_lazy as _, ugettext
-from ishtar_common.utils import cached_label_changed
+from ishtar_common.utils import cached_label_changed, shortify
from ishtar_common.models import GeneralType, BaseHistorizedItem, \
HistoricalRecords, LightHistorizedItem, OwnPerms, Department, Source,\
@@ -155,6 +155,8 @@ class Operation(BaseHistorizedItem, OwnPerms):
if self.operation_code:
items.append("-".join((unicode(self.year),
unicode(self.operation_code))))
+ if self.common_name:
+ items.append(shortify(self.common_name))
cached_label = settings.JOINT.join(items)
return cached_label
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 50f4a6b41..d5fc37276 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -17,6 +17,8 @@
# See the file COPYING for details.
+from django.utils.translation import ugettext
+
def cached_label_changed(sender, **kwargs):
if not kwargs.get('instance'):
return
@@ -25,3 +27,9 @@ def cached_label_changed(sender, **kwargs):
if lbl != instance.cached_label:
instance.cached_label = lbl
instance.save()
+
+SHORTIFY_STR = ugettext(" (...)")
+def shortify(lbl, number=20):
+ if len(lbl) <= number:
+ return lbl
+ return lbl[:number-len(SHORTIFY_STR)] + SHORTIFY_STR