From 1a1bcb235806cef861eb7cb811a402d143c78425 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 4 Aug 2012 15:02:02 +0200 Subject: [PATCH] updated some parts of OpenSlides to the new user-api --- .../templates/application/overview.html | 2 +- .../templates/projector/Application.html | 2 +- openslides/application/views.py | 9 +++---- openslides/assignment/forms.py | 3 +-- openslides/assignment/models.py | 23 ++++++++--------- .../templates/assignment/overview.html | 2 +- .../assignment/templates/assignment/view.html | 25 ++++++++----------- .../templates/projector/Assignment.html | 10 ++++---- openslides/assignment/views.py | 14 ++++++----- 9 files changed, 41 insertions(+), 49 deletions(-) diff --git a/openslides/application/templates/application/overview.html b/openslides/application/templates/application/overview.html index 2e72d568d..16336453d 100644 --- a/openslides/application/templates/application/overview.html +++ b/openslides/application/templates/application/overview.html @@ -59,7 +59,7 @@ {% if not forloop.last %}
{%endif%} {% endfor %} - {{ application.submitter.profile }} + {{ application.submitter }} {{ application.creation_time }} diff --git a/openslides/application/templates/projector/Application.html b/openslides/application/templates/projector/Application.html index 9f7dddaf7..4a5d1488b 100644 --- a/openslides/application/templates/projector/Application.html +++ b/openslides/application/templates/projector/Application.html @@ -53,7 +53,7 @@ {% endwith %}

{% trans "Submitter" %}:
- {{ application.submitter.profile }} + {{ application.submitter }}

diff --git a/openslides/application/views.py b/openslides/application/views.py index f2c12645b..0158e2513 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -748,13 +748,10 @@ class ApplicationPDF(PDFView): if application.status == "pub": cell1b.append(Paragraph("__________________________________________",stylesheet['Signaturefield'])) cell1b.append(Spacer(0,0.1*cm)) - cell1b.append(Paragraph("       "+unicode(application.submitter.profile), stylesheet['Small'])) + cell1b.append(Paragraph("       "+unicode(application.submitter), stylesheet['Small'])) cell1b.append(Spacer(0,0.2*cm)) else: - try: - cell1b.append(Paragraph(unicode(application.submitter.profile), stylesheet['Normal'])) - except Profile.DoesNotExist: - pass + cell1b.append(Paragraph(unicode(application.submitter), stylesheet['Normal'])) # supporters cell2a = [] @@ -764,7 +761,7 @@ class ApplicationPDF(PDFView): cell2a.append(Paragraph("%s:" % _("Supporters"), stylesheet['Heading4'])) for supporter in application.supporters: - cell2b.append(Paragraph(".  %s" % unicode(s.profile), stylesheet['Signaturefield'])) + cell2b.append(Paragraph(".  %s" % unicode(supporter), stylesheet['Signaturefield'])) if application.status == "pub": for x in range(0,application.missing_supporters): cell2b.append(Paragraph(".  __________________________________________",stylesheet['Signaturefield'])) diff --git a/openslides/assignment/forms.py b/openslides/assignment/forms.py index 07c06fc02..c3a648355 100644 --- a/openslides/assignment/forms.py +++ b/openslides/assignment/forms.py @@ -16,7 +16,6 @@ from django.utils.translation import ugettext_lazy as _, ugettext_noop from openslides.utils.forms import CssClassMixin from openslides.utils.user import UserFormField -from openslides.participant.models import Profile from openslides.assignment.models import Assignment @@ -26,7 +25,7 @@ class AssignmentForm(forms.ModelForm, CssClassMixin): class Meta: model = Assignment - exclude = ('status', 'profile', 'elected') + exclude = ('status', 'elected') class AssignmentRunForm(forms.Form, CssClassMixin): diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 6f7fbf169..d3bab3dca 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -23,8 +23,6 @@ from openslides.config.signals import default_config_value from openslides.projector.api import register_slidemodel from openslides.projector.projector import SlideMixin -from openslides.participant.models import Profile - from openslides.poll.models import (BasePoll, CountInvalid, CountVotesCast, BaseOption, PublishPollMixin, BaseVote) @@ -71,28 +69,27 @@ class Assignment(models.Model, SlideMixin): self.status = status self.save() - def run(self, profile, user=None): + def run(self, candidate, user=None): """ run for a vote """ - if self.is_candidate(profile): - raise NameError(_('%s is already a candidate.') % profile) + # TODO: don't make any permission checks here. + # Use other Exceptions + if self.is_candidate(candidate): + raise NameError(_('%s is already a candidate.') % candidate) if not user.has_perm("assignment.can_manage_assignment") and self.status != 'sea': raise NameError(_('The candidate list is already closed.')) - AssignmentCandidate(assignment=self, user=profile, elected=False).save() + AssignmentCandidate(assignment=self, user=candidate, elected=False).save() - def delrun(self, user): + def delrun(self, candidate): """ stop running for a vote """ - if self.status != 'sea': - # TODO: Use an OpenSlides Error - raise Exception(_('The candidate list is already closed.')) - if self.is_candidate(user): - assignment_candidats.get(user=user).delete() + if self.is_candidate(candidate): + self.assignment_candidats.get(user=candidate).delete() else: # TODO: Use an OpenSlides Error - raise Exception(_('%s is no candidate') % user) + raise Exception(_('%s is no candidate') % candidate) def is_candidate(self, user): if self.assignment_candidats.filter(user=user).exists(): diff --git a/openslides/assignment/templates/assignment/overview.html b/openslides/assignment/templates/assignment/overview.html index 85e850c18..2d9e3b8e0 100644 --- a/openslides/assignment/templates/assignment/overview.html +++ b/openslides/assignment/templates/assignment/overview.html @@ -31,7 +31,7 @@ {{ assignment }} - {{ assignment.profile.count }} / {{ assignment.posts }} + {{ assignment.candidates|length }} / {{ assignment.posts }} {{ assignment.get_status_display }} diff --git a/openslides/assignment/templates/assignment/view.html b/openslides/assignment/templates/assignment/view.html index 9a60c96db..2614b26d6 100644 --- a/openslides/assignment/templates/assignment/view.html +++ b/openslides/assignment/templates/assignment/view.html @@ -54,21 +54,18 @@
{% csrf_token %} {% if perms.assignment.can_nominate_self %}

- {% if user.profile in assignment.profile.all %} - - - - {% trans 'Withdraw self candidature' %} - - + {% if user in assignment.candidates %} + + + {% trans 'Withdraw self candidature' %} + + {% else %} - {% if user.profile %} - - - {% trans 'Self candidature' %} - - - {% endif %} + + + {% trans 'Self candidature' %} + + {% endif %}

{% endif %} diff --git a/openslides/assignment/templates/projector/Assignment.html b/openslides/assignment/templates/projector/Assignment.html index d516baa88..8627d6022 100644 --- a/openslides/assignment/templates/projector/Assignment.html +++ b/openslides/assignment/templates/projector/Assignment.html @@ -28,17 +28,17 @@ {% endblock %} {% block scrollcontent %} - {% if not assignment.profile.exists %} + {% if not assignment.candidates %}

{{ assignment.description|linebreaks }}

{% endif %} - {% if assignment.profile.exists and assignment.status != "fin" %} + {% if assignment.candidates and assignment.status != "fin" %}

{% trans "Candidates" %}

    - {% for profile in assignment.profile.all|dictsort:"user.first_name" %} -
  1. {{ profile }}
  2. + {% for candidate in assignment.candidates %} +
  3. {{ candidate }}
  4. {% empty %}
  5. {% trans "No candidates available." %} @@ -122,7 +122,7 @@ - {% elif assignment.profile.exists %} + {% elif assignment.candidates %} {% trans "No ballots available." %} {% endif %}
    diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index 350bf0e19..0b2ef82a0 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -33,7 +33,9 @@ from openslides.utils.views import FormView, DeleteView, PDFView, RedirectView from openslides.utils.user import get_user from openslides.config.models import config + from openslides.participant.models import Profile +from openslides.participant.api import user2djangouser from openslides.projector.projector import Widget @@ -169,13 +171,10 @@ def set_status(request, assignment_id=None, status=None): def run(request, assignment_id): assignment = Assignment.objects.get(pk=assignment_id) try: - assignment.run(request.user.profile, request.user) + assignment.run(user2djangouser(request.user), request.user) messages.success(request, _('You have set your candidature successfully.') ) except NameError, e: messages.error(request, e) - except Profile.DoesNotExist: - messages.error(request, - _("You can't candidate. Your user account is only for administration.")) return redirect(reverse('assignment_view', args=[assignment_id])) @@ -183,7 +182,10 @@ def run(request, assignment_id): def delrun(request, assignment_id): assignment = Assignment.objects.get(pk=assignment_id) try: - assignment.delrun(request.user.profile) + if assignment.status == 'sea' or user.has_perm("assignment.can_manage_assignment"): + assignment.delrun(user2djangouser(request.user)) + else: + messages.error(request, _('The candidate list is already closed.')) except Exception, e: messages.error(request, e) else: @@ -370,7 +372,7 @@ class AssignmentPDF(PDFView): cell2a.append(Paragraph("%s:" % _("Candidates"), stylesheet['Heading4'])) cell2b = [] - for candidate in assignment.profile.all(): + for candidate in assignment.candidates: cell2b.append(Paragraph(".  %s" % candidate, stylesheet['Signaturefield'])) if assignment.status == "sea":