Fixed saving anonymous user in a PersonField

This commit is contained in:
Oskar Hahn 2013-04-24 09:28:58 +02:00
parent e755712403
commit f581169e1e
3 changed files with 18 additions and 7 deletions

View File

@ -11,6 +11,7 @@
""" """
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.contrib.auth.models import AnonymousUser
from openslides.config.api import config from openslides.config.api import config
from openslides.projector.projector import Widget 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. Returns the widgets of the account app. It is only a personal_info_widget.
""" """
if not isinstance(request.user, AnonymousUser):
return [get_personal_info_widget(request)] return [get_personal_info_widget(request)]
else:
return []
def get_personal_info_widget(request): def get_personal_info_widget(request):

View File

@ -153,7 +153,7 @@
<p> <p>
{% if is_speaker %} {% if is_speaker %}
<a href="{% url 'agenda_speaker_delete' object.id %}" class="btn">{% trans "Remove me from the list" %}</a> <a href="{% url 'agenda_speaker_delete' object.id %}" class="btn">{% trans "Remove me from the list" %}</a>
{% elif not object.speaker_list_closed %} {% elif not object.speaker_list_closed and perms.can_be_speaker %}
<a href="{% url 'agenda_speaker_append' object.id %}" class="btn">{% trans "Put me on the list" %}</a> <a href="{% url 'agenda_speaker_append' object.id %}" class="btn">{% trans "Put me on the list" %}</a>
{% endif %} {% endif %}
</p> </p>

View File

@ -11,6 +11,8 @@
""" """
from django.db import models from django.db import models
from openslides.utils.exceptions import OpenSlidesError
from .forms import PersonFormField from .forms import PersonFormField
from .api import get_person, generate_person_id 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. Convert a person object to a string, to store it in the database.
""" """
if value is None: if value is None:
# For Fields with null=True
return None return None
elif isinstance(value, basestring): elif isinstance(value, basestring):
# The object is already a a person_id
return value return value
else: elif hasattr(value, 'person_id'):
# The object is a person
return value.person_id return value.person_id
else:
OpenSlidesError('%s (%s) is no person' % (value, type(value)))
def formfield(self, **kwargs): def formfield(self, **kwargs):
defaults = {'form_class': PersonFormField} defaults = {'form_class': PersonFormField}