small fix to the person api

This commit is contained in:
Oskar Hahn 2012-09-15 09:11:56 +02:00
parent eac23ecd99
commit 2984fd791c
3 changed files with 18 additions and 11 deletions

View File

@ -137,7 +137,10 @@ class UsersConnector(object):
if (not self.person_prefix_filter or
self.person_prefix_filter == User.person_prefix):
if self.id_filter:
yield self.users.get(pk=self.id_filter)
try:
yield self.users.get(pk=self.id_filter)
except User.DoesNotExist:
pass
else:
for user in self.users:
yield user
@ -145,14 +148,14 @@ class UsersConnector(object):
if (not self.person_prefix_filter or
self.person_prefix_filter == Group.person_prefix):
if self.id_filter:
yield self.groups.get(pk=self.id_filter)
try:
yield self.groups.get(pk=self.id_filter)
except Group.DoesNotExist:
pass
else:
for group in self.groups:
yield group
def __getitem__(self, key):
return User.objects.get(pk=key)
@receiver(receive_persons, dispatch_uid="participant")
def receive_persons(sender, **kwargs):

View File

@ -16,7 +16,7 @@ from openslides.utils.person.forms import PersonFormField, MultiplePersonFormFie
from openslides.utils.person.models import PersonField, PersonMixin
class EmtyPerson(PersonMixin):
class EmptyPerson(PersonMixin):
@property
def person_id(self):
return 'emtyuser'
return 'empty'

View File

@ -25,13 +25,17 @@ class Persons(object):
try:
return iter(self._cache)
except AttributeError:
return iter(self.iter_persons())
return self.iter_persons()
def __len__(self):
return len(list(self.__iter__()))
def __getitem__(self, key):
return list(self)[key]
try:
return list(self)[key]
except IndexError:
from openslides.utils.person import EmptyPerson
return EmptyPerson()
def iter_persons(self):
self._cache = list()
@ -61,6 +65,6 @@ def get_person(person_id):
try:
person_prefix, id = split_person_id(person_id)
except TypeError:
from openslides.utils.person import EmtyPerson
return EmtyPerson()
from openslides.utils.person import EmptyPerson
return EmptyPerson()
return Persons(person_prefix_filter=person_prefix, id_filter=id)[0]