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.py44
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',