make the openslides user a child model of the django user model
This commit is contained in:
parent
29049119f7
commit
1832a0c125
@ -22,7 +22,7 @@ from openslides.utils.person.signals import receiv_persons
|
|||||||
from openslides.config.signals import default_config_value
|
from openslides.config.signals import default_config_value
|
||||||
|
|
||||||
|
|
||||||
class OpenSlidesUser(models.Model, PersonMixin):
|
class OpenSlidesUser(User, PersonMixin):
|
||||||
person_prefix = 'openslides_user'
|
person_prefix = 'openslides_user'
|
||||||
GENDER_CHOICES = (
|
GENDER_CHOICES = (
|
||||||
('male', _('Male')),
|
('male', _('Male')),
|
||||||
@ -35,10 +35,10 @@ class OpenSlidesUser(models.Model, PersonMixin):
|
|||||||
('guest', _('Guest')),
|
('guest', _('Guest')),
|
||||||
)
|
)
|
||||||
|
|
||||||
user = models.OneToOneField(User, unique=True, editable=False)
|
user = models.OneToOneField(User, unique=True, editable=False, parent_link=True)
|
||||||
category = models.CharField(
|
category = models.CharField(
|
||||||
max_length=100, null=True, blank=True, verbose_name=_("Category"),
|
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(
|
gender = models.CharField(
|
||||||
max_length=50, choices=GENDER_CHOICES, blank=True,
|
max_length=50, choices=GENDER_CHOICES, blank=True,
|
||||||
verbose_name=_("Gender"), help_text=_('Only for filter the userlist.'))
|
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)
|
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):
|
def reset_password(self, password=None):
|
||||||
"""
|
"""
|
||||||
Reset the password for the user to his default-password.
|
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.set_password(password)
|
||||||
self.user.save()
|
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
|
@models.permalink
|
||||||
def get_absolute_url(self, link='edit'):
|
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 (%s)" % (self.get_full_name(), self.name_surfix)
|
||||||
return u"%s" % self.get_full_name()
|
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:
|
class Meta:
|
||||||
# Rename permissions
|
# Rename permissions
|
||||||
permissions = (
|
permissions = (
|
||||||
@ -193,8 +160,10 @@ def default_config(sender, key, **kwargs):
|
|||||||
|
|
||||||
@receiver(signals.post_save, sender=User)
|
@receiver(signals.post_save, sender=User)
|
||||||
def user_post_save(sender, instance, signal, *args, **kwargs):
|
def user_post_save(sender, instance, signal, *args, **kwargs):
|
||||||
# Creates OpenSlidesUser
|
try:
|
||||||
openslidesuser, new = OpenSlidesUser.objects.get_or_create(user=instance)
|
instance.openslidesuser
|
||||||
|
except OpenSlidesUser.DoesNotExist:
|
||||||
|
OpenSlidesUser(user=instance).save_base(raw=True)
|
||||||
|
|
||||||
|
|
||||||
@receiver(signals.post_save, sender=Group)
|
@receiver(signals.post_save, sender=Group)
|
||||||
|
Loading…
Reference in New Issue
Block a user