-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Active poll mixin to filter poll by is_active
- Loading branch information
Showing
2 changed files
with
19 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = "[email protected]_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 = "[email protected]_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 = "[email protected]_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 = "[email protected]_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 = "[email protected]_poll_flow" | ||
|