diff options
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/migrations/0063_auto_20180807_1824.py | 25 | ||||
| -rw-r--r-- | ishtar_common/models.py | 24 | 
2 files changed, 41 insertions, 8 deletions
diff --git a/ishtar_common/migrations/0063_auto_20180807_1824.py b/ishtar_common/migrations/0063_auto_20180807_1824.py new file mode 100644 index 000000000..d39f5368f --- /dev/null +++ b/ishtar_common/migrations/0063_auto_20180807_1824.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.10 on 2018-08-07 18:24 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + +    dependencies = [ +        ('ishtar_common', '0062_searchquery'), +    ] + +    operations = [ +        migrations.AddField( +            model_name='historicalperson', +            name='cached_label', +            field=models.TextField(blank=True, db_index=True, null=True, verbose_name='Cached name'), +        ), +        migrations.AddField( +            model_name='person', +            name='cached_label', +            field=models.TextField(blank=True, db_index=True, null=True, verbose_name='Cached name'), +        ), +    ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index af63cb7c1..1aaa44b59 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2619,6 +2619,8 @@ class Person(Address, Merge, OwnPerms, ValueGetter):      attached_to = models.ForeignKey(          'Organization', related_name='members', on_delete=models.SET_NULL,          verbose_name=_(u"Is attached to"), blank=True, null=True) +    cached_label = models.TextField(_(u"Cached name"), null=True, blank=True, +                                    db_index=True)      history = HistoricalRecords()      class Meta: @@ -2661,16 +2663,19 @@ class Person(Address, Merge, OwnPerms, ValueGetter):          return u" ".join(values)      def __unicode__(self): -        values = [unicode(getattr(self, attr)) for attr in ('surname', 'name') -                  if getattr(self, attr)] -        if not values and self.raw_name: -            values = [self.raw_name] +        if self.cached_label: +            return self.cached_label +        self.save() +        return self.cached_label + +    def _generate_cached_label(self): +        lbl = get_external_id('person_raw_name', self) +        if not lbl: +            return u"-"          if self.attached_to:              attached_to = unicode(self.attached_to) -            if values: -                values.append(u'-') -            values.append(attached_to) -        return u" ".join(values) +            lbl += u" ({})".format(attached_to) +        return lbl      def fancy_str(self):          values = ["<strong>"] @@ -2829,6 +2834,9 @@ class Person(Address, Merge, OwnPerms, ValueGetter):                =user.ishtaruser) +post_save.connect(cached_label_changed, sender=Person) + +  class ProfileType(GeneralType):      groups = models.ManyToManyField(Group, verbose_name=_(u"Groups"),                                      blank=True)  | 
