OpenSlides/openslides/utils/person/models.py
Emanuel Schuetze abad75c129 A lot of template improvements and translation fixes
- Fixed agenda widget for special slide views (e.g. list of speakers, summary).
- Fixed back to motion(s) link
- Set icon for list of speakers widget.
- Fixed overlay widget layout of form elements.
- Added submenu with other config_pages to version.html.
- Updated completly DE translations, fixed EN strings.
- Coding style: Use correct ugettext and ugettext_lazy strings. Use "as _" for ugettext only.
Updated translation.
- Improved projector template (clock image, fixed facicon, added subtitle for list of speakers)
- Changed permission strings ('oneself'). Added check if group(pk=3) exists.
- Added event name and description to base template. Some minor template layout fixes.
- Use static subtile (no context var). Show last 2 old_speakers for projector.
- Cut old_speakers.
- Projektor template style changes (e.g. overlay list of speakers).
2013-04-24 10:38:03 +02:00

81 lines
2.3 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.utils.person.models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Models and ModelFields for the OpenSlides person api.
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
from django.db import models
from openslides.utils.exceptions import OpenSlidesError
from .forms import PersonFormField
from .api import get_person, generate_person_id
class PersonField(models.fields.Field):
__metaclass__ = models.SubfieldBase
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 255
super(PersonField, self).__init__(*args, **kwargs)
def get_internal_type(self):
return "CharField"
def to_python(self, value):
"""
Convert string value to a User Object.
"""
if isinstance(value, PersonMixin):
return value
elif value is None:
return None
else:
return get_person(value)
def get_prep_value(self, value):
"""
Convert a person object to a string, to store it in the database.
"""
if value is None:
# For Fields with null=True
return None
elif isinstance(value, basestring):
# The object is already a a person_id
return value
elif hasattr(value, 'person_id'):
# The object is a person
return value.person_id
else:
OpenSlidesError('%s (%s) is no person' % (value, type(value)))
def formfield(self, **kwargs):
defaults = {'form_class': PersonFormField}
defaults.update(kwargs)
return super(PersonField, self).formfield(**defaults)
class PersonMixin(object):
@property
def person_id(self):
try:
return generate_person_id(self.person_prefix, self.pk)
except AttributeError:
raise AttributeError("%s has to have a attribute 'person_prefix'"
% self)
def __unicode__(self):
return 'MyPerson: %s' % self.person_id
def prepare_database_save(self, field):
if type(field) is PersonField:
return self.person_id
else:
return super(PersonMixin, self).prepare_database_save(field)