updated some parts of OpenSlides to the new user-api

This commit is contained in:
Oskar Hahn 2012-08-04 15:02:02 +02:00
parent 465497ab30
commit 1a1bcb2358
9 changed files with 41 additions and 49 deletions

View File

@ -59,7 +59,7 @@
{% if not forloop.last %}<br>{%endif%} {% if not forloop.last %}<br>{%endif%}
{% endfor %} {% endfor %}
</td> </td>
<td>{{ application.submitter.profile }}</td> <td>{{ application.submitter }}</td>
<td>{{ application.creation_time }}</td> <td>{{ application.creation_time }}</td>
<td> <td>
<span style="width: 1px; white-space: nowrap;"> <span style="width: 1px; white-space: nowrap;">

View File

@ -53,7 +53,7 @@
{% endwith %} {% endwith %}
<p><b>{% trans "Submitter" %}:</b><br> <p><b>{% trans "Submitter" %}:</b><br>
{{ application.submitter.profile }} {{ application.submitter }}
</p> </p>
</div> </div>
</div> </div>

View File

@ -748,13 +748,10 @@ class ApplicationPDF(PDFView):
if application.status == "pub": if application.status == "pub":
cell1b.append(Paragraph("__________________________________________",stylesheet['Signaturefield'])) cell1b.append(Paragraph("__________________________________________",stylesheet['Signaturefield']))
cell1b.append(Spacer(0,0.1*cm)) cell1b.append(Spacer(0,0.1*cm))
cell1b.append(Paragraph("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+unicode(application.submitter.profile), stylesheet['Small'])) cell1b.append(Paragraph("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+unicode(application.submitter), stylesheet['Small']))
cell1b.append(Spacer(0,0.2*cm)) cell1b.append(Spacer(0,0.2*cm))
else: else:
try: cell1b.append(Paragraph(unicode(application.submitter), stylesheet['Normal']))
cell1b.append(Paragraph(unicode(application.submitter.profile), stylesheet['Normal']))
except Profile.DoesNotExist:
pass
# supporters # supporters
cell2a = [] cell2a = []
@ -764,7 +761,7 @@ class ApplicationPDF(PDFView):
cell2a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font><seqreset id='counter'>" % _("Supporters"), stylesheet['Heading4'])) cell2a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font><seqreset id='counter'>" % _("Supporters"), stylesheet['Heading4']))
for supporter in application.supporters: for supporter in application.supporters:
cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; %s" % unicode(s.profile), stylesheet['Signaturefield'])) cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; %s" % unicode(supporter), stylesheet['Signaturefield']))
if application.status == "pub": if application.status == "pub":
for x in range(0,application.missing_supporters): for x in range(0,application.missing_supporters):
cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; __________________________________________",stylesheet['Signaturefield'])) cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; __________________________________________",stylesheet['Signaturefield']))

View File

@ -16,7 +16,6 @@ from django.utils.translation import ugettext_lazy as _, ugettext_noop
from openslides.utils.forms import CssClassMixin from openslides.utils.forms import CssClassMixin
from openslides.utils.user import UserFormField from openslides.utils.user import UserFormField
from openslides.participant.models import Profile
from openslides.assignment.models import Assignment from openslides.assignment.models import Assignment
@ -26,7 +25,7 @@ class AssignmentForm(forms.ModelForm, CssClassMixin):
class Meta: class Meta:
model = Assignment model = Assignment
exclude = ('status', 'profile', 'elected') exclude = ('status', 'elected')
class AssignmentRunForm(forms.Form, CssClassMixin): class AssignmentRunForm(forms.Form, CssClassMixin):

View File

@ -23,8 +23,6 @@ from openslides.config.signals import default_config_value
from openslides.projector.api import register_slidemodel from openslides.projector.api import register_slidemodel
from openslides.projector.projector import SlideMixin from openslides.projector.projector import SlideMixin
from openslides.participant.models import Profile
from openslides.poll.models import (BasePoll, CountInvalid, CountVotesCast, from openslides.poll.models import (BasePoll, CountInvalid, CountVotesCast,
BaseOption, PublishPollMixin, BaseVote) BaseOption, PublishPollMixin, BaseVote)
@ -71,28 +69,27 @@ class Assignment(models.Model, SlideMixin):
self.status = status self.status = status
self.save() self.save()
def run(self, profile, user=None): def run(self, candidate, user=None):
""" """
run for a vote run for a vote
""" """
if self.is_candidate(profile): # TODO: don't make any permission checks here.
raise NameError(_('<b>%s</b> is already a candidate.') % profile) # Use other Exceptions
if self.is_candidate(candidate):
raise NameError(_('<b>%s</b> is already a candidate.') % candidate)
if not user.has_perm("assignment.can_manage_assignment") and self.status != 'sea': if not user.has_perm("assignment.can_manage_assignment") and self.status != 'sea':
raise NameError(_('The candidate list is already closed.')) 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 stop running for a vote
""" """
if self.status != 'sea': if self.is_candidate(candidate):
# TODO: Use an OpenSlides Error self.assignment_candidats.get(user=candidate).delete()
raise Exception(_('The candidate list is already closed.'))
if self.is_candidate(user):
assignment_candidats.get(user=user).delete()
else: else:
# TODO: Use an OpenSlides Error # TODO: Use an OpenSlides Error
raise Exception(_('%s is no candidate') % user) raise Exception(_('%s is no candidate') % candidate)
def is_candidate(self, user): def is_candidate(self, user):
if self.assignment_candidats.filter(user=user).exists(): if self.assignment_candidats.filter(user=user).exists():

View File

@ -31,7 +31,7 @@
<tr class="{% cycle '' 'odd' %} <tr class="{% cycle '' 'odd' %}
{% if assignment.active %}activeline{% endif %}"> {% if assignment.active %}activeline{% endif %}">
<td><a href="{% url assignment_view assignment.id %}">{{ assignment }}</a></td> <td><a href="{% url assignment_view assignment.id %}">{{ assignment }}</a></td>
<td>{{ assignment.profile.count }} / {{ assignment.posts }}</td> <td>{{ assignment.candidates|length }} / {{ assignment.posts }}</td>
<td>{{ assignment.get_status_display }}</td> <td>{{ assignment.get_status_display }}</td>
<td> <td>
<span style="width: 1px; white-space: nowrap;"> <span style="width: 1px; white-space: nowrap;">

View File

@ -54,21 +54,18 @@
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
{% if perms.assignment.can_nominate_self %} {% if perms.assignment.can_nominate_self %}
<p> <p>
{% if user.profile in assignment.profile.all %} {% if user in assignment.candidates %}
<a href='{% url assignment_delrun assignment.id %}'>
<a href='{% url assignment_delrun assignment.id %}'> <span class="button">
<span class="button"> <span class="icon removeuser">{% trans 'Withdraw self candidature' %}</span>
<span class="icon removeuser">{% trans 'Withdraw self candidature' %}</span> </span>
</span> </a>
</a>
{% else %} {% else %}
{% if user.profile %} <a href='{% url assignment_run assignment.id %}'>
<a href='{% url assignment_run assignment.id %}'> <span class="button">
<span class="button"> <span class="icon adduser">{% trans 'Self candidature' %}</span>
<span class="icon adduser">{% trans 'Self candidature' %}</span> </span>
</span> </a>
</a>
{% endif %}
{% endif %} {% endif %}
</p> </p>
{% endif %} {% endif %}

View File

@ -28,17 +28,17 @@
{% endblock %} {% endblock %}
{% block scrollcontent %} {% block scrollcontent %}
{% if not assignment.profile.exists %} {% if not assignment.candidates %}
<p> <p>
<div class="text">{{ assignment.description|linebreaks }}</div> <div class="text">{{ assignment.description|linebreaks }}</div>
</p> </p>
{% endif %} {% endif %}
{% if assignment.profile.exists and assignment.status != "fin" %} {% if assignment.candidates and assignment.status != "fin" %}
<h3>{% trans "Candidates" %}</h3> <h3>{% trans "Candidates" %}</h3>
<ol> <ol>
{% for profile in assignment.profile.all|dictsort:"user.first_name" %} {% for candidate in assignment.candidates %}
<li>{{ profile }} </li> <li>{{ candidate }} </li>
{% empty %} {% empty %}
<li style="list-style: none outside none;"> <li style="list-style: none outside none;">
<i>{% trans "No candidates available." %}</i> <i>{% trans "No candidates available." %}</i>
@ -122,7 +122,7 @@
</tr> </tr>
</table> </table>
{% elif assignment.profile.exists %} {% elif assignment.candidates %}
<i>{% trans "No ballots available." %}</i> <i>{% trans "No ballots available." %}</i>
{% endif %} {% endif %}
<br> <br>

View File

@ -33,7 +33,9 @@ from openslides.utils.views import FormView, DeleteView, PDFView, RedirectView
from openslides.utils.user import get_user from openslides.utils.user import get_user
from openslides.config.models import config from openslides.config.models import config
from openslides.participant.models import Profile from openslides.participant.models import Profile
from openslides.participant.api import user2djangouser
from openslides.projector.projector import Widget from openslides.projector.projector import Widget
@ -169,13 +171,10 @@ def set_status(request, assignment_id=None, status=None):
def run(request, assignment_id): def run(request, assignment_id):
assignment = Assignment.objects.get(pk=assignment_id) assignment = Assignment.objects.get(pk=assignment_id)
try: try:
assignment.run(request.user.profile, request.user) assignment.run(user2djangouser(request.user), request.user)
messages.success(request, _('You have set your candidature successfully.') ) messages.success(request, _('You have set your candidature successfully.') )
except NameError, e: except NameError, e:
messages.error(request, 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])) return redirect(reverse('assignment_view', args=[assignment_id]))
@ -183,7 +182,10 @@ def run(request, assignment_id):
def delrun(request, assignment_id): def delrun(request, assignment_id):
assignment = Assignment.objects.get(pk=assignment_id) assignment = Assignment.objects.get(pk=assignment_id)
try: 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: except Exception, e:
messages.error(request, e) messages.error(request, e)
else: else:
@ -370,7 +372,7 @@ class AssignmentPDF(PDFView):
cell2a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font><seqreset" \ cell2a.append(Paragraph("<font name='Ubuntu-Bold'>%s:</font><seqreset" \
" id='counter'>" % _("Candidates"), stylesheet['Heading4'])) " id='counter'>" % _("Candidates"), stylesheet['Heading4']))
cell2b = [] cell2b = []
for candidate in assignment.profile.all(): for candidate in assignment.candidates:
cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; %s" % candidate, cell2b.append(Paragraph("<seq id='counter'/>.&nbsp; %s" % candidate,
stylesheet['Signaturefield'])) stylesheet['Signaturefield']))
if assignment.status == "sea": if assignment.status == "sea":