-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
budgeting//moderationtasks: add moderation task filter to proposal api
- Loading branch information
rine
committed
Nov 18, 2022
1 parent
0c8b097
commit b5ad2b4
Showing
2 changed files
with
51 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from rest_framework.filters import BaseFilterBackend | ||
|
||
from meinberlin.apps.moderationtasks.models import ModerationTask | ||
|
||
|
||
class ModerationTaskFilterBackend(BaseFilterBackend): | ||
"""Filter out proposals that have the moderation tasks completed.""" | ||
|
||
def filter_queryset(self, request, queryset, view): | ||
|
||
if 'open_task' in request.GET: | ||
task_id = request.GET['open_task'] | ||
try: | ||
moderation_task = ModerationTask.objects.get(id=task_id) | ||
proposals_completed = getattr( | ||
moderation_task, | ||
'{app_label}_{model}_completed'.format( | ||
app_label=queryset.model._meta.app_label, | ||
model=queryset.model.__name__.lower())).all() | ||
return queryset.exclude(id__in=proposals_completed) | ||
except ModerationTask.DoesNotExist: | ||
pass | ||
return queryset |