Skip to content

Commit

Permalink
Add Active poll mixin to filter poll by is_active
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Oct 25, 2023
1 parent a35d807 commit 33156d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion templates/polls/poll_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h2 class="is-size-2 has-text-weight-bold">
</thead>
<tbody>
{% for obj in object_list %}
<tr class="{% cycle 'row2' 'row1' %} {% if not obj.published and obj|is_smartobject %}inactive{% endif %}">
<tr class="{% cycle 'row2' 'row1' %} {% if not obj.published or not obj.is_active and obj|is_smartobject %}inactive{% endif %}">
<td style="max-width: 500px;min-width: 300px;">
<b class="detail-link">
{% get_value obj 'category' %}
Expand Down
24 changes: 18 additions & 6 deletions ureport/polls/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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 = "[email protected]_questions"
Expand All @@ -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 = "[email protected]_poll_date"
Expand Down Expand Up @@ -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 = "[email protected]_responses"
title = _("Poll Images")
success_message = _("Now enter any responses you'd like to feature. (if any)")
Expand Down Expand Up @@ -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"
Expand All @@ -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 = "[email protected]_images"
title = _("Poll Questions")
form_class = QuestionForm
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 = "[email protected]_poll_flow"
Expand Down

0 comments on commit 33156d4

Please sign in to comment.