publish assignment polls
This commit is contained in:
parent
a69ddffea5
commit
a25d980f92
@ -133,7 +133,7 @@ class Item(MPTTModel, SlideMixin):
|
||||
order_insertion_by = ['weight', 'title']
|
||||
|
||||
|
||||
register_slidemodel(Item, category=_('Agenda'))
|
||||
register_slidemodel(Item, category=_('Agenda'), model_name=_('Agenda Item'))
|
||||
|
||||
# TODO: put this in another file
|
||||
|
||||
|
@ -17,7 +17,7 @@ from participant.models import Profile
|
||||
|
||||
from projector.models import SlideMixin
|
||||
from projector.api import register_slidemodel
|
||||
from poll.models import BasePoll, CountInvalid, CountVotesCast, BaseOption
|
||||
from poll.models import BasePoll, CountInvalid, CountVotesCast, BaseOption, PublishPollMixin
|
||||
|
||||
|
||||
class Assignment(models.Model, SlideMixin):
|
||||
@ -122,7 +122,8 @@ class Assignment(models.Model, SlideMixin):
|
||||
('can_manage_assignment', "Can manage assignment"),
|
||||
)
|
||||
|
||||
register_slidemodel(Assignment)
|
||||
register_slidemodel(Assignment, category=_('Assignment'))
|
||||
|
||||
|
||||
class AssignmentOption(BaseOption):
|
||||
candidate = models.ForeignKey(Profile)
|
||||
@ -131,7 +132,7 @@ class AssignmentOption(BaseOption):
|
||||
return unicode(self.candidate)
|
||||
|
||||
|
||||
class AssignmentPoll(BasePoll, CountInvalid, CountVotesCast):
|
||||
class AssignmentPoll(BasePoll, CountInvalid, CountVotesCast, PublishPollMixin):
|
||||
option_class = AssignmentOption
|
||||
|
||||
assignment = models.ForeignKey(Assignment, related_name='poll_set')
|
||||
@ -143,3 +144,5 @@ class AssignmentPoll(BasePoll, CountInvalid, CountVotesCast):
|
||||
def append_pollform_fields(self, fields):
|
||||
CountInvalid.append_pollform_fields(self, fields)
|
||||
CountVotesCast.append_pollform_fields(self, fields)
|
||||
|
||||
register_slidemodel(AssignmentPoll, category=_('Assignment'))
|
||||
|
@ -192,6 +192,7 @@ def set_active(request, assignment_id):
|
||||
assignment.set_active()
|
||||
return redirect(reverse('assignment_view', args=[assignment_id]))
|
||||
|
||||
|
||||
@permission_required('assignment.can_manage_assignment')
|
||||
def gen_poll(request, assignment_id):
|
||||
poll = Assignment.objects.get(pk=assignment_id).gen_poll()
|
||||
@ -218,16 +219,17 @@ class ViewPoll(PollFormView):
|
||||
@permission_required('assignment.can_manage_assignment')
|
||||
def set_published(request, poll_id, published=True):
|
||||
try:
|
||||
poll = Poll.objects.get(pk=poll_id)
|
||||
poll = AssignmentPoll.objects.get(pk=poll_id)
|
||||
poll.set_published(published)
|
||||
if poll.published:
|
||||
messages.success(request, _("Poll successfully set to published.") )
|
||||
else:
|
||||
messages.success(request, _("Poll successfully set to unpublished.") )
|
||||
except Poll.DoesNotExist:
|
||||
except AssignmentPoll.DoesNotExist:
|
||||
messages.error(request, _('Poll ID %d does not exist.') % int(poll_id))
|
||||
return redirect(reverse('assignment_view', args=[poll.assignment.id]))
|
||||
|
||||
|
||||
@permission_required('assignment.can_manage_assignment')
|
||||
def delete_poll(request, poll_id):
|
||||
poll = Poll.objects.get(pk=poll_id)
|
||||
@ -240,6 +242,7 @@ def delete_poll(request, poll_id):
|
||||
del_confirm_form(request, poll, name=_("the %s. ballot") % ballot)
|
||||
return redirect(reverse('assignment_view', args=[assignment.id]))
|
||||
|
||||
|
||||
@permission_required('assignment.can_manage_assignment')
|
||||
def set_elected(request, assignment_id, profile_id, elected=True):
|
||||
assignment = Assignment.objects.get(pk=assignment_id)
|
||||
|
@ -67,6 +67,17 @@ class CountInvalid(models.Model):
|
||||
abstract = True
|
||||
|
||||
|
||||
class PublishPollMixin(models.Model):
|
||||
published = models.BooleanField(default=False)
|
||||
|
||||
def set_published(self, published):
|
||||
self.published = published
|
||||
self.save()
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class BasePoll(models.Model, SlideMixin):
|
||||
#TODO: It would be nice if this class wouldn't be a subclass from models.Model. But it is needet aslong
|
||||
# BaseOption has a foreignKey on BasePoll
|
||||
@ -135,8 +146,6 @@ class BasePoll(models.Model, SlideMixin):
|
||||
return data
|
||||
|
||||
|
||||
register_slidemodel(BasePoll)
|
||||
|
||||
def print_value(value):
|
||||
if value == -1:
|
||||
return _('majority')
|
||||
|
@ -35,13 +35,14 @@ def set_active_slide(sid):
|
||||
config["presentation"] = sid
|
||||
|
||||
|
||||
def register_slidemodel(model, category=None):
|
||||
def register_slidemodel(model, category=None, model_name=''):
|
||||
#TODO: Warn if there already is a slide with this prefix
|
||||
SLIDE[model.prefix] = Slide(
|
||||
model_slide=True,
|
||||
model=model,
|
||||
category=category,
|
||||
key=model.prefix,
|
||||
model_name=model_name,
|
||||
)
|
||||
|
||||
|
||||
|
@ -42,29 +42,21 @@ class SlideMixin(object):
|
||||
|
||||
|
||||
class Slide(object):
|
||||
def __init__(self, model_slide=False, func=None, model=None, category=None, key=None):
|
||||
def __init__(self, model_slide=False, func=None, model=None, category=None, key=None, model_name=''):
|
||||
"""
|
||||
model_slide: Boolean if the value is a Model.
|
||||
func: The function to call. Only if modelslide is False.
|
||||
model: The model. Only if modelslide is True.
|
||||
model_name: The name shown for the model.
|
||||
category: The category to show this Slide.
|
||||
key: the key in the slide object to find myself.
|
||||
"""
|
||||
self.model_slide = model_slide
|
||||
self.func = func
|
||||
self.model = model
|
||||
self.model_name = model_name
|
||||
self.category = category
|
||||
self.key = key
|
||||
|
||||
def get_items(self):
|
||||
return self.model.objects.all()
|
||||
|
||||
def get_dict(self):
|
||||
return {
|
||||
'key': self.key,
|
||||
'category': self.category,
|
||||
'model_slide': self.model_slide,
|
||||
'func': self.func,
|
||||
'model': self.model,
|
||||
'self': self,
|
||||
}
|
||||
|
@ -11,9 +11,12 @@
|
||||
<h2>{{ category }}</h2>
|
||||
{% for slide in slides %}
|
||||
{% if slide.model_slide %}
|
||||
<h3>{{ slide.model_name }}</h3>
|
||||
<ul>
|
||||
{% for item in slide.get_items %}
|
||||
<li><a href="{% url projector_activate_slide item.sid %}">{{ item }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<li><a href="{% url projector_activate_slide slide.key %}">{{ slide.key }}</a></li>
|
||||
{% endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user