From 15b13c2bcd3f492be5d4f47ed6990c6e9ea5d877 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 2 Feb 2013 21:19:37 +0100 Subject: [PATCH] Handel null=True in PersonField --- openslides/utils/person/api.py | 2 +- openslides/utils/person/models.py | 32 +++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/openslides/utils/person/api.py b/openslides/utils/person/api.py index 1dff34d3d..24a759551 100644 --- a/openslides/utils/person/api.py +++ b/openslides/utils/person/api.py @@ -10,7 +10,7 @@ :license: GNU GPL, see LICENSE for more details. """ -from openslides.utils.person.signals import receive_persons +from .signals import receive_persons class Person(object): diff --git a/openslides/utils/person/models.py b/openslides/utils/person/models.py index cf16f7286..f22cdddc4 100644 --- a/openslides/utils/person/models.py +++ b/openslides/utils/person/models.py @@ -11,16 +11,16 @@ """ from django.db import models -from openslides.utils.person.forms import PersonFormField -from openslides.utils.person.api import get_person, generate_person_id +from .forms import PersonFormField +from .api import get_person, generate_person_id, Person class PersonField(models.fields.Field): __metaclass__ = models.SubfieldBase def __init__(self, *args, **kwargs): - super(PersonField, self).__init__(max_length=255, *args, **kwargs) - # TODO: Validate the uid + kwargs['max_length'] = 255 + super(PersonField, self).__init__(*args, **kwargs) def get_internal_type(self): return "CharField" @@ -29,21 +29,21 @@ class PersonField(models.fields.Field): """ Convert string value to a User Object. """ - if hasattr(value, 'person_id'): - person = value + if isinstance(value, Person): + return value + elif value is None: + return None else: - person = get_person(value) - - person.prepare_database_save = ( - lambda unused: PersonField().get_prep_value(person)) - return person + return get_person(value) def get_prep_value(self, value): - return value.person_id - - def value_to_string(self, obj): - value = self._get_val_from_obj(obj) - return self.get_prep_value(value) + """ + Convert a person object to a string, to store it in the database. + """ + if value is None: + return None + else: + return value.person_id def formfield(self, **kwargs): defaults = {'form_class': PersonFormField}