From 1832a0c125eae33acf35192eeba47e0f5e09f68b Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Fri, 10 Aug 2012 13:11:10 +0200 Subject: [PATCH] make the openslides user a child model of the django user model --- openslides/participant/models.py | 45 +++++--------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/openslides/participant/models.py b/openslides/participant/models.py index f833f3bd7..850b23806 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -22,7 +22,7 @@ from openslides.utils.person.signals import receiv_persons from openslides.config.signals import default_config_value -class OpenSlidesUser(models.Model, PersonMixin): +class OpenSlidesUser(User, PersonMixin): person_prefix = 'openslides_user' GENDER_CHOICES = ( ('male', _('Male')), @@ -35,10 +35,10 @@ class OpenSlidesUser(models.Model, PersonMixin): ('guest', _('Guest')), ) - user = models.OneToOneField(User, unique=True, editable=False) + user = models.OneToOneField(User, unique=True, editable=False, parent_link=True) category = models.CharField( max_length=100, null=True, blank=True, verbose_name=_("Category"), - help_text=_('Shown behind the name.')) + help_text=_('Will be shown behind the name.')) gender = models.CharField( max_length=50, choices=GENDER_CHOICES, blank=True, verbose_name=_("Gender"), help_text=_('Only for filter the userlist.')) @@ -65,27 +65,6 @@ class OpenSlidesUser(models.Model, PersonMixin): name_surfix = property(get_name_surfix, set_name_surfix) - def get_first_name(self): - return self.user.first_name - - def set_first_name(self, first_name): - self.user.first_name = first_name - self.save_user_object = True - - first_name = property(get_first_name, set_first_name) - - def get_full_name(self): - return "%s %s" % self.first_name, self.last_name - - def get_last_name(self): - return self.user.last_name - - def set_last_name(self, last_name): - self.user.last_name = last_name - self.save_user_object = True - - last_name = property(get_last_name, set_last_name) - def reset_password(self, password=None): """ Reset the password for the user to his default-password. @@ -95,12 +74,6 @@ class OpenSlidesUser(models.Model, PersonMixin): self.user.set_password(password) self.user.save() - def has_perm(self, perm): - return self.user.has_perm(perm) - - def save_in_user_object(self, attribute, value): - self.save_in_user_object_dict[attribute] = value - @models.permalink def get_absolute_url(self, link='edit'): """ @@ -120,12 +93,6 @@ class OpenSlidesUser(models.Model, PersonMixin): return u"%s (%s)" % (self.get_full_name(), self.name_surfix) return u"%s" % self.get_full_name() - def save(self, *args, **kwargs): - if self.save_user_object: - self.user.save() - self.save_user_object = False - super(OpenSlidesUser, self).save(*args, **kwargs) - class Meta: # Rename permissions permissions = ( @@ -193,8 +160,10 @@ def default_config(sender, key, **kwargs): @receiver(signals.post_save, sender=User) def user_post_save(sender, instance, signal, *args, **kwargs): - # Creates OpenSlidesUser - openslidesuser, new = OpenSlidesUser.objects.get_or_create(user=instance) + try: + instance.openslidesuser + except OpenSlidesUser.DoesNotExist: + OpenSlidesUser(user=instance).save_base(raw=True) @receiver(signals.post_save, sender=Group)