diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-23 13:12:44 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-08-23 13:12:44 +0200 | 
| commit | e5123c28e4ef5773d416b06805cec471ec432f57 (patch) | |
| tree | 4272d98a6f29f4b16ee69d6c6a6eae63f3c22f09 /ishtar_common/models.py | |
| parent | dd63f57e3fc55ec8e88dbcc55a17d221b6c82562 (diff) | |
| download | Ishtar-e5123c28e4ef5773d416b06805cec471ec432f57.tar.bz2 Ishtar-e5123c28e4ef5773d416b06805cec471ec432f57.zip | |
Administration: allow admin to display field number live
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 22 | 
1 files changed, 22 insertions, 0 deletions
| diff --git a/ishtar_common/models.py b/ishtar_common/models.py index d14e9b346..51d3550e9 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2997,6 +2997,8 @@ class UserProfile(models.Model):      areas = models.ManyToManyField("Area", verbose_name=_(u"Areas"),                                     blank=True, related_name='profiles')      current = models.BooleanField(_(u"Current profile"), default=False) +    show_field_number = models.BooleanField( +        _(u"Show field number"), default=False)      person = models.ForeignKey(          Person, verbose_name=_(u"Person"), related_name='profiles') @@ -3062,6 +3064,16 @@ class UserProfile(models.Model):              p.save() +def post_save_userprofile(sender, **kwargs): +    if not kwargs.get('instance'): +        return +    instance = kwargs.get('instance') +    instance.person.ishtaruser.show_field_number(update=True) + + +post_save.connect(post_save_userprofile, sender=UserProfile) + +  class IshtarUser(FullSearch):      TABLE_COLS = ('username', 'person__name', 'person__surname',                    'person__email', 'person__person_types_list', @@ -3123,6 +3135,16 @@ class IshtarUser(FullSearch):      def __unicode__(self):          return unicode(self.person) +    def show_field_number(self, update=False): +        cache_key, value = get_cache(self.__class__, ['show_field_number']) +        if not update and value is not None: +            return value +        value = False +        if self.current_profile: +            value = self.current_profile.show_field_number +        cache.set(cache_key, value, settings.CACHE_TIMEOUT) +        return value +      @property      def current_profile_name(self):          q = UserProfile.objects.filter(current=True, person__ishtaruser=self) | 
