From 2984fd791ccdd3a18f45b01739713cd84859e9d2 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 15 Sep 2012 09:11:56 +0200 Subject: [PATCH] small fix to the person api --- openslides/participant/models.py | 13 ++++++++----- openslides/utils/person/__init__.py | 4 ++-- openslides/utils/person/api.py | 12 ++++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/openslides/participant/models.py b/openslides/participant/models.py index b97ed119c..4977b3dcf 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -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): diff --git a/openslides/utils/person/__init__.py b/openslides/utils/person/__init__.py index da896616f..cc983caf9 100644 --- a/openslides/utils/person/__init__.py +++ b/openslides/utils/person/__init__.py @@ -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' diff --git a/openslides/utils/person/api.py b/openslides/utils/person/api.py index 55b4691a8..49d901f28 100644 --- a/openslides/utils/person/api.py +++ b/openslides/utils/person/api.py @@ -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]