first_name, last_name and name_surfix as OpenSlidesUser attributes

This commit is contained in:
Oskar Hahn 2012-08-10 11:14:11 +02:00
parent 5353053d29
commit 153482f32d
2 changed files with 49 additions and 2 deletions

View File

@ -36,7 +36,7 @@ class OpenSlidesUser(models.Model, PersonMixin):
) )
user = models.OneToOneField(User, unique=True, editable=False) user = models.OneToOneField(User, unique=True, editable=False)
name_surfix = models.CharField( category = models.CharField(
max_length=100, null=True, blank=True, verbose_name=_("Name Surfix"), max_length=100, null=True, blank=True, verbose_name=_("Name Surfix"),
help_text=_('Shown behind the name.')) help_text=_('Shown behind the name.'))
gender = models.CharField( gender = models.CharField(
@ -55,6 +55,34 @@ class OpenSlidesUser(models.Model, PersonMixin):
max_length=100, null=True, blank=True, max_length=100, null=True, blank=True,
verbose_name=_("First Password")) verbose_name=_("First Password"))
save_user_object = False
def get_name_surfix(self):
return self.category
def set_name_surfix(self, value):
self.category = value
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_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.
@ -67,6 +95,9 @@ class OpenSlidesUser(models.Model, PersonMixin):
def has_perm(self, perm): def has_perm(self, perm):
return self.user.has_perm(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'):
""" """
@ -86,6 +117,12 @@ class OpenSlidesUser(models.Model, PersonMixin):
return "%s (%s)" % (self.user.get_full_name(), self.name_surfix) return "%s (%s)" % (self.user.get_full_name(), self.name_surfix)
return "%s" % self.user.get_full_name() return "%s" % self.user.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 = (

View File

@ -39,7 +39,7 @@ class OpenSlidesUserTest(TestCase):
self.assertEqual(unicode(self.openslidesuser1), u'Max Mustermann') self.assertEqual(unicode(self.openslidesuser1), u'Max Mustermann')
def test_name_surfix(self): def test_name_surfix(self):
self.openslidesuser1.name_surfix = u'München' self.openslidesuser1.category = u'München'
self.openslidesuser1.save() self.openslidesuser1.save()
self.assertEqual(unicode(self.openslidesuser1), u'Max Mustermann (München)') self.assertEqual(unicode(self.openslidesuser1), u'Max Mustermann (München)')
@ -57,6 +57,16 @@ class OpenSlidesUserTest(TestCase):
self.assertEqual(get_person('openslides_user:1'), self.openslidesuser1) self.assertEqual(get_person('openslides_user:1'), self.openslidesuser1)
self.assertEqual(len(Persons()), 1) self.assertEqual(len(Persons()), 1)
def test_save_name(self):
self.assertEqual(self.openslidesuser1.first_name, self.user1.first_name)
self.assertEqual(self.openslidesuser1.last_name, self.user1.last_name)
self.openslidesuser1.first_name = 'foo'
self.openslidesuser1.last_name = 'bar'
self.openslidesuser1.save()
user1 = User.objects.get(pk=1)
self.assertEqual(user1.first_name, 'foo')
self.assertEqual(user1.last_name, 'bar')
class OpenSlidesGroupTest(TestCase): class OpenSlidesGroupTest(TestCase):
def setUp(self): def setUp(self):