summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py41
1 files changed, 31 insertions, 10 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 76f16eaae..de34a2b9c 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3093,9 +3093,21 @@ class Document(OwnPerms, ImageModel, FullSearch):
'treatment_files', 'treatments', 'finds', 'context_records',
'operations', 'sites', 'warehouses',
]
-
+ SLUG = 'document'
LINK_SPLIT = u"<||>"
+ TABLE_COLS = ['title', 'source_type', 'cache_related_label', 'authors',
+ 'associated_url']
+ COL_LINK = ['associated_url']
+ BASE_SEARCH_VECTORS = ['title', 'source_type__label', 'external_id',
+ 'reference', 'description', 'comment',
+ 'additional_information']
+ PARENT_SEARCH_VECTORS = ['authors', ]
+
+ BOOL_FIELDS = ['duplicate']
+
+ CACHED_LABELS = ['cache_related_label']
+
title = models.TextField(_(u"Title"), blank=True, default='')
associated_file = models.FileField(
upload_to=get_image_path, blank=True, null=True, max_length=255)
@@ -3137,13 +3149,9 @@ class Document(OwnPerms, ImageModel, FullSearch):
duplicate = models.BooleanField(_(u"Has a duplicate"), default=False)
associated_links = models.TextField(_(u"Symbolic links"), blank=True,
null=True)
-
- TABLE_COLS = ['title', 'source_type', 'authors', 'associated_url']
- COL_LINK = ['associated_url']
- BASE_SEARCH_VECTORS = ['title', 'source_type__label', 'external_id',
- 'reference', 'description', 'comment',
- 'additional_information']
- PARENT_SEARCH_VECTORS = ['authors', ]
+ cache_related_label = models.TextField(
+ _(u"Related"), blank=True, null=True, db_index=True,
+ help_text=_(u"Cached value - do not edit"))
class Meta:
verbose_name = _(u"Document")
@@ -3199,7 +3207,7 @@ class Document(OwnPerms, ImageModel, FullSearch):
for related_model in self.RELATED_MODELS:
q = getattr(self, related_model).all()
if q.count():
- item = q.all()[0].item
+ item = q.all()[0]
yield item._get_base_image_path()
def _get_base_image_path(self):
@@ -3259,7 +3267,7 @@ class Document(OwnPerms, ImageModel, FullSearch):
for related_model in self.RELATED_MODELS:
q = getattr(self, related_model).all()
if q.count():
- item = q.all()[0].item
+ item = q.all()[0]
base_path = item._get_base_image_path()
new_path = base_path + u"/" + filename
if not reference_path:
@@ -3295,6 +3303,16 @@ class Document(OwnPerms, ImageModel, FullSearch):
os.symlink(reference_path, new_path)
return links
+ def related_label(self):
+ items = []
+ for rel_attr in reversed(self.RELATED_MODELS):
+ for item in getattr(self, rel_attr).all():
+ items.append(unicode(item))
+ return u" ; ".join(items)
+
+ def _generate_cache_related_label(self):
+ return self.related_label()
+
def save(self, *args, **kwargs):
no_path_change = 'no_path_change' in kwargs \
and kwargs.pop('no_path_change')
@@ -3309,6 +3327,9 @@ class Document(OwnPerms, ImageModel, FullSearch):
self.save(no_path_change=True)
+post_save.connect(cached_label_changed, sender=Document)
+
+
class Arrondissement(models.Model):
name = models.CharField(u"Nom", max_length=30)
department = models.ForeignKey(Department, verbose_name=u"Département")