Append a default class for the person-api.

Also fixed the assignment-ballot-paper for group-persons
This commit is contained in:
Oskar Hahn 2012-10-24 12:15:29 +02:00
parent f99fdc6981
commit 3e1938941f
4 changed files with 46 additions and 11 deletions

View File

@ -430,7 +430,7 @@ class AssignmentPDF(PDFView):
for candidate, poll_list in vote_results.iteritems():
row = []
candidate_string = candidate.user.get_full_name()
candidate_string = candidate.clean_name
if candidate in elected_candidates:
candidate_string = "* " + candidate_string
if candidate.category:
@ -565,7 +565,7 @@ class AssignmentPollPDF(PDFView):
if self.poll.yesnoabstain:
for option in options:
candidate = option.candidate
cell.append(Paragraph(candidate.user.get_full_name(),
cell.append(Paragraph(candidate.clean_name,
stylesheet['Ballot_option_name']))
if candidate.name_suffix:
cell.append(Paragraph("(%s)" % candidate.name_suffix,
@ -591,9 +591,9 @@ class AssignmentPollPDF(PDFView):
else:
for option in options:
candidate = option.candidate
cell.append(Paragraph(circle + candidate.user.get_full_name(),
cell.append(Paragraph(circle + candidate.clean_name,
stylesheet['Ballot_option_name']))
if candidate.category:
if candidate.name_suffix:
cell.append(Paragraph("(%s)" % candidate.category,
stylesheet['Ballot_option_group_right']))
else:

View File

@ -16,14 +16,14 @@ from django.db.models import signals
from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _, ugettext_noop
from openslides.utils.person import PersonMixin
from openslides.utils.person import PersonMixin, Person
from openslides.utils.person.signals import receive_persons
from openslides.config.models import config
from openslides.config.signals import default_config_value
class User(DjangoUser, PersonMixin):
class User(DjangoUser, PersonMixin, Person):
person_prefix = 'user'
GENDER_CHOICES = (
('male', _('Male')),
@ -56,6 +56,10 @@ class User(DjangoUser, PersonMixin):
max_length=100, null=True, blank=True,
verbose_name=_("Default password"))
@property
def clean_name(self):
return self.get_full_name() or self.username
def get_name_suffix(self):
return self.category
@ -88,10 +92,9 @@ class User(DjangoUser, PersonMixin):
return ('user_delete', [str(self.id)])
def __unicode__(self):
name = self.get_full_name() or self.username
if self.name_suffix:
return u"%s (%s)" % (name, self.name_suffix)
return u"%s" % name
return u"%s (%s)" % (self.clean_name, self.name_suffix)
return u"%s" % self.clean_name
class Meta:
# Rename permissions
@ -103,7 +106,7 @@ class User(DjangoUser, PersonMixin):
ordering = ('last_name',)
class Group(DjangoGroup, PersonMixin):
class Group(DjangoGroup, PersonMixin, Person):
person_prefix = 'group'
django_group = models.OneToOneField(DjangoGroup, editable=False, parent_link=True)

View File

@ -11,7 +11,8 @@
"""
from openslides.utils.person.signals import receive_persons
from openslides.utils.person.api import generate_person_id, get_person, Persons
from openslides.utils.person.api import (generate_person_id, get_person,
Person, Persons)
from openslides.utils.person.forms import PersonFormField, MultiplePersonFormField
from openslides.utils.person.models import PersonField, PersonMixin

View File

@ -13,6 +13,37 @@
from openslides.utils.person.signals import receive_persons
class Person(object):
"""
Meta-class for all person objects
"""
def person_id(self):
"""
Return an id for representation of ths person. Has to be unique.
"""
raise NotImplementedError('Any person object needs a person_id')
def __repr__(self):
"""
Return a string for this person.
"""
return str(self.person_id)
@property
def clean_name(self):
"""
Return the name of this person without a suffix
"""
return unicode(self)
@property
def name_suffix(self):
"""
Return a suffix for the person-name.
"""
return ''
class Persons(object):
"""
A Storage for a multiplicity of different Person-Objects.