diff --git a/templates/polls/poll_list.html b/templates/polls/poll_list.html index c9ac82c9a..1d013434c 100644 --- a/templates/polls/poll_list.html +++ b/templates/polls/poll_list.html @@ -38,7 +38,7 @@

{% for obj in object_list %} - + {% get_value obj 'category' %} diff --git a/ureport/polls/views.py b/ureport/polls/views.py index 85f93458b..87cc5d303 100644 --- a/ureport/polls/views.py +++ b/ureport/polls/views.py @@ -181,6 +181,15 @@ class Meta: fields = ("id",) +class ActivePollMixin(OrgObjPermsMixin): + def get_queryset(self): + queryset = super(ActivePollMixin, self).get_queryset() + if not self.request.user.is_superuser: + queryset = queryset.filter(is_active=True) + + return queryset + + class PollCRUDL(SmartCRUDL): model = Poll actions = ( @@ -195,7 +204,7 @@ class PollCRUDL(SmartCRUDL): "poll_flow", ) - class PollDate(OrgObjPermsMixin, SmartUpdateView): + class PollDate(ActivePollMixin, SmartUpdateView): form_class = PollFlowForm title = _("Adjust poll date") success_url = "id@polls.poll_questions" @@ -208,7 +217,7 @@ def get_form_kwargs(self): kwargs["backend"] = self.object.backend return kwargs - class PollFlow(OrgObjPermsMixin, SmartUpdateView): + class PollFlow(ActivePollMixin, SmartUpdateView): form_class = PollFlowForm title = _("Configure flow") success_url = "id@polls.poll_poll_date" @@ -337,7 +346,7 @@ def post_save(self, obj): Poll.find_main_poll(org) return obj - class Images(OrgObjPermsMixin, SmartUpdateView): + class Images(ActivePollMixin, SmartUpdateView): success_url = "id@polls.poll_responses" title = _("Poll Images") success_message = _("Now enter any responses you'd like to feature. (if any)") @@ -391,7 +400,7 @@ def post_save(self, obj): return obj - class Responses(OrgObjPermsMixin, SmartUpdateView): + class Responses(ActivePollMixin, SmartUpdateView): form_class = PollResponseForm title = _("Poll Response") success_url = "@polls.poll_list" @@ -403,7 +412,7 @@ def get_form_kwargs(self): kwargs["org"] = self.request.org return kwargs - class Questions(OrgObjPermsMixin, SmartUpdateView): + class Questions(ActivePollMixin, SmartUpdateView): success_url = "id@polls.poll_images" title = _("Poll Questions") form_class = QuestionForm @@ -643,6 +652,9 @@ class List(OrgPermsMixin, SmartListView): def get_queryset(self): queryset = super(PollCRUDL.List, self).get_queryset().filter(org=self.request.org) + if not self.request.user.is_superuser: + queryset = queryset.filter(is_active=True) + return queryset def get_context_data(self, **kwargs): @@ -706,7 +718,7 @@ def lookup_field_link(self, context, field, obj): else: return super(PollCRUDL.List, self).lookup_field_link(context, field, obj) - class Update(OrgObjPermsMixin, SmartUpdateView): + class Update(ActivePollMixin, SmartUpdateView): form_class = PollForm fields = ("is_active", "is_featured", "title", "category", "category_image", "poll_tags") success_url = "id@polls.poll_poll_flow"