publish assignment polls

This commit is contained in:
Oskar Hahn 2012-03-03 11:16:10 +01:00
parent a69ddffea5
commit a25d980f92
7 changed files with 31 additions and 20 deletions

View File

@ -133,7 +133,7 @@ class Item(MPTTModel, SlideMixin):
order_insertion_by = ['weight', 'title'] 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 # TODO: put this in another file

View File

@ -17,7 +17,7 @@ from participant.models import Profile
from projector.models import SlideMixin from projector.models import SlideMixin
from projector.api import register_slidemodel 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): class Assignment(models.Model, SlideMixin):
@ -122,7 +122,8 @@ class Assignment(models.Model, SlideMixin):
('can_manage_assignment', "Can manage assignment"), ('can_manage_assignment', "Can manage assignment"),
) )
register_slidemodel(Assignment) register_slidemodel(Assignment, category=_('Assignment'))
class AssignmentOption(BaseOption): class AssignmentOption(BaseOption):
candidate = models.ForeignKey(Profile) candidate = models.ForeignKey(Profile)
@ -131,7 +132,7 @@ class AssignmentOption(BaseOption):
return unicode(self.candidate) return unicode(self.candidate)
class AssignmentPoll(BasePoll, CountInvalid, CountVotesCast): class AssignmentPoll(BasePoll, CountInvalid, CountVotesCast, PublishPollMixin):
option_class = AssignmentOption option_class = AssignmentOption
assignment = models.ForeignKey(Assignment, related_name='poll_set') assignment = models.ForeignKey(Assignment, related_name='poll_set')
@ -143,3 +144,5 @@ class AssignmentPoll(BasePoll, CountInvalid, CountVotesCast):
def append_pollform_fields(self, fields): def append_pollform_fields(self, fields):
CountInvalid.append_pollform_fields(self, fields) CountInvalid.append_pollform_fields(self, fields)
CountVotesCast.append_pollform_fields(self, fields) CountVotesCast.append_pollform_fields(self, fields)
register_slidemodel(AssignmentPoll, category=_('Assignment'))

View File

@ -192,6 +192,7 @@ def set_active(request, assignment_id):
assignment.set_active() assignment.set_active()
return redirect(reverse('assignment_view', args=[assignment_id])) return redirect(reverse('assignment_view', args=[assignment_id]))
@permission_required('assignment.can_manage_assignment') @permission_required('assignment.can_manage_assignment')
def gen_poll(request, assignment_id): def gen_poll(request, assignment_id):
poll = Assignment.objects.get(pk=assignment_id).gen_poll() poll = Assignment.objects.get(pk=assignment_id).gen_poll()
@ -218,16 +219,17 @@ class ViewPoll(PollFormView):
@permission_required('assignment.can_manage_assignment') @permission_required('assignment.can_manage_assignment')
def set_published(request, poll_id, published=True): def set_published(request, poll_id, published=True):
try: try:
poll = Poll.objects.get(pk=poll_id) poll = AssignmentPoll.objects.get(pk=poll_id)
poll.set_published(published) poll.set_published(published)
if poll.published: if poll.published:
messages.success(request, _("Poll successfully set to published.") ) messages.success(request, _("Poll successfully set to published.") )
else: else:
messages.success(request, _("Poll successfully set to unpublished.") ) 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)) messages.error(request, _('Poll ID %d does not exist.') % int(poll_id))
return redirect(reverse('assignment_view', args=[poll.assignment.id])) return redirect(reverse('assignment_view', args=[poll.assignment.id]))
@permission_required('assignment.can_manage_assignment') @permission_required('assignment.can_manage_assignment')
def delete_poll(request, poll_id): def delete_poll(request, poll_id):
poll = Poll.objects.get(pk=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) del_confirm_form(request, poll, name=_("the %s. ballot") % ballot)
return redirect(reverse('assignment_view', args=[assignment.id])) return redirect(reverse('assignment_view', args=[assignment.id]))
@permission_required('assignment.can_manage_assignment') @permission_required('assignment.can_manage_assignment')
def set_elected(request, assignment_id, profile_id, elected=True): def set_elected(request, assignment_id, profile_id, elected=True):
assignment = Assignment.objects.get(pk=assignment_id) assignment = Assignment.objects.get(pk=assignment_id)

View File

@ -67,6 +67,17 @@ class CountInvalid(models.Model):
abstract = True 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): 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 #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 # BaseOption has a foreignKey on BasePoll
@ -135,8 +146,6 @@ class BasePoll(models.Model, SlideMixin):
return data return data
register_slidemodel(BasePoll)
def print_value(value): def print_value(value):
if value == -1: if value == -1:
return _('majority') return _('majority')

View File

@ -35,13 +35,14 @@ def set_active_slide(sid):
config["presentation"] = 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 #TODO: Warn if there already is a slide with this prefix
SLIDE[model.prefix] = Slide( SLIDE[model.prefix] = Slide(
model_slide=True, model_slide=True,
model=model, model=model,
category=category, category=category,
key=model.prefix, key=model.prefix,
model_name=model_name,
) )

View File

@ -42,29 +42,21 @@ class SlideMixin(object):
class Slide(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. model_slide: Boolean if the value is a Model.
func: The function to call. Only if modelslide is False. func: The function to call. Only if modelslide is False.
model: The model. Only if modelslide is True. model: The model. Only if modelslide is True.
model_name: The name shown for the model.
category: The category to show this Slide. category: The category to show this Slide.
key: the key in the slide object to find myself. key: the key in the slide object to find myself.
""" """
self.model_slide = model_slide self.model_slide = model_slide
self.func = func self.func = func
self.model = model self.model = model
self.model_name = model_name
self.category = category self.category = category
self.key = key self.key = key
def get_items(self): def get_items(self):
return self.model.objects.all() 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,
}

View File

@ -11,9 +11,12 @@
<h2>{{ category }}</h2> <h2>{{ category }}</h2>
{% for slide in slides %} {% for slide in slides %}
{% if slide.model_slide %} {% if slide.model_slide %}
<h3>{{ slide.model_name }}</h3>
<ul>
{% for item in slide.get_items %} {% for item in slide.get_items %}
<li><a href="{% url projector_activate_slide item.sid %}">{{ item }}</a></li> <li><a href="{% url projector_activate_slide item.sid %}">{{ item }}</a></li>
{% endfor %} {% endfor %}
</ul>
{% else %} {% else %}
<li><a href="{% url projector_activate_slide slide.key %}">{{ slide.key }}</a></li> <li><a href="{% url projector_activate_slide slide.key %}">{{ slide.key }}</a></li>
{% endif %} {% endif %}