diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index 68f561c87..a65d10997 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -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: diff --git a/openslides/participant/models.py b/openslides/participant/models.py index 42b965f69..2cce07709 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -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) diff --git a/openslides/utils/person/__init__.py b/openslides/utils/person/__init__.py index cc983caf9..7a69e8f25 100644 --- a/openslides/utils/person/__init__.py +++ b/openslides/utils/person/__init__.py @@ -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 diff --git a/openslides/utils/person/api.py b/openslides/utils/person/api.py index 49d901f28..5c842dea2 100644 --- a/openslides/utils/person/api.py +++ b/openslides/utils/person/api.py @@ -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.