OpenSlides/openslides/assignment/views.py

654 lines
24 KiB
Python
Raw Normal View History

2012-07-06 18:00:43 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.assignment.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Views for the assignment app.
:copyright: 20112013 by OpenSlides team, see AUTHORS.
2012-07-06 18:00:43 +02:00
:license: GNU GPL, see LICENSE for more details.
"""
import os
from reportlab.lib import colors
from reportlab.platypus import (
SimpleDocTemplate, PageBreak, Paragraph, Spacer, Table, TableStyle)
2012-07-06 18:00:43 +02:00
from reportlab.lib.units import cm
2012-07-10 11:27:06 +02:00
from django.conf import settings
2012-07-06 18:00:43 +02:00
from django.core.urlresolvers import reverse
from django.contrib import messages
2012-07-10 11:27:06 +02:00
from django.shortcuts import redirect
from django.utils.translation import ungettext, ugettext as _
2012-07-06 18:00:43 +02:00
from openslides.utils.pdf import stylesheet
from openslides.utils.template import Tab
from openslides.utils.utils import gen_confirm_form
from openslides.utils.views import (
CreateView, DeleteView, RedirectView, UpdateView, ListView, PDFView,
DetailView, View, PermissionMixin, SingleObjectMixin, QuestionMixin)
from openslides.utils.person import get_person
from openslides.utils.utils import html_strong
from openslides.config.api import config
from openslides.participant.models import User, Group
2012-07-10 11:27:06 +02:00
from openslides.projector.projector import Widget
from openslides.poll.views import PollFormView
from openslides.agenda.views import CreateRelatedAgendaItemView as _CreateRelatedAgendaItemView
from openslides.assignment.models import Assignment, AssignmentPoll
from openslides.assignment.forms import AssignmentForm, AssignmentRunForm
2012-07-06 18:00:43 +02:00
class AssignmentListView(ListView):
"""ListView for all Assignments"""
permission_required = 'assignment.can_see_assignment'
model = Assignment
2012-07-06 18:00:43 +02:00
class AssignmentDetail(DetailView):
permission_required = 'assignment.can_see_assignment'
model = Assignment
form_class = AssignmentRunForm
def get_context_data(self, *args, **kwargs):
context = super(AssignmentDetail, self).get_context_data(*args, **kwargs)
if self.request.method == 'POST':
context['form'] = self.form_class(self.request.POST)
else:
context['form'] = self.form_class()
polls = self.object.poll_set.all()
if not self.request.user.has_perm('assignment.can_manage_assignment'):
polls = self.object.poll_set.filter(published=True)
vote_results = self.object.vote_results(only_published=True)
else:
polls = self.object.poll_set.all()
vote_results = self.object.vote_results(only_published=False)
blocked_candidates = [
candidate.person for candidate in
self.object.assignment_candidates.filter(blocked=True)]
context['polls'] = polls
context['vote_results'] = vote_results
context['blocked_candidates'] = blocked_candidates
context['user_is_candidate'] = self.object.is_candidate(self.request.user)
return context
def post(self, *args, **kwargs):
self.object = self.get_object()
if self.request.user.has_perm('assignment.can_nominate_other'):
form = self.form_class(self.request.POST)
2012-07-06 18:00:43 +02:00
if form.is_valid():
user = form.cleaned_data['candidate']
try:
self.object.run(user, self.request.user)
2012-07-06 18:00:43 +02:00
except NameError, e:
messages.error(self.request, e)
else:
messages.success(self.request, _(
"Candidate %s was nominated successfully.")
% html_strong(user))
return super(AssignmentDetail, self).get(*args, **kwargs)
class AssignmentCreateView(CreateView):
model = Assignment
form_class = AssignmentForm
permission_required = 'assignment.can_manage_assignment'
class AssignmentUpdateView(UpdateView):
model = Assignment
form_class = AssignmentForm
permission_required = 'assignment.can_manage_assignment'
class AssignmentDeleteView(DeleteView):
permission_required = 'assignment.can_manage_assignment'
model = Assignment
success_url_name = 'assignment_list'
class AssignmentSetStatusView(SingleObjectMixin, RedirectView):
model = Assignment
permission_required = 'assignment.can_manage_assignment'
url_name = 'assignment_detail'
def pre_redirect(self, *args, **kwargs):
self.object = self.get_object()
status = kwargs.get('status')
2012-07-06 18:00:43 +02:00
if status is not None:
try:
self.object.set_status(status)
except ValueError, e:
messages.error(self.request, e)
else:
messages.success(
self.request,
_('Election status was set to: %s.') %
html_strong(self.object.get_status_display())
)
class AssignmentRunView(SingleObjectMixin, PermissionMixin, View):
model = Assignment
permission_required = 'assignment.can_nominate_self'
def get(self, *args, **kwargs):
assignment = self.get_object()
try:
assignment.run(self.request.user, self.request.user)
except NameError, e:
messages.error(self.request, e)
else:
messages.success(
self.request, _('You have set your candidature successfully.'))
return redirect(reverse('assignment_detail', args=[assignment.pk]))
2012-07-06 18:00:43 +02:00
class AssignmentRunDeleteView(SingleObjectMixin, RedirectView):
model = Assignment
url_name = 'assignment_detail'
success_message = _("You have withdrawn your candidature successfully. "
"You can not be nominated by other participants anymore.")
def pre_redirect(self, *args, **kwargs):
self.object = self.get_object()
if self.object.status == 'sea' or self.request.user.has_perm(
"assignment.can_manage_assignment"):
try:
self.object.delrun(self.request.user, blocked=True)
except Exception, e:
messages.error(self.request, e)
2012-09-13 21:51:50 +02:00
else:
messages.success(self.request, self.success_message)
else:
messages.error(self.request, _('The candidate list is already closed.'))
class AssignmentRunOtherDeleteView(SingleObjectMixin, QuestionMixin,
RedirectView):
model = Assignment
permission_required = 'assignment.can_manage_assignment'
question_url_name = 'assignment_detail'
success_url_name = 'assignment_detail'
success_message = ''
def pre_redirect(self, *args, **kwargs):
self._get_person_information(*args, **kwargs)
if not self.is_blocked:
message = _("Do you really want to withdraw %s from the election?") % html_strong(self.person)
2012-09-13 21:51:50 +02:00
else:
message = _("Do you really want to unblock %s for the election?") % html_strong(self.person)
gen_confirm_form(self.request, message, reverse('assignment_delother',
args=[self.object.pk, kwargs['user_id']]))
2012-07-06 18:00:43 +02:00
def pre_post_redirect(self, *args, **kwargs):
self._get_person_information(*args, **kwargs)
if self.get_answer() == 'yes':
self.case_yes()
2012-07-06 18:00:43 +02:00
def get_answer(self):
if 'submit' in self.request.POST:
return 'yes'
2012-07-06 18:00:43 +02:00
def case_yes(self):
try:
self.object.delrun(self.person, blocked=False)
except Exception, e:
messages.error(self.request, e)
else:
messages.success(self.request, self.get_success_message())
def get_success_message(self):
success_message = _("Candidate %s was withdrawn successfully.") % html_strong(self.person)
if self.is_blocked:
success_message = _("%s was unblocked successfully.") % html_strong(self.person)
return success_message
2012-07-06 18:00:43 +02:00
def _get_person_information(self, *args, **kwargs):
self.object = self.get_object()
self.person = get_person(kwargs.get('user_id'))
self.is_blocked = self.object.is_blocked(self.person)
2012-07-06 18:00:43 +02:00
class PollCreateView(SingleObjectMixin, RedirectView):
model = Assignment
permission_required = 'assignment.can_manage_assignment'
url_name = 'assignment_poll_view'
def pre_redirect(self, *args, **kwargs):
self.object = self.get_object().gen_poll()
messages.success(self.request, _("New ballot was successfully created."))
class PollUpdateView(PollFormView):
2012-07-06 18:00:43 +02:00
poll_class = AssignmentPoll
template_name = 'assignment/poll_view.html'
def get_context_data(self, **kwargs):
context = super(PollUpdateView, self).get_context_data(**kwargs)
2012-07-06 18:00:43 +02:00
self.assignment = self.poll.get_assignment()
context['assignment'] = self.assignment
context['poll'] = self.poll
context['polls'] = self.assignment.poll_set.filter(assignment=self.assignment)
context['ballotnumber'] = self.poll.get_ballot()
return context
def get_success_url(self):
return_url = ''
2012-07-06 18:00:43 +02:00
if not 'apply' in self.request.POST:
return_url = reverse('assignment_detail', args=[self.poll.assignment.id])
return return_url
class SetPublishStatusView(SingleObjectMixin, RedirectView):
model = AssignmentPoll
permission_required = 'assignment.can_manage_assignment'
url_name = 'assignment_detail'
allow_ajax = True
2012-07-06 18:00:43 +02:00
def get_ajax_context(self, **kwargs):
return {'published': self.object.published}
2012-07-06 18:00:43 +02:00
def pre_redirect(self, *args, **kwargs):
try:
self.object = self.get_object()
except self.model.DoesNotExist:
messages.error(self.request, _('Ballot ID %d does not exist.') %
int(kwargs['poll_id']))
2012-07-06 18:00:43 +02:00
else:
if self.object.published:
self.object.set_published(False)
else:
self.object.set_published(True)
class SetElectedView(SingleObjectMixin, RedirectView):
model = Assignment
permission_required = 'assignment.can_manage_assignment'
url_name = 'assignment_detail'
allow_ajax = True
def pre_redirect(self, *args, **kwargs):
self.object = self.get_object()
self.person = get_person(kwargs['user_id'])
self.elected = kwargs['elected']
self.object.set_elected(self.person, self.elected)
def get_ajax_context(self, **kwargs):
if self.elected:
link = reverse('assignment_user_not_elected',
args=[self.object.id, self.person.person_id])
2012-07-06 18:00:43 +02:00
text = _('not elected')
else:
link = reverse('assignment_user_elected',
args=[self.object.id, self.person.person_id])
2012-07-06 18:00:43 +02:00
text = _('elected')
return {'elected': self.elected, 'link': link, 'text': text}
2012-07-06 18:00:43 +02:00
class AssignmentPollDeleteView(DeleteView):
2012-07-06 18:00:43 +02:00
"""
Delete an assignment poll object.
"""
permission_required = 'assignment.can_manage_assignment'
model = AssignmentPoll
def pre_redirect(self, request, *args, **kwargs):
self.set_assignment()
super(AssignmentPollDeleteView, self).pre_redirect(request, *args, **kwargs)
2012-07-06 18:00:43 +02:00
def pre_post_redirect(self, request, *args, **kwargs):
self.set_assignment()
super(AssignmentPollDeleteView, self).pre_post_redirect(request, *args, **kwargs)
2012-07-06 18:00:43 +02:00
def set_assignment(self):
self.assignment = self.object.assignment
def get_redirect_url(self, **kwargs):
return reverse('assignment_detail', args=[self.assignment.id])
2012-07-06 18:00:43 +02:00
def get_success_message(self):
return _('Ballot was successfully deleted.')
2012-07-06 18:00:43 +02:00
class AssignmentPDF(PDFView):
permission_required = 'assignment.can_see_assignment'
top_space = 0
def get_filename(self):
try:
assignment_id = self.kwargs['pk']
2012-07-06 18:00:43 +02:00
assignment = Assignment.objects.get(id=assignment_id)
filename = u'%s-%s' % (
_("Assignment"),
assignment.name.replace(' ', '_'))
2012-07-06 18:00:43 +02:00
except:
filename = _("Elections")
return filename
def append_to_pdf(self, story):
try:
assignment_id = self.kwargs['pk']
2012-07-06 18:00:43 +02:00
except KeyError:
assignment_id = None
if assignment_id is None: # print all assignments
2012-07-06 18:00:43 +02:00
title = config["assignment_pdf_title"]
story.append(Paragraph(title, stylesheet['Heading1']))
preamble = config["assignment_pdf_preamble"]
if preamble:
story.append(Paragraph(
"%s" % preamble.replace('\r\n', '<br/>'),
2012-07-10 11:27:06 +02:00
stylesheet['Paragraph']))
story.append(Spacer(0, 0.75 * cm))
assignments = Assignment.objects.all()
if not assignments: # No assignments existing
story.append(Paragraph(
_("No assignments available."), stylesheet['Heading3']))
else: # Print all assignments
2012-07-06 18:00:43 +02:00
# List of assignments
for assignment in assignments:
story.append(Paragraph(
assignment.name, stylesheet['Heading3']))
2012-07-06 18:00:43 +02:00
# Assignment details (each assignment on single page)
for assignment in assignments:
story.append(PageBreak())
# append the assignment to the story-object
self.get_assignment(assignment, story)
2012-07-06 18:00:43 +02:00
else: # print selected assignment
assignment = Assignment.objects.get(id=assignment_id)
# append the assignment to the story-object
self.get_assignment(assignment, story)
2012-07-06 18:00:43 +02:00
def get_assignment(self, assignment, story):
# title
story.append(Paragraph(
_("Election: %s") % assignment.name, stylesheet['Heading1']))
story.append(Spacer(0, 0.5 * cm))
2012-07-06 18:00:43 +02:00
# posts
cell1a = []
cell1a.append(Paragraph(
"<font name='Ubuntu-Bold'>%s:</font>" %
2012-07-10 11:27:06 +02:00
_("Number of available posts"), stylesheet['Bold']))
2012-07-06 18:00:43 +02:00
cell1b = []
cell1b.append(Paragraph(str(assignment.posts), stylesheet['Paragraph']))
# candidates
cell2a = []
cell2a.append(Paragraph(
"<font name='Ubuntu-Bold'>%s:</font><seqreset"
2012-07-10 11:27:06 +02:00
" id='counter'>" % _("Candidates"), stylesheet['Heading4']))
2012-07-06 18:00:43 +02:00
cell2b = []
for candidate in assignment.candidates:
cell2b.append(Paragraph(
"<seq id='counter'/>.&nbsp; %s" % candidate,
2012-07-10 11:27:06 +02:00
stylesheet['Signaturefield']))
2012-07-06 18:00:43 +02:00
if assignment.status == "sea":
for x in range(0, 2 * assignment.posts):
cell2b.append(
Paragraph(
"<seq id='counter'/>.&nbsp; "
"__________________________________________",
stylesheet['Signaturefield']))
cell2b.append(Spacer(0, 0.2 * cm))
2012-07-06 18:00:43 +02:00
# Vote results
# Preparing
vote_results = assignment.vote_results(only_published=True)
polls = assignment.poll_set.filter(published=True)
2012-07-06 18:00:43 +02:00
data_votes = []
# Left side
cell3a = []
cell3a.append(Paragraph(
"%s:" % (_("Vote results")), stylesheet['Heading4']))
2012-07-06 18:00:43 +02:00
if polls.count() == 1:
cell3a.append(Paragraph(
"%s %s" % (polls.count(), _("ballot")), stylesheet['Normal']))
elif polls.count() > 1:
cell3a.append(Paragraph(
"%s %s" % (polls.count(), _("ballots")), stylesheet['Normal']))
2012-07-06 18:00:43 +02:00
# Add table head row
headrow = []
headrow.append(_("Candidates"))
for poll in polls:
headrow.append("%s." % poll.get_ballot())
2012-07-06 18:00:43 +02:00
data_votes.append(headrow)
# Add result rows
2012-08-08 10:52:13 +02:00
elected_candidates = list(assignment.elected)
2012-07-06 18:00:43 +02:00
for candidate, poll_list in vote_results.iteritems():
row = []
candidate_string = candidate.clean_name
if candidate in elected_candidates:
candidate_string = "* " + candidate_string
2012-10-24 12:30:45 +02:00
if candidate.name_suffix:
candidate_string += "\n(%s)" % candidate.name_suffix
row.append(candidate_string)
for vote in poll_list:
if vote is None:
row.append('')
elif 'Yes' in vote and 'No' in vote and 'Abstain' in vote:
row.append(
_("Y: %(YES)s\nN: %(NO)s\nA: %(ABSTAIN)s")
% {'YES': vote['Yes'], 'NO': vote['No'],
'ABSTAIN': vote['Abstain']})
elif 'Votes' in vote:
row.append(vote['Votes'])
2012-07-06 18:00:43 +02:00
else:
pass
data_votes.append(row)
# Add votes invalid row
footrow_one = []
footrow_one.append(_("Invalid votes"))
for poll in polls:
footrow_one.append(poll.print_votesinvalid())
2012-07-06 18:00:43 +02:00
data_votes.append(footrow_one)
# Add votes cast row
footrow_two = []
footrow_two.append(_("Votes cast"))
for poll in polls:
footrow_two.append(poll.print_votescast())
2012-07-06 18:00:43 +02:00
data_votes.append(footrow_two)
table_votes = Table(data_votes)
table_votes.setStyle(
TableStyle([
('GRID', (0, 0), (-1, -1), 0.5, colors.grey),
('VALIGN', (0, 0), (-1, -1), 'TOP'),
('LINEABOVE', (0, 0), (-1, 0), 2, colors.black),
('LINEABOVE', (0, 1), (-1, 1), 1, colors.black),
('LINEBELOW', (0, -1), (-1, -1), 2, colors.black),
('ROWBACKGROUNDS', (0, 1), (-1, -1), (colors.white, (.9, .9, .9)))
])
)
2012-07-06 18:00:43 +02:00
# table
data = []
data.append([cell1a, cell1b])
if polls:
data.append([cell3a, table_votes])
data.append(['', '* = ' + _('elected')])
2012-07-06 18:00:43 +02:00
else:
data.append([cell2a, cell2b])
2012-07-10 11:27:06 +02:00
data.append([Spacer(0, 0.2 * cm), ''])
t = Table(data)
2012-07-10 11:27:06 +02:00
t._argW[0] = 4.5 * cm
t._argW[1] = 11 * cm
t.setStyle(TableStyle([
('BOX', (0, 0), (-1, -1), 1, colors.black),
('VALIGN', (0, 0), (-1, -1), 'TOP')]))
2012-07-06 18:00:43 +02:00
story.append(t)
2012-07-10 11:27:06 +02:00
story.append(Spacer(0, 1 * cm))
2012-07-06 18:00:43 +02:00
# text
story.append(
Paragraph("%s" % assignment.description.replace('\r\n', '<br/>'),
stylesheet['Paragraph']))
2012-07-06 18:00:43 +02:00
class CreateRelatedAgendaItemView(_CreateRelatedAgendaItemView):
"""
View to create and agenda item for an assignment.
"""
model = Assignment
2012-07-06 18:00:43 +02:00
class AssignmentPollPDF(PDFView):
permission_required = 'assignment.can_manage_assignment'
top_space = 0
def get(self, request, *args, **kwargs):
self.poll = AssignmentPoll.objects.get(id=self.kwargs['poll_id'])
return super(AssignmentPollPDF, self).get(request, *args, **kwargs)
def get_filename(self):
filename = u'%s-%s_%s' % (
_("Election"), self.poll.assignment.name.replace(' ', '_'),
2012-07-23 23:00:00 +02:00
self.poll.get_ballot())
2012-07-06 18:00:43 +02:00
return filename
def get_template(self, buffer):
return SimpleDocTemplate(
buffer, topMargin=-6, bottomMargin=-6, leftMargin=0, rightMargin=0,
showBoundary=False)
2012-07-06 18:00:43 +02:00
def build_document(self, pdf_document, story):
pdf_document.build(story)
def append_to_pdf(self, story):
2013-01-18 22:23:31 +01:00
imgpath = os.path.join(settings.SITE_ROOT, 'static/img/circle.png')
2012-07-06 18:00:43 +02:00
circle = "<img src='%s' width='15' height='15'/>&nbsp;&nbsp;" % imgpath
cell = []
cell.append(Spacer(0, 0.8 * cm))
cell.append(Paragraph(
_("Election") + ": " + self.poll.assignment.name,
2012-07-10 11:27:06 +02:00
stylesheet['Ballot_title']))
cell.append(Paragraph(
self.poll.assignment.polldescription,
2012-07-10 11:27:06 +02:00
stylesheet['Ballot_subtitle']))
2012-11-22 16:19:09 +01:00
options = self.poll.get_options()
2012-07-10 11:27:06 +02:00
ballot_string = _("%d. ballot") % self.poll.get_ballot()
candidate_string = ungettext(
"%d candidate", "%d candidates", len(options)) % len(options)
available_posts_string = ungettext(
"%d available post", "%d available posts",
self.poll.assignment.posts) % self.poll.assignment.posts
cell.append(Paragraph(
"%s, %s, %s" % (ballot_string, candidate_string, available_posts_string),
stylesheet['Ballot_description']))
2012-07-10 11:27:06 +02:00
cell.append(Spacer(0, 0.4 * cm))
2012-07-06 18:00:43 +02:00
data = []
2012-07-06 18:00:43 +02:00
# get ballot papers config values
ballot_papers_selection = config["assignment_pdf_ballot_papers_selection"]
ballot_papers_number = config["assignment_pdf_ballot_papers_number"]
# set number of ballot papers
if ballot_papers_selection == "NUMBER_OF_DELEGATES":
try:
if Group.objects.get(pk=3):
number = User.objects.filter(groups__pk=3).count()
except Group.DoesNotExist:
number = 0
2012-07-06 18:00:43 +02:00
elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS":
number = int(User.objects.count())
else: # ballot_papers_selection == "CUSTOM_NUMBER"
2012-07-06 18:00:43 +02:00
number = int(ballot_papers_number)
number = max(1, number)
# Choose kind of ballot paper
if self.poll.yesnoabstain:
for option in options:
candidate = option.candidate
cell.append(Paragraph(
candidate.clean_name, stylesheet['Ballot_option_name']))
if candidate.name_suffix:
cell.append(Paragraph(
"(%s)" % candidate.name_suffix,
2012-07-10 11:27:06 +02:00
stylesheet['Ballot_option_group']))
2012-07-06 18:00:43 +02:00
else:
cell.append(Paragraph(
"&nbsp;", stylesheet['Ballot_option_group']))
cell.append(Paragraph(
circle + _("Yes") + "&nbsp; " * 3 + circle
+ _("No") + "&nbsp; " * 3 + circle + _("Abstention"),
2012-07-10 11:27:06 +02:00
stylesheet['Ballot_option_YNA']))
2012-07-06 18:00:43 +02:00
# print ballot papers
for user in xrange(number / 2):
data.append([cell, cell])
rest = number % 2
if rest:
data.append([cell, ''])
if len(options) <= 2:
2012-07-10 11:27:06 +02:00
t = Table(data, 10.5 * cm, 7.42 * cm)
2012-07-06 18:00:43 +02:00
elif len(options) <= 5:
2012-07-10 11:27:06 +02:00
t = Table(data, 10.5 * cm, 14.84 * cm)
2012-07-06 18:00:43 +02:00
else:
2012-07-10 11:27:06 +02:00
t = Table(data, 10.5 * cm, 29.7 * cm)
2012-07-06 18:00:43 +02:00
else:
for option in options:
candidate = option.candidate
cell.append(Paragraph(
circle + candidate.clean_name,
2012-07-10 11:27:06 +02:00
stylesheet['Ballot_option_name']))
if candidate.name_suffix:
cell.append(Paragraph(
"(%s)" % candidate.name_suffix,
2012-07-10 11:27:06 +02:00
stylesheet['Ballot_option_group_right']))
2012-07-06 18:00:43 +02:00
else:
cell.append(Paragraph(
"&nbsp;", stylesheet['Ballot_option_group_right']))
2012-07-06 18:00:43 +02:00
# print ballot papers
for user in xrange(number / 2):
data.append([cell, cell])
rest = number % 2
if rest:
data.append([cell, ''])
if len(options) <= 4:
2012-07-10 11:27:06 +02:00
t = Table(data, 10.5 * cm, 7.42 * cm)
2012-07-06 18:00:43 +02:00
elif len(options) <= 8:
2012-07-10 11:27:06 +02:00
t = Table(data, 10.5 * cm, 14.84 * cm)
2012-07-06 18:00:43 +02:00
else:
2012-07-10 11:27:06 +02:00
t = Table(data, 10.5 * cm, 29.7 * cm)
2012-07-06 18:00:43 +02:00
t.setStyle(TableStyle([
('GRID', (0, 0), (-1, -1), 0.25, colors.grey),
('VALIGN', (0, 0), (-1, -1), 'TOP')]))
2012-07-06 18:00:43 +02:00
story.append(t)
def register_tab(request):
2012-07-10 11:27:06 +02:00
selected = request.path.startswith('/assignment/')
2012-07-06 18:00:43 +02:00
return Tab(
title=_('Elections'),
app='assignment',
url=reverse('assignment_list'),
permission=(
request.user.has_perm('assignment.can_see_assignment') or
request.user.has_perm('assignment.can_nominate_other') or
request.user.has_perm('assignment.can_nominate_self') or
request.user.has_perm('assignment.can_manage_assignment')),
2012-07-06 18:00:43 +02:00
selected=selected,
)
def get_widgets(request):
return [Widget(
2013-06-13 23:38:58 +02:00
request,
name='assignments',
display_name=_('Elections'),
template='assignment/widget.html',
context={'assignments': Assignment.objects.all()},
permission_required='projector.can_manage_projector',
default_column=1,
default_weight=50)]