diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-04-09 17:19:29 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-06-12 08:39:42 +0200 | 
| commit | 19465c0e44276a176f50523967a4dd01d113493a (patch) | |
| tree | 68bb0dc6aab81650301b15f3da410b463992f9f1 /ishtar_common/models.py | |
| parent | ab1f6d5016175a1990892f1ea7408dfe495de103 (diff) | |
| download | Ishtar-19465c0e44276a176f50523967a4dd01d113493a.tar.bz2 Ishtar-19465c0e44276a176f50523967a4dd01d113493a.zip | |
Add an explicit profile for user (refs #4046)
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 44 | 
1 files changed, 44 insertions, 0 deletions
| diff --git a/ishtar_common/models.py b/ishtar_common/models.py index b92614e08..7c2069309 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2470,6 +2470,24 @@ class Person(Address, Merge, OwnPerms, ValueGetter):              [unicode(getattr(self, attr))               for attr in ['title', 'salutation'] if getattr(self, attr)]) +    @property +    def default_profile(self): +        q = self.profiles.filter(default=True) +        if q.count(): +            return q.all()[0] +        q = self.profiles +        nb = q.count() +        if not nb: +            return +        if nb > 1: +            # arbitrary return the first one +            return q.all()[0] +        # if there is only one it is the default +        profile = q.all()[0] +        profile.default = True +        profile.save() +        return profile +      def simple_lbl(self):          values = [unicode(getattr(self, attr)) for attr in ('surname', 'name')                    if getattr(self, attr)] @@ -2630,6 +2648,32 @@ class Person(Address, Merge, OwnPerms, ValueGetter):                =user.ishtaruser) +class ProfileType(GeneralType): +    groups = models.ManyToManyField(Group, verbose_name=_(u"Groups"), +                                    blank=True) + +    class Meta: +        verbose_name = _(u"Profile type") +        verbose_name_plural = _(u"Profile types") +        ordering = ('label',) + + +post_save.connect(post_save_cache, sender=ProfileType) +post_delete.connect(post_save_cache, sender=ProfileType) + + +class UserProfile(models.Model): +    profile_type = models.ForeignKey( +        ProfileType, verbose_name=_(u"Profile type")) +    default = models.BooleanField(_(u"Default profile"), default=False) +    person = models.ForeignKey( +        Person, verbose_name=_(u"Person"), related_name='profiles') + +    class Meta: +        verbose_name = _(u"User profile") +        verbose_name_plural = _(u"User profiles") + +  class IshtarUser(FullSearch):      TABLE_COLS = ('username', 'person__name', 'person__surname',                    'person__email', 'person__person_types_list', | 
