From f581169e1e24072eb0b783e13cd34f2543a10e62 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Wed, 24 Apr 2013 09:28:58 +0200 Subject: [PATCH] Fixed saving anonymous user in a PersonField --- openslides/account/views.py | 6 +++++- openslides/agenda/templates/agenda/view.html | 10 +++++----- openslides/utils/person/models.py | 9 ++++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/openslides/account/views.py b/openslides/account/views.py index a3b9c47e9..5fa151665 100644 --- a/openslides/account/views.py +++ b/openslides/account/views.py @@ -11,6 +11,7 @@ """ from django.utils.translation import ugettext as _ +from django.contrib.auth.models import AnonymousUser from openslides.config.api import config from openslides.projector.projector import Widget @@ -20,7 +21,10 @@ def get_widgets(request): """ Returns the widgets of the account app. It is only a personal_info_widget. """ - return [get_personal_info_widget(request)] + if not isinstance(request.user, AnonymousUser): + return [get_personal_info_widget(request)] + else: + return [] def get_personal_info_widget(request): diff --git a/openslides/agenda/templates/agenda/view.html b/openslides/agenda/templates/agenda/view.html index 400f2542e..33bb9f18a 100644 --- a/openslides/agenda/templates/agenda/view.html +++ b/openslides/agenda/templates/agenda/view.html @@ -151,11 +151,11 @@

- {% if is_speaker %} - {% trans "Remove me from the list" %} - {% elif not object.speaker_list_closed %} - {% trans "Put me on the list" %} - {% endif %} + {% if is_speaker %} + {% trans "Remove me from the list" %} + {% elif not object.speaker_list_closed and perms.can_be_speaker %} + {% trans "Put me on the list" %} + {% endif %}

{% if perms.can_manage_agenda %} diff --git a/openslides/utils/person/models.py b/openslides/utils/person/models.py index f4beadd05..c56c1e6a2 100644 --- a/openslides/utils/person/models.py +++ b/openslides/utils/person/models.py @@ -11,6 +11,8 @@ """ from django.db import models +from openslides.utils.exceptions import OpenSlidesError + from .forms import PersonFormField from .api import get_person, generate_person_id @@ -41,11 +43,16 @@ class PersonField(models.fields.Field): 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 - else: + 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}