-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60b1664
commit f36a050
Showing
4 changed files
with
49 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class RoleFilterChoices(models.TextChoices): | ||
record_manager = "record_manager", _("Record manager") | ||
main_reviewer = "main_reviewer", _("Main reviewer") | ||
co_reviewer = "co_reviewer", _("Co-reviewer") | ||
archivist = "archivist", _("Archivist") |
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,34 @@ | ||
from django.db.models import QuerySet | ||
|
||
from django_filters import ChoiceFilter, FilterSet | ||
|
||
from ..models import User | ||
from .constants import RoleFilterChoices | ||
|
||
|
||
class UsersFilterset(FilterSet): | ||
role = ChoiceFilter( | ||
field_name="role", | ||
method="filter_role", | ||
help_text="Filter on the user's role.", | ||
choices=RoleFilterChoices.choices, | ||
) | ||
|
||
class Meta: | ||
model = User | ||
fields = ("role",) | ||
|
||
def filter_role( | ||
self, queryset: QuerySet[User], name: str, value: str | ||
) -> QuerySet[User]: | ||
match value: | ||
case RoleFilterChoices.record_manager: | ||
return User.objects.record_managers() | ||
case RoleFilterChoices.main_reviewer: | ||
return User.objects.main_reviewers() | ||
case RoleFilterChoices.co_reviewer: | ||
return User.objects.co_reviewers() | ||
case RoleFilterChoices.archivist: | ||
return User.objects.archivists() | ||
case _: | ||
return queryset |
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