diff options
| author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-07-17 13:58:40 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-07-17 13:58:40 +0200 | 
| commit | c2f69fa7a50275841f0fbb3bd577b0ce93f122d6 (patch) | |
| tree | aa74812fab75ae6263bb4eecdfd67f79f9ab27be /archaeological_files/models.py | |
| parent | 194e67bd223bfb5e32cb32162702d49c26e5fc4f (diff) | |
| download | Ishtar-c2f69fa7a50275841f0fbb3bd577b0ce93f122d6.tar.bz2 Ishtar-c2f69fa7a50275841f0fbb3bd577b0ce93f122d6.zip | |
Improve cached_label managemnent
* more genericity
* adapt it to archaeological files
Diffstat (limited to 'archaeological_files/models.py')
| -rw-r--r-- | archaeological_files/models.py | 14 | 
1 files changed, 14 insertions, 0 deletions
| diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 8f2f513d2..ae6ad726e 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -22,8 +22,11 @@ import datetime  from django.conf import settings  from django.contrib.gis.db import models  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.models import GeneralType, BaseHistorizedItem, \      HistoricalRecords, OwnPerms, Person, Organization, Department, Town, \      Dashboard, IshtarUser @@ -100,6 +103,8 @@ class File(BaseHistorizedItem, OwnPerms):      postal_code = models.CharField(_(u"Main address - postal code"),                                     max_length=10, null=True, blank=True)      comment = models.TextField(_(u"Comment"), null=True, blank=True) +    cached_label = models.CharField(_(u"Cached name"), max_length=100, +                                   null=True, blank=True)      history = HistoricalRecords()      class Meta: @@ -128,6 +133,12 @@ class File(BaseHistorizedItem, OwnPerms):          return cls.objects.count()      def __unicode__(self): +        if self.cached_label: +            return self.cached_label +        self.save() +        return self.cached_label + +    def _generate_cached_label(self):          items = [unicode(_('Intercommunal'))]          if self.towns.count() == 1:              items[0] = unicode(self.towns.all()[0]) @@ -175,6 +186,9 @@ class File(BaseHistorizedItem, OwnPerms):      def is_preventive(self):          return FileType.is_preventive(self.file_type.pk) +m2m_changed.connect(cached_label_changed, sender=File.towns.through) +post_save.connect(cached_label_changed, sender=File) +  class FileByDepartment(models.Model):      '''      Database view for dashboard | 
