diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index 65616a8dc..b924c4d20 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -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 diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 3066a1828..3f0c8732e 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -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')) diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index 3a576da55..c82da4f4c 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -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) diff --git a/openslides/poll/models.py b/openslides/poll/models.py index e8c7878cd..02ec12e9b 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -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') diff --git a/openslides/projector/api.py b/openslides/projector/api.py index 51004d1c1..7a8fd024c 100644 --- a/openslides/projector/api.py +++ b/openslides/projector/api.py @@ -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, ) diff --git a/openslides/projector/models.py b/openslides/projector/models.py index b1c7f37fe..032e2a155 100644 --- a/openslides/projector/models.py +++ b/openslides/projector/models.py @@ -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, - } diff --git a/openslides/projector/templates/projector/settings.html b/openslides/projector/templates/projector/settings.html index 83d8a5dc0..eb472bffa 100644 --- a/openslides/projector/templates/projector/settings.html +++ b/openslides/projector/templates/projector/settings.html @@ -11,9 +11,12 @@