Skip to content

Commit

Permalink
added name and is_inactive parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewakiv committed Dec 19, 2024
1 parent cfb63a8 commit 624d6e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
17 changes: 14 additions & 3 deletions BackEnd/administration/filters.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
from django.db.models import Q
from django_filters import filters
from django_filters.rest_framework import FilterSet


class UsersFilter(FilterSet):
"""
Filters
/?id= , /?surname=, /?email= , /?is_active= , /?is_staff=,
/?is_superuser=, /?is_deleted=True or False, /?company_name=, /?registration_date=,
/?id= , ,/?name= /?surname=, /?email= , /?is_active= , /?is_staff=,
/?is_superuser=, /?is_deleted=True or False, /?company_name=,
/?registration_date=,
Ordering sample
/?ordering=id asc or /?ordering=-id desc
"""

id = filters.NumberFilter(lookup_expr="contains")
name = filters.CharFilter(lookup_expr="icontains")
surname = filters.CharFilter(lookup_expr="icontains")
email = filters.CharFilter(lookup_expr="icontains")
is_active = filters.BooleanFilter()
is_inactive = filters.BooleanFilter(method="is_inactive_filter")
is_staff = filters.BooleanFilter()
is_superuser = filters.BooleanFilter()
is_deleted = filters.BooleanFilter(method="is_deleted_filter")
Expand All @@ -25,6 +28,14 @@ class UsersFilter(FilterSet):
field_name="profile__created_at", lookup_expr="icontains"
)

def is_inactive_filter(self, queryset, name, value):
if value:
queryset = queryset.filter(
~Q(email__startswith="is_deleted_"),
is_active=False
)
return queryset

def is_deleted_filter(self, queryset, name, value):
if value:
queryset = queryset.filter(email__startswith="is_deleted_")
Expand Down
1 change: 1 addition & 0 deletions BackEnd/administration/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def get_status(self, obj) -> dict:
"is_staff": obj.is_staff,
"is_superuser": obj.is_superuser,
"is_deleted": obj.email.startswith("is_deleted_"),
"is_inactive": not obj.is_active and not obj.email.startswith("is_deleted_"),
}
return data

Expand Down
6 changes: 2 additions & 4 deletions BackEnd/administration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,17 @@
from .serializers import FeedbackSerializer
from utils.administration.send_email_feedback import send_email_feedback

from django_filters.rest_framework import DjangoFilterBackend
from .filters import UsersFilter, CategoriesFilter
from utils.administration.send_email_notification import send_email_to_user
from .filters import UsersFilter


class UsersListView(ListAPIView):
"""
View to list users with optional filtering and ordering.
### Query Parameters:
- **id** / **surname** / **email** / **is_active** / **is_staff** / **is_superuser** / **is_deleted**
- **company_name** / **registration_date**
- **name** / **surname** /**email** / **is_active** / **is_staff** /
- **is_superuser** / **is_deleted**/ **company_name** / **registration_date**
### Ordering:
- Use the `ordering` parameter to sort the results.
Expand Down

0 comments on commit 624d6e8

Please sign in to comment.