2014-01-12 11:03:43 +01:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2012-06-11 13:43:48 +02:00
|
|
|
from django.core.urlresolvers import reverse
|
2012-07-10 11:27:06 +02:00
|
|
|
from django.db import models
|
2013-07-08 14:08:27 +02:00
|
|
|
from django.utils.datastructures import SortedDict
|
2013-09-25 10:01:01 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.utils.translation import ugettext_lazy, ugettext_noop
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2014-01-12 11:03:43 +01:00
|
|
|
from openslides.agenda.models import Item, Speaker
|
2014-12-26 13:45:13 +01:00
|
|
|
from openslides.core.models import Tag
|
2013-09-25 10:01:01 +02:00
|
|
|
from openslides.config.api import config
|
|
|
|
from openslides.poll.models import (BaseOption, BasePoll, BaseVote,
|
2014-04-10 20:18:22 +02:00
|
|
|
CollectDefaultVotesMixin,
|
2013-09-25 10:01:01 +02:00
|
|
|
PublishPollMixin)
|
2015-01-17 14:01:44 +01:00
|
|
|
from openslides.projector.models import SlideMixin
|
2014-01-12 11:03:43 +01:00
|
|
|
from openslides.utils.exceptions import OpenSlidesError
|
2014-01-11 17:57:24 +01:00
|
|
|
from openslides.utils.models import AbsoluteUrlMixin
|
2015-01-17 14:25:05 +01:00
|
|
|
from openslides.utils.rest_api import RESTModelMixin
|
2013-09-08 14:33:43 +02:00
|
|
|
from openslides.utils.utils import html_strong
|
2014-10-11 14:34:49 +02:00
|
|
|
from openslides.users.models import User
|
2012-06-23 11:41:32 +02:00
|
|
|
|
2012-04-21 21:38:59 +02:00
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
class AssignmentCandidate(RESTModelMixin, models.Model):
|
2013-10-03 21:49:51 +02:00
|
|
|
"""
|
|
|
|
Many2Many table between an assignment and the candidates.
|
|
|
|
"""
|
2012-08-03 13:49:05 +02:00
|
|
|
assignment = models.ForeignKey("Assignment")
|
2014-10-11 14:34:49 +02:00
|
|
|
person = models.ForeignKey(User, db_index=True)
|
2012-08-03 13:49:05 +02:00
|
|
|
elected = models.BooleanField(default=False)
|
2012-09-06 15:57:42 +02:00
|
|
|
blocked = models.BooleanField(default=False)
|
2012-08-03 13:49:05 +02:00
|
|
|
|
2013-10-03 21:49:51 +02:00
|
|
|
class Meta:
|
|
|
|
unique_together = ("assignment", "person")
|
|
|
|
|
2014-08-16 09:25:18 +02:00
|
|
|
def __str__(self):
|
|
|
|
return str(self.person)
|
2012-08-03 13:49:05 +02:00
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
def get_root_rest_element(self):
|
|
|
|
"""
|
2015-01-24 16:35:50 +01:00
|
|
|
Returns the assignment to this instance which is the root REST element.
|
2015-01-17 14:25:05 +01:00
|
|
|
"""
|
|
|
|
return self.assignment
|
|
|
|
|
2012-08-03 13:49:05 +02:00
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
class Assignment(RESTModelMixin, SlideMixin, AbsoluteUrlMixin, models.Model):
|
2013-08-04 12:59:11 +02:00
|
|
|
slide_callback_name = 'assignment'
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
STATUS = (
|
2013-04-22 19:59:05 +02:00
|
|
|
('sea', ugettext_lazy('Searching for candidates')),
|
|
|
|
('vot', ugettext_lazy('Voting')),
|
|
|
|
('fin', ugettext_lazy('Finished')),
|
2011-07-31 10:46:29 +02:00
|
|
|
)
|
|
|
|
|
2013-04-22 19:59:05 +02:00
|
|
|
name = models.CharField(max_length=100, verbose_name=ugettext_lazy("Name"))
|
|
|
|
description = models.TextField(null=True, blank=True, verbose_name=ugettext_lazy("Description"))
|
|
|
|
posts = models.PositiveSmallIntegerField(verbose_name=ugettext_lazy("Number of available posts"))
|
2014-01-11 17:07:47 +01:00
|
|
|
poll_description_default = models.CharField(
|
|
|
|
max_length=79, null=True, blank=True,
|
|
|
|
verbose_name=ugettext_lazy("Default comment on the ballot paper"))
|
2012-06-23 13:17:50 +02:00
|
|
|
status = models.CharField(max_length=3, choices=STATUS, default='sea')
|
2014-12-26 13:45:13 +01:00
|
|
|
tags = models.ManyToManyField(Tag, blank=True)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-08-04 12:59:11 +02:00
|
|
|
class Meta:
|
|
|
|
permissions = (
|
2013-11-16 20:20:53 +01:00
|
|
|
('can_see_assignment', ugettext_noop('Can see elections')), # TODO: Add plural s to the codestring
|
2013-08-04 12:59:11 +02:00
|
|
|
('can_nominate_other', ugettext_noop('Can nominate another person')),
|
|
|
|
('can_nominate_self', ugettext_noop('Can nominate oneself')),
|
2013-11-16 20:20:53 +01:00
|
|
|
('can_manage_assignment', ugettext_noop('Can manage elections')), # TODO: Add plural s also to the codestring
|
2013-08-04 12:59:11 +02:00
|
|
|
)
|
|
|
|
ordering = ('name',)
|
2013-11-16 20:20:53 +01:00
|
|
|
verbose_name = ugettext_noop('Election')
|
2013-08-04 12:59:11 +02:00
|
|
|
|
2014-08-16 09:25:18 +02:00
|
|
|
def __str__(self):
|
2013-08-04 12:59:11 +02:00
|
|
|
return self.name
|
|
|
|
|
|
|
|
def get_absolute_url(self, link='detail'):
|
2014-01-11 17:57:24 +01:00
|
|
|
if link == 'detail':
|
|
|
|
url = reverse('assignment_detail', args=[str(self.pk)])
|
|
|
|
elif link == 'update':
|
|
|
|
url = reverse('assignment_update', args=[str(self.pk)])
|
|
|
|
elif link == 'delete':
|
|
|
|
url = reverse('assignment_delete', args=[str(self.pk)])
|
|
|
|
else:
|
|
|
|
url = super(Assignment, self).get_absolute_url(link)
|
|
|
|
return url
|
2013-08-04 12:59:11 +02:00
|
|
|
|
2013-10-03 21:49:51 +02:00
|
|
|
def get_slide_context(self, **context):
|
|
|
|
context.update({
|
|
|
|
'polls': self.poll_set.filter(published=True),
|
|
|
|
'vote_results': self.vote_results(only_published=True)})
|
|
|
|
return super(Assignment, self).get_slide_context(**context)
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
def set_status(self, status):
|
2013-09-08 14:33:43 +02:00
|
|
|
status_dict = dict(self.STATUS)
|
|
|
|
if status not in status_dict:
|
|
|
|
raise ValueError(_('%s is not a valid status.') % html_strong(status))
|
2011-07-31 10:46:29 +02:00
|
|
|
if self.status == status:
|
2013-09-08 14:33:43 +02:00
|
|
|
raise ValueError(
|
2013-11-16 20:20:53 +01:00
|
|
|
_('The election status is already %s.') % html_strong(status_dict[status]))
|
2011-07-31 10:46:29 +02:00
|
|
|
self.status = status
|
|
|
|
self.save()
|
|
|
|
|
2012-08-07 22:43:57 +02:00
|
|
|
def run(self, candidate, person=None):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
|
|
|
run for a vote
|
2012-09-06 15:57:42 +02:00
|
|
|
candidate: The user who will be a candidate
|
|
|
|
person: The user who chooses the candidate
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2012-08-04 15:02:02 +02:00
|
|
|
# TODO: don't make any permission checks here.
|
|
|
|
# Use other Exceptions
|
|
|
|
if self.is_candidate(candidate):
|
|
|
|
raise NameError(_('<b>%s</b> is already a candidate.') % candidate)
|
2012-08-07 22:43:57 +02:00
|
|
|
if not person.has_perm("assignment.can_manage_assignment") and self.status != 'sea':
|
2012-07-16 22:21:23 +02:00
|
|
|
raise NameError(_('The candidate list is already closed.'))
|
2012-11-24 17:39:28 +01:00
|
|
|
candidature = self.assignment_candidates.filter(person=candidate)
|
|
|
|
if candidature and candidate != person and \
|
2012-09-13 14:59:14 +02:00
|
|
|
not person.has_perm("assignment.can_manage_assignment"):
|
2012-11-24 17:39:28 +01:00
|
|
|
# if the candidature is blocked and anotherone tries to run the
|
2012-09-06 15:57:42 +02:00
|
|
|
# candidate
|
|
|
|
raise NameError(
|
2012-09-11 20:50:53 +02:00
|
|
|
_('%s does not want to be a candidate.') % candidate)
|
2012-11-24 17:39:28 +01:00
|
|
|
elif candidature:
|
|
|
|
candidature[0].blocked = False
|
|
|
|
candidature[0].save()
|
2012-09-06 15:57:42 +02:00
|
|
|
else:
|
|
|
|
AssignmentCandidate(assignment=self, person=candidate).save()
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-09-06 15:57:42 +02:00
|
|
|
def delrun(self, candidate, blocked=True):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
|
|
|
stop running for a vote
|
|
|
|
"""
|
2012-09-13 14:59:14 +02:00
|
|
|
try:
|
2012-11-24 17:39:28 +01:00
|
|
|
candidature = self.assignment_candidates.get(person=candidate)
|
2012-09-13 14:59:14 +02:00
|
|
|
except AssignmentCandidate.DoesNotExist:
|
|
|
|
raise Exception(_('%s is no candidate') % candidate)
|
|
|
|
|
2012-11-24 17:39:28 +01:00
|
|
|
if not candidature.blocked:
|
2012-09-06 15:57:42 +02:00
|
|
|
if blocked:
|
2012-11-24 17:39:28 +01:00
|
|
|
candidature.blocked = True
|
|
|
|
candidature.save()
|
2012-09-06 15:57:42 +02:00
|
|
|
else:
|
2012-11-24 17:39:28 +01:00
|
|
|
candidature.delete()
|
2011-07-31 10:46:29 +02:00
|
|
|
else:
|
2012-11-24 17:39:28 +01:00
|
|
|
candidature.delete()
|
2012-09-13 14:59:14 +02:00
|
|
|
|
2012-08-07 22:43:57 +02:00
|
|
|
def is_candidate(self, person):
|
2012-09-06 15:57:42 +02:00
|
|
|
"""
|
|
|
|
return True, if person is a candidate.
|
|
|
|
"""
|
2012-09-19 14:16:17 +02:00
|
|
|
try:
|
2012-11-24 14:01:21 +01:00
|
|
|
return self.assignment_candidates.filter(person=person).exclude(blocked=True).exists()
|
2012-09-19 14:16:17 +02:00
|
|
|
except AttributeError:
|
|
|
|
return False
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-09-13 14:59:14 +02:00
|
|
|
def is_blocked(self, person):
|
|
|
|
"""
|
2012-11-24 17:39:28 +01:00
|
|
|
return True, if the person is blockt for candidature.
|
2012-09-13 14:59:14 +02:00
|
|
|
"""
|
2012-11-24 14:01:21 +01:00
|
|
|
return self.assignment_candidates.filter(person=person).filter(blocked=True).exists()
|
2012-09-13 14:59:14 +02:00
|
|
|
|
2012-08-03 18:56:00 +02:00
|
|
|
@property
|
2012-11-21 20:12:08 +01:00
|
|
|
def assignment_candidates(self):
|
2012-08-03 18:56:00 +02:00
|
|
|
return AssignmentCandidate.objects.filter(assignment=self)
|
|
|
|
|
2011-09-03 11:42:44 +02:00
|
|
|
@property
|
|
|
|
def candidates(self):
|
2012-08-03 18:56:00 +02:00
|
|
|
return self.get_participants(only_candidate=True)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def elected(self):
|
|
|
|
return self.get_participants(only_elected=True)
|
2011-09-03 11:42:44 +02:00
|
|
|
|
2012-08-03 18:56:00 +02:00
|
|
|
def get_participants(self, only_elected=False, only_candidate=False):
|
2012-11-21 20:12:08 +01:00
|
|
|
candidates = self.assignment_candidates.exclude(blocked=True)
|
2012-07-03 00:05:48 +02:00
|
|
|
|
2012-09-12 10:17:51 +02:00
|
|
|
assert not (only_elected and only_candidate)
|
2012-08-03 18:56:00 +02:00
|
|
|
|
|
|
|
if only_elected:
|
|
|
|
candidates = candidates.filter(elected=True)
|
|
|
|
|
|
|
|
if only_candidate:
|
|
|
|
candidates = candidates.filter(elected=False)
|
|
|
|
|
2014-10-11 14:34:49 +02:00
|
|
|
# TODO: rewrite this with a queryset
|
2012-09-12 10:17:51 +02:00
|
|
|
participants = []
|
2012-08-07 22:43:57 +02:00
|
|
|
for candidate in candidates.all():
|
2012-09-12 10:17:51 +02:00
|
|
|
participants.append(candidate.person)
|
|
|
|
return participants
|
2011-09-03 11:42:44 +02:00
|
|
|
|
2012-08-07 22:43:57 +02:00
|
|
|
def set_elected(self, person, value=True):
|
2012-11-21 20:12:08 +01:00
|
|
|
candidate = self.assignment_candidates.get(person=person)
|
2012-08-03 18:56:00 +02:00
|
|
|
candidate.elected = value
|
|
|
|
candidate.save()
|
|
|
|
|
2012-08-07 22:43:57 +02:00
|
|
|
def is_elected(self, person):
|
|
|
|
return person in self.elected
|
2011-09-03 11:42:44 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
def gen_poll(self):
|
2014-01-12 11:03:43 +01:00
|
|
|
"""
|
|
|
|
Creates an new poll for the assignment and adds all candidates to all
|
|
|
|
lists of speakers of related agenda items.
|
|
|
|
"""
|
2014-05-12 17:56:07 +02:00
|
|
|
if config['assignment_poll_vote_values'] == 'votes':
|
|
|
|
yesnoabstain = False
|
|
|
|
elif config['assignment_poll_vote_values'] == 'yesnoabstain':
|
|
|
|
yesnoabstain = True
|
|
|
|
else:
|
|
|
|
# config['assignment_poll_vote_values'] == 'auto'
|
|
|
|
# candidates <= available posts -> yes/no/abstain
|
|
|
|
if len(self.candidates) <= (self.posts - len(self.elected)):
|
|
|
|
yesnoabstain = True
|
|
|
|
else:
|
|
|
|
yesnoabstain = False
|
|
|
|
|
2014-01-11 17:07:47 +01:00
|
|
|
poll = AssignmentPoll.objects.create(
|
2014-05-12 17:56:07 +02:00
|
|
|
assignment=self,
|
|
|
|
description=self.poll_description_default,
|
|
|
|
yesnoabstain=yesnoabstain)
|
2012-08-07 22:43:57 +02:00
|
|
|
poll.set_options([{'candidate': person} for person in self.candidates])
|
2014-05-12 17:56:07 +02:00
|
|
|
|
2014-01-12 11:03:43 +01:00
|
|
|
items = Item.objects.filter(content_type=ContentType.objects.get_for_model(Assignment), object_id=self.pk)
|
|
|
|
for item in items:
|
|
|
|
for candidate in self.candidates:
|
|
|
|
try:
|
2015-01-17 14:01:44 +01:00
|
|
|
Speaker.objects.add(candidate, item)
|
2014-01-12 11:03:43 +01:00
|
|
|
except OpenSlidesError:
|
|
|
|
# The Speaker is already on the list. Do nothing.
|
|
|
|
# TODO: Find a smart way not to catch the error concerning AnonymousUser.
|
|
|
|
pass
|
2014-05-12 17:56:07 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
return poll
|
|
|
|
|
2012-07-10 00:47:00 +02:00
|
|
|
def vote_results(self, only_published):
|
2012-07-03 00:05:48 +02:00
|
|
|
"""
|
|
|
|
returns a table represented as a list with all candidates from all
|
2012-07-04 11:00:58 +02:00
|
|
|
related polls and their vote results.
|
2012-07-03 00:05:48 +02:00
|
|
|
"""
|
2013-07-08 14:08:27 +02:00
|
|
|
vote_results_dict = SortedDict()
|
2012-07-04 11:00:58 +02:00
|
|
|
# All polls related to this assigment
|
2012-07-02 20:32:13 +02:00
|
|
|
polls = self.poll_set.all()
|
2012-07-10 00:47:00 +02:00
|
|
|
if only_published:
|
|
|
|
polls = polls.filter(published=True)
|
2012-07-04 11:00:58 +02:00
|
|
|
# All PollOption-Objects related to this assignment
|
2012-07-03 00:05:48 +02:00
|
|
|
options = []
|
2012-07-02 20:32:13 +02:00
|
|
|
for poll in polls:
|
|
|
|
options += poll.get_options()
|
2012-07-03 00:05:48 +02:00
|
|
|
|
|
|
|
for option in options:
|
|
|
|
candidate = option.candidate
|
|
|
|
if candidate in vote_results_dict:
|
|
|
|
continue
|
|
|
|
vote_results_dict[candidate] = []
|
2012-07-02 20:32:13 +02:00
|
|
|
for poll in polls:
|
2012-07-10 00:47:00 +02:00
|
|
|
votes = {}
|
2012-07-03 00:05:48 +02:00
|
|
|
try:
|
2012-07-04 16:05:31 +02:00
|
|
|
# candidate related to this poll
|
|
|
|
poll_option = poll.get_options().get(candidate=candidate)
|
|
|
|
for vote in poll_option.get_votes():
|
2012-07-13 11:16:06 +02:00
|
|
|
votes[vote.value] = vote.print_weight()
|
2012-07-03 00:05:48 +02:00
|
|
|
except AssignmentOption.DoesNotExist:
|
2012-07-04 11:00:58 +02:00
|
|
|
# candidate not in related to this poll
|
2012-07-10 00:47:00 +02:00
|
|
|
votes = None
|
2012-07-04 16:05:31 +02:00
|
|
|
vote_results_dict[candidate].append(votes)
|
2012-07-03 00:05:48 +02:00
|
|
|
return vote_results_dict
|
|
|
|
|
2012-06-23 10:27:58 +02:00
|
|
|
def get_agenda_title(self):
|
|
|
|
return self.name
|
2012-04-21 21:38:59 +02:00
|
|
|
|
2013-09-07 00:18:13 +02:00
|
|
|
def get_agenda_title_supplement(self):
|
|
|
|
return '(%s)' % _('Assignment')
|
|
|
|
|
2012-02-19 19:27:00 +01:00
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
class AssignmentVote(RESTModelMixin, BaseVote):
|
2012-07-13 11:16:06 +02:00
|
|
|
option = models.ForeignKey('AssignmentOption')
|
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
def get_root_rest_element(self):
|
|
|
|
"""
|
2015-01-24 16:35:50 +01:00
|
|
|
Returns the assignment to this instance which is the root REST element.
|
2015-01-17 14:25:05 +01:00
|
|
|
"""
|
|
|
|
return self.option.poll.assignment
|
|
|
|
|
2012-07-13 11:16:06 +02:00
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
class AssignmentOption(RESTModelMixin, BaseOption):
|
2012-07-13 11:16:06 +02:00
|
|
|
poll = models.ForeignKey('AssignmentPoll')
|
2014-10-11 14:34:49 +02:00
|
|
|
candidate = models.ForeignKey(User)
|
2012-07-13 11:16:06 +02:00
|
|
|
vote_class = AssignmentVote
|
2012-02-19 19:27:00 +01:00
|
|
|
|
2014-08-16 09:25:18 +02:00
|
|
|
def __str__(self):
|
|
|
|
return str(self.candidate)
|
2012-02-19 19:27:00 +01:00
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
def get_root_rest_element(self):
|
|
|
|
"""
|
2015-01-24 16:35:50 +01:00
|
|
|
Returns the assignment to this instance which is the root REST element.
|
2015-01-17 14:25:05 +01:00
|
|
|
"""
|
|
|
|
return self.poll.assignment
|
2012-02-19 19:27:00 +01:00
|
|
|
|
2015-01-17 14:25:05 +01:00
|
|
|
|
|
|
|
class AssignmentPoll(RESTModelMixin, SlideMixin, CollectDefaultVotesMixin,
|
2014-01-11 17:57:24 +01:00
|
|
|
PublishPollMixin, AbsoluteUrlMixin, BasePoll):
|
2013-10-17 11:34:54 +02:00
|
|
|
|
|
|
|
slide_callback_name = 'assignmentpoll'
|
2014-05-12 17:56:07 +02:00
|
|
|
"""Name of the callback for the slide system."""
|
2013-10-17 11:34:54 +02:00
|
|
|
|
2012-02-19 19:27:00 +01:00
|
|
|
option_class = AssignmentOption
|
|
|
|
assignment = models.ForeignKey(Assignment, related_name='poll_set')
|
2014-10-12 11:11:54 +02:00
|
|
|
yesnoabstain = models.BooleanField(default=False)
|
2014-01-11 17:07:47 +01:00
|
|
|
description = models.CharField(
|
|
|
|
max_length=79, null=True, blank=True,
|
|
|
|
verbose_name=ugettext_lazy("Comment on the ballot paper"))
|
2012-02-19 19:27:00 +01:00
|
|
|
|
2014-08-16 09:25:18 +02:00
|
|
|
def __str__(self):
|
2013-10-03 21:49:51 +02:00
|
|
|
return _("Ballot %d") % self.get_ballot()
|
|
|
|
|
2014-01-11 17:57:24 +01:00
|
|
|
def get_absolute_url(self, link='update'):
|
2013-10-17 11:34:54 +02:00
|
|
|
"""
|
|
|
|
Return an URL for the poll.
|
|
|
|
|
|
|
|
The keyargument 'link' can be 'update' or 'delete'.
|
|
|
|
"""
|
2014-01-11 17:57:24 +01:00
|
|
|
if link == 'update':
|
2013-10-17 11:34:54 +02:00
|
|
|
url = reverse('assignmentpoll_update', args=[str(self.pk)])
|
2014-01-11 17:57:24 +01:00
|
|
|
elif link == 'delete':
|
2013-10-17 11:34:54 +02:00
|
|
|
url = reverse('assignmentpoll_delete', args=[str(self.pk)])
|
2014-01-11 17:57:24 +01:00
|
|
|
else:
|
|
|
|
url = super(AssignmentPoll, self).get_absolute_url(link)
|
|
|
|
return url
|
2013-10-03 21:49:51 +02:00
|
|
|
|
2012-02-19 19:27:00 +01:00
|
|
|
def get_assignment(self):
|
|
|
|
return self.assignment
|
|
|
|
|
2012-06-18 09:48:27 +02:00
|
|
|
def get_vote_values(self):
|
2012-06-28 20:11:16 +02:00
|
|
|
if self.yesnoabstain:
|
2012-11-24 14:01:21 +01:00
|
|
|
return [ugettext_noop('Yes'), ugettext_noop('No'), ugettext_noop('Abstain')]
|
2012-06-18 09:48:27 +02:00
|
|
|
else:
|
2012-07-10 12:11:07 +02:00
|
|
|
return [ugettext_noop('Votes')]
|
2012-06-18 09:48:27 +02:00
|
|
|
|
2012-04-18 19:02:41 +02:00
|
|
|
def get_ballot(self):
|
2012-05-14 21:34:46 +02:00
|
|
|
return self.assignment.poll_set.filter(id__lte=self.id).count()
|
2014-01-11 17:07:47 +01:00
|
|
|
|
2014-04-10 20:18:22 +02:00
|
|
|
def get_percent_base_choice(self):
|
|
|
|
return config['assignment_poll_100_percent_base']
|
|
|
|
|
2014-01-11 17:07:47 +01:00
|
|
|
def append_pollform_fields(self, fields):
|
|
|
|
fields.append('description')
|
2014-04-09 21:00:32 +02:00
|
|
|
super(AssignmentPoll, self).append_pollform_fields(fields)
|
2013-10-17 11:34:54 +02:00
|
|
|
|
|
|
|
def get_slide_context(self, **context):
|
|
|
|
return super(AssignmentPoll, self).get_slide_context(poll=self)
|
2015-01-17 14:25:05 +01:00
|
|
|
|
|
|
|
def get_root_rest_element(self):
|
|
|
|
"""
|
2015-01-24 16:35:50 +01:00
|
|
|
Returns the assignment to this instance which is the root REST element.
|
2015-01-17 14:25:05 +01:00
|
|
|
"""
|
|
|
|
return self.assignment
|