Handel null=True in PersonField
This commit is contained in:
parent
2e430b4406
commit
15b13c2bcd
@ -10,7 +10,7 @@
|
|||||||
:license: GNU GPL, see LICENSE for more details.
|
:license: GNU GPL, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from openslides.utils.person.signals import receive_persons
|
from .signals import receive_persons
|
||||||
|
|
||||||
|
|
||||||
class Person(object):
|
class Person(object):
|
||||||
|
@ -11,16 +11,16 @@
|
|||||||
"""
|
"""
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from openslides.utils.person.forms import PersonFormField
|
from .forms import PersonFormField
|
||||||
from openslides.utils.person.api import get_person, generate_person_id
|
from .api import get_person, generate_person_id, Person
|
||||||
|
|
||||||
|
|
||||||
class PersonField(models.fields.Field):
|
class PersonField(models.fields.Field):
|
||||||
__metaclass__ = models.SubfieldBase
|
__metaclass__ = models.SubfieldBase
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(PersonField, self).__init__(max_length=255, *args, **kwargs)
|
kwargs['max_length'] = 255
|
||||||
# TODO: Validate the uid
|
super(PersonField, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def get_internal_type(self):
|
def get_internal_type(self):
|
||||||
return "CharField"
|
return "CharField"
|
||||||
@ -29,22 +29,22 @@ class PersonField(models.fields.Field):
|
|||||||
"""
|
"""
|
||||||
Convert string value to a User Object.
|
Convert string value to a User Object.
|
||||||
"""
|
"""
|
||||||
if hasattr(value, 'person_id'):
|
if isinstance(value, Person):
|
||||||
person = value
|
return value
|
||||||
|
elif value is None:
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
person = get_person(value)
|
return get_person(value)
|
||||||
|
|
||||||
person.prepare_database_save = (
|
|
||||||
lambda unused: PersonField().get_prep_value(person))
|
|
||||||
return person
|
|
||||||
|
|
||||||
def get_prep_value(self, value):
|
def get_prep_value(self, 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
|
return value.person_id
|
||||||
|
|
||||||
def value_to_string(self, obj):
|
|
||||||
value = self._get_val_from_obj(obj)
|
|
||||||
return self.get_prep_value(value)
|
|
||||||
|
|
||||||
def formfield(self, **kwargs):
|
def formfield(self, **kwargs):
|
||||||
defaults = {'form_class': PersonFormField}
|
defaults = {'form_class': PersonFormField}
|
||||||
defaults.update(kwargs)
|
defaults.update(kwargs)
|
||||||
|
Loading…
Reference in New Issue
Block a user