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.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 1ff809315..429c8217b 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -56,8 +56,7 @@ def post_save_user(sender, **kwargs):
ishtaruser = q.all()[0]
if ishtaruser.is_superuser \
and not ishtaruser.has_right('administrator'):
- ishtaruser.person.person_types.add(PersonType.objects.get(
- txt_idx='administrator'))
+ ishtaruser.person.person_types.add(ADMINISTRATOR)
post_save.connect(post_save_user, sender=User)
class ValueGetter(object):
@@ -318,6 +317,12 @@ class GeneralType(models.Model):
for child in cls._get_childs(item, dct, instances, exclude=exclude):
yield child
+ def save(self, *args, **kwargs):
+ if not self.id and not self.label:
+ self.label = u" ".join(u" ".join(self.txt_idx.split('-')
+ ).split('_')).title()
+ return super(GeneralType, self).save(*args, **kwargs)
+
class ImageModel(models.Model):
image = models.ImageField(upload_to="upload/", blank=True, null=True)
thumbnail = models.ImageField(upload_to='upload/thumbs/', blank=True,
@@ -758,6 +763,9 @@ class PersonType(GeneralType):
verbose_name_plural = _(u"Person types")
ordering = ('label',)
+ADMINISTRATOR, created = PersonType.objects.get_or_create(
+ txt_idx='administrator')
+
class Person(Address, OwnPerms, ValueGetter) :
_prefix = 'person_'
TYPE = (('Mr', _(u'Mr')),
@@ -859,9 +867,10 @@ class IshtarUser(User):
email = user.email
person_type = None
if user.is_superuser:
- person_type = PersonType.objects.get(txt_idx='administrator')
+ person_type = ADMINISTRATOR
else:
- person_type = PersonType.objects.get(txt_idx='public_access')
+ person_type, created = PersonType.objects.get_or_create(
+ txt_idx='public_access')
person = Person.objects.create(title='Mr', surname=surname,
name=name, email=email,
history_modifier=user)