From 7a9e85f5e52b2b757d7ed64aca018245575f1ef5 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Thu, 5 Dec 2024 17:41:40 +0200 Subject: [PATCH 01/16] add categori api --- BackEnd/administration/filters.py | 9 +++++++ BackEnd/administration/serializers.py | 16 +++++++++++ BackEnd/administration/urls.py | 12 +++++++++ BackEnd/administration/views.py | 39 +++++++++++++++++++++++++-- 4 files changed, 74 insertions(+), 2 deletions(-) diff --git a/BackEnd/administration/filters.py b/BackEnd/administration/filters.py index 2a522ddc5..217832eb8 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -43,3 +43,12 @@ def filter_is_deleted(self, queryset, name, value): ("profile__created_at", "registration_date"), ) ) + + +class CategoriFilter(FilterSet): + """ + manage categori filter + """ + + id = filters.CharFilter(lookup_expr="icontains") + name = filters.CharFilter(lookup_expr="icontains") diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 24cda9beb..8eb3d8937 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -5,6 +5,7 @@ from profiles.models import ( Profile, Region, + Category, ) from utils.administration.create_password import generate_password from utils.administration.send_email import send_email_about_admin_registration @@ -213,3 +214,18 @@ class FeedbackSerializer(serializers.Serializer): required=True, error_messages={"required": "Please select a category."}, ) + + +class ManageCategoriesSerializer(serializers.ModelSerializer): + class Meta: + model = Category + fields = ( + "id", + "name", + ) + + +class CategorieDetailSerializer(serializers.ModelSerializer): + class Meta: + model = Category + fields = ("name",) diff --git a/BackEnd/administration/urls.py b/BackEnd/administration/urls.py index d860830c3..cd5f9049c 100644 --- a/BackEnd/administration/urls.py +++ b/BackEnd/administration/urls.py @@ -10,6 +10,8 @@ ModerationEmailView, FeedbackView, CreateAdminUserView, + ManageCategoriesView, + CategoriesDetailView, ) app_name = "administration" @@ -28,4 +30,14 @@ path("contacts/", ContactsView.as_view(), name="contacts"), path("feedback/", FeedbackView.as_view(), name="feedback"), path("admin_create/", CreateAdminUserView.as_view(), name="admin-create"), + path( + "manage_categories/", + ManageCategoriesView.as_view(), + name="manage-categories", + ), + path( + "manage_categories//", + CategoriesDetailView.as_view(), + name="categories_detail", + ), ] diff --git a/BackEnd/administration/views.py b/BackEnd/administration/views.py index 7f137a5bc..04b0b125c 100644 --- a/BackEnd/administration/views.py +++ b/BackEnd/administration/views.py @@ -8,6 +8,7 @@ from rest_framework.generics import ( ListAPIView, + ListCreateAPIView, RetrieveUpdateDestroyAPIView, RetrieveUpdateAPIView, CreateAPIView, @@ -22,17 +23,19 @@ AdminUserDetailSerializer, AutoModerationHoursSerializer, ModerationEmailSerializer, + ManageCategoriesSerializer, + CategorieDetailSerializer, ) from administration.pagination import ListPagination from administration.models import AutoModeration, ModerationEmail from authentication.models import CustomUser -from profiles.models import Profile +from profiles.models import Profile, Category from .permissions import IsStaffUser, IsStaffUserOrReadOnly, IsSuperUser 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 +from .filters import UsersFilter, CategoriFilter class UsersListView(ListAPIView): @@ -199,3 +202,35 @@ def perform_create(self, serializer): category = serializer.validated_data["category"] send_email_feedback(email, message, category) + + +class ManageCategoriesView(ListCreateAPIView): + """ + Manage categories + ### Query Parameters: + - **id** / **name** + + ### Ordering: + - Use the `ordering` parameter to sort the results. + - Example: `/manage_categori/?ordering=id` (ascending by ID) or `/manage_categori/?ordering=-id` (descending by ID). + + ### Filters: + - Filters are applied using `DjangoFilterBackend`. All the above query parameters are supported for filtering. + """ + + permission_classes = [IsStaffUser] + serializer_class = ManageCategoriesSerializer + filter_backends = [DjangoFilterBackend] + filterset_class = CategoriFilter + pagination_class = ListPagination + queryset = Category.objects.all().order_by("id") + + +class CategoriesDetailView(RetrieveUpdateAPIView): + """ + Modify activity category + """ + + permission_classes = [IsStaffUser] + serializer_class = CategorieDetailSerializer + queryset = Category.objects.all() From e20229f8524d5cd952d1ae4a49b4e7005c365a35 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Thu, 5 Dec 2024 18:08:16 +0200 Subject: [PATCH 02/16] api name categori --- BackEnd/administration/urls.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BackEnd/administration/urls.py b/BackEnd/administration/urls.py index cd5f9049c..51f743bca 100644 --- a/BackEnd/administration/urls.py +++ b/BackEnd/administration/urls.py @@ -31,12 +31,12 @@ path("feedback/", FeedbackView.as_view(), name="feedback"), path("admin_create/", CreateAdminUserView.as_view(), name="admin-create"), path( - "manage_categories/", + "categories/", ManageCategoriesView.as_view(), - name="manage-categories", + name="categories", ), path( - "manage_categories//", + "categories//", CategoriesDetailView.as_view(), name="categories_detail", ), From b75433e64d46cb619d62dbb2904bdf2b64333fe1 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Sun, 8 Dec 2024 17:00:46 +0200 Subject: [PATCH 03/16] start test v1.0.0 --- BackEnd/administration/factories.py | 9 ++- BackEnd/administration/filters.py | 8 ++- BackEnd/administration/serializers.py | 8 ++- .../tests/test_admin_category.py | 68 +++++++++++++++++++ BackEnd/administration/urls.py | 6 +- BackEnd/administration/views.py | 14 ++-- 6 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 BackEnd/administration/tests/test_admin_category.py diff --git a/BackEnd/administration/factories.py b/BackEnd/administration/factories.py index 251ec104b..ca1c27235 100644 --- a/BackEnd/administration/factories.py +++ b/BackEnd/administration/factories.py @@ -1,7 +1,7 @@ import factory.django from authentication.models import CustomUser -from profiles.models import Profile +from profiles.models import Profile, Category class AdminUserFactory(factory.django.DjangoModelFactory): @@ -39,3 +39,10 @@ class Meta: official_name = "Test official name" startup_idea = "Test startup idea" is_deleted = False + + +class AdminCategoryFactory(factory.django.DjangoModelFactory): + class Meta: + model = Category + + name = factory.Sequence(lambda n: f"category {n + 1}") \ No newline at end of file diff --git a/BackEnd/administration/filters.py b/BackEnd/administration/filters.py index 217832eb8..b1e8ccfee 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -45,10 +45,16 @@ def filter_is_deleted(self, queryset, name, value): ) -class CategoriFilter(FilterSet): +class CategoriesFilter(FilterSet): """ manage categori filter """ id = filters.CharFilter(lookup_expr="icontains") name = filters.CharFilter(lookup_expr="icontains") + ordering = filters.OrderingFilter( + fields=( + ("id", "id"), + ("name", "name"), + ) + ) \ No newline at end of file diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 8eb3d8937..ed6a5a55f 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -223,9 +223,13 @@ class Meta: "id", "name", ) + + def validate_name(self, value): + if Category.objects.filter(name=value).exists(): + raise serializers.ValidationError("Category with this name already exists.") + return value - -class CategorieDetailSerializer(serializers.ModelSerializer): +class CategoryDetailSerializer(serializers.ModelSerializer): class Meta: model = Category fields = ("name",) diff --git a/BackEnd/administration/tests/test_admin_category.py b/BackEnd/administration/tests/test_admin_category.py new file mode 100644 index 000000000..fec4c710f --- /dev/null +++ b/BackEnd/administration/tests/test_admin_category.py @@ -0,0 +1,68 @@ +from rest_framework import status +from rest_framework.test import APITestCase + +from administration.factories import AdminCategoryFactory, AdminUserFactory +from utils.dump_response import dump # noqa + + + +class TestAdminCategoryAPIUserNotStaff(APITestCase): + def setUp(self): + self.user = AdminUserFactory( + is_staff=False, + is_active=True, + ) + self.name = AdminCategoryFactory() + + def test_get_category_users_not_staff(self): + self.client.force_authenticate(self.user) + response = self.client.get(path="/api/admin/categories/") + self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) + + def test_get_category_id_users_not_staff(self): + self.client.force_authenticate(self.user) + response = self.client.get(path="/api/admin/categories/1/") + self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) + + +class TestAdminCategoryAPIUserStaff(APITestCase): + def setUp(self): + self.user = AdminUserFactory( + is_staff=True, + is_active=True, + ) + self.name = AdminCategoryFactory.create_batch(2) + + def test_get_categoryes_users_staff(self): + self.client.force_authenticate(self.user) + response = self.client.get(path="/api/admin/categories/") + data = [ + { + "id":3 , + "name":"category 3", + }, + { + "id":4 , + "name":"category 4", + }, + ] + print( [dict(item) for item in response.data["results"]]) + self.assertEqual(data, [dict(item) for item in response.data["results"]]) + self.assertEqual(status.HTTP_200_OK, response.status_code) + + # def test_get_categoryes_id_users_staff(self): + # self.client.force_authenticate(self.user) + # response = self.client.get(path="/api/admin/categories/1/") + # data = [ + # { + # "id":2 , + # "name":"categori", + # }, + # { + # "id":2 , + # "name":"categori", + # }, + # ] + # print(response) + # self.assertEqual(status.HTTP_200_OK, response.status_code) + # self.assertEqual(data, response.data["results"]) \ No newline at end of file diff --git a/BackEnd/administration/urls.py b/BackEnd/administration/urls.py index 51f743bca..23a92d279 100644 --- a/BackEnd/administration/urls.py +++ b/BackEnd/administration/urls.py @@ -11,7 +11,7 @@ FeedbackView, CreateAdminUserView, ManageCategoriesView, - CategoriesDetailView, + CategoryDetailView, ) app_name = "administration" @@ -37,7 +37,7 @@ ), path( "categories//", - CategoriesDetailView.as_view(), - name="categories_detail", + CategoryDetailView.as_view(), + name="category_detail", ), ] diff --git a/BackEnd/administration/views.py b/BackEnd/administration/views.py index 04b0b125c..6d3ab213c 100644 --- a/BackEnd/administration/views.py +++ b/BackEnd/administration/views.py @@ -24,7 +24,7 @@ AutoModerationHoursSerializer, ModerationEmailSerializer, ManageCategoriesSerializer, - CategorieDetailSerializer, + CategoryDetailSerializer, ) from administration.pagination import ListPagination from administration.models import AutoModeration, ModerationEmail @@ -35,7 +35,7 @@ from utils.administration.send_email_feedback import send_email_feedback from django_filters.rest_framework import DjangoFilterBackend -from .filters import UsersFilter, CategoriFilter +from .filters import UsersFilter, CategoriesFilter class UsersListView(ListAPIView): @@ -221,16 +221,16 @@ class ManageCategoriesView(ListCreateAPIView): permission_classes = [IsStaffUser] serializer_class = ManageCategoriesSerializer filter_backends = [DjangoFilterBackend] - filterset_class = CategoriFilter + filterset_class = CategoriesFilter pagination_class = ListPagination - queryset = Category.objects.all().order_by("id") + queryset = Category.objects.all().order_by("id").select_related() -class CategoriesDetailView(RetrieveUpdateAPIView): +class CategoryDetailView(RetrieveUpdateAPIView): """ Modify activity category """ permission_classes = [IsStaffUser] - serializer_class = CategorieDetailSerializer - queryset = Category.objects.all() + serializer_class = CategoryDetailSerializer + queryset = Category.objects.all().select_related() From fa2793632755f6da26e6c47de5efbda69bea0774 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Sun, 8 Dec 2024 17:02:17 +0200 Subject: [PATCH 04/16] format black --- BackEnd/administration/factories.py | 2 +- BackEnd/administration/filters.py | 4 ++-- BackEnd/administration/serializers.py | 9 +++++--- .../tests/test_admin_category.py | 21 ++++++++++--------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/BackEnd/administration/factories.py b/BackEnd/administration/factories.py index ca1c27235..c11da7d34 100644 --- a/BackEnd/administration/factories.py +++ b/BackEnd/administration/factories.py @@ -45,4 +45,4 @@ class AdminCategoryFactory(factory.django.DjangoModelFactory): class Meta: model = Category - name = factory.Sequence(lambda n: f"category {n + 1}") \ No newline at end of file + name = factory.Sequence(lambda n: f"category {n + 1}") diff --git a/BackEnd/administration/filters.py b/BackEnd/administration/filters.py index b1e8ccfee..1346318f7 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -56,5 +56,5 @@ class CategoriesFilter(FilterSet): fields=( ("id", "id"), ("name", "name"), - ) - ) \ No newline at end of file + ) + ) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index ed6a5a55f..87adbcc32 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -223,11 +223,14 @@ class Meta: "id", "name", ) - + def validate_name(self, value): if Category.objects.filter(name=value).exists(): - raise serializers.ValidationError("Category with this name already exists.") - return value + raise serializers.ValidationError( + "Category with this name already exists." + ) + return value + class CategoryDetailSerializer(serializers.ModelSerializer): class Meta: diff --git a/BackEnd/administration/tests/test_admin_category.py b/BackEnd/administration/tests/test_admin_category.py index fec4c710f..be44c4749 100644 --- a/BackEnd/administration/tests/test_admin_category.py +++ b/BackEnd/administration/tests/test_admin_category.py @@ -3,7 +3,6 @@ from administration.factories import AdminCategoryFactory, AdminUserFactory from utils.dump_response import dump # noqa - class TestAdminCategoryAPIUserNotStaff(APITestCase): @@ -22,7 +21,7 @@ def test_get_category_users_not_staff(self): def test_get_category_id_users_not_staff(self): self.client.force_authenticate(self.user) response = self.client.get(path="/api/admin/categories/1/") - self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) + self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) class TestAdminCategoryAPIUserStaff(APITestCase): @@ -38,16 +37,18 @@ def test_get_categoryes_users_staff(self): response = self.client.get(path="/api/admin/categories/") data = [ { - "id":3 , - "name":"category 3", + "id": 3, + "name": "category 3", }, { - "id":4 , - "name":"category 4", + "id": 4, + "name": "category 4", }, ] - print( [dict(item) for item in response.data["results"]]) - self.assertEqual(data, [dict(item) for item in response.data["results"]]) + print([dict(item) for item in response.data["results"]]) + self.assertEqual( + data, [dict(item) for item in response.data["results"]] + ) self.assertEqual(status.HTTP_200_OK, response.status_code) # def test_get_categoryes_id_users_staff(self): @@ -64,5 +65,5 @@ def test_get_categoryes_users_staff(self): # }, # ] # print(response) - # self.assertEqual(status.HTTP_200_OK, response.status_code) - # self.assertEqual(data, response.data["results"]) \ No newline at end of file + # self.assertEqual(status.HTTP_200_OK, response.status_code) + # self.assertEqual(data, response.data["results"]) From d96907ef52b8ff6a91af4b1a0bc69a3806d2a96f Mon Sep 17 00:00:00 2001 From: romanmyko Date: Wed, 11 Dec 2024 21:38:59 +0200 Subject: [PATCH 05/16] test v1.0.1 --- BackEnd/administration/factories.py | 1 + .../tests/test_admin_category.py | 68 ++++++++++++------- BackEnd/administration/views.py | 4 +- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/BackEnd/administration/factories.py b/BackEnd/administration/factories.py index c11da7d34..78c8b336b 100644 --- a/BackEnd/administration/factories.py +++ b/BackEnd/administration/factories.py @@ -44,5 +44,6 @@ class Meta: class AdminCategoryFactory(factory.django.DjangoModelFactory): class Meta: model = Category + django_get_or_create = ("name",) name = factory.Sequence(lambda n: f"category {n + 1}") diff --git a/BackEnd/administration/tests/test_admin_category.py b/BackEnd/administration/tests/test_admin_category.py index be44c4749..2936d4b42 100644 --- a/BackEnd/administration/tests/test_admin_category.py +++ b/BackEnd/administration/tests/test_admin_category.py @@ -1,8 +1,9 @@ from rest_framework import status from rest_framework.test import APITestCase -from administration.factories import AdminCategoryFactory, AdminUserFactory +from administration.factories import AdminCategoryFactory, AdminUserFactory, AdminProfileFactory from utils.dump_response import dump # noqa +from profiles.models import Profile, Category, CustomUser class TestAdminCategoryAPIUserNotStaff(APITestCase): @@ -13,6 +14,16 @@ def setUp(self): ) self.name = AdminCategoryFactory() + def tearDown(self): + super().tearDown() + Category.objects.all().delete() + Profile.objects.all().delete() + CustomUser.objects.all().delete() + AdminUserFactory.reset_sequence(0) + AdminCategoryFactory.reset_sequence(0) + AdminProfileFactory.reset_sequence(0) + + def test_get_category_users_not_staff(self): self.client.force_authenticate(self.user) response = self.client.get(path="/api/admin/categories/") @@ -22,7 +33,7 @@ def test_get_category_id_users_not_staff(self): self.client.force_authenticate(self.user) response = self.client.get(path="/api/admin/categories/1/") self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) - + class TestAdminCategoryAPIUserStaff(APITestCase): def setUp(self): @@ -32,38 +43,47 @@ def setUp(self): ) self.name = AdminCategoryFactory.create_batch(2) + def tearDown(self): + super().tearDown() + Category.objects.all().delete() + Profile.objects.all().delete() + CustomUser.objects.all().delete() + AdminUserFactory.reset_sequence(0) + AdminCategoryFactory.reset_sequence(0) + AdminProfileFactory.reset_sequence(0) + + def test_get_categoryes_users_staff(self): self.client.force_authenticate(self.user) response = self.client.get(path="/api/admin/categories/") data = [ { - "id": 3, - "name": "category 3", + "id": 5, + "name": "category 1", }, { - "id": 4, - "name": "category 4", + "id": 6, + "name": "category 2", }, ] - print([dict(item) for item in response.data["results"]]) + self.assertEqual( - data, [dict(item) for item in response.data["results"]] + data, response.json()["results"] ) self.assertEqual(status.HTTP_200_OK, response.status_code) - # def test_get_categoryes_id_users_staff(self): - # self.client.force_authenticate(self.user) - # response = self.client.get(path="/api/admin/categories/1/") - # data = [ - # { - # "id":2 , - # "name":"categori", - # }, - # { - # "id":2 , - # "name":"categori", - # }, - # ] - # print(response) - # self.assertEqual(status.HTTP_200_OK, response.status_code) - # self.assertEqual(data, response.data["results"]) + def test_get_categoryes_id_users_staff(self): + self.client.force_authenticate(self.user) + response = self.client.get(path="/api/admin/categories/3/") + data = {"name":"category 1"} + self.assertEqual(status.HTTP_200_OK, response.status_code) + self.assertEqual(data, response.json()) + + + def test_post_new_categoryes_users_staff(self): + self.client.force_authenticate(self.user) + data = {"name":"category 11"} + response = self.client.post(path="/api/admin/categories/",data=data) + self.assertEqual(status.HTTP_201_CREATED, response.status_code) + self.assertEqual(response.json()["name"], data["name"]) + self.assertIn("id", response.json()) diff --git a/BackEnd/administration/views.py b/BackEnd/administration/views.py index 6d3ab213c..830c2ec87 100644 --- a/BackEnd/administration/views.py +++ b/BackEnd/administration/views.py @@ -223,7 +223,7 @@ class ManageCategoriesView(ListCreateAPIView): filter_backends = [DjangoFilterBackend] filterset_class = CategoriesFilter pagination_class = ListPagination - queryset = Category.objects.all().order_by("id").select_related() + queryset = Category.objects.all().order_by("id") class CategoryDetailView(RetrieveUpdateAPIView): @@ -233,4 +233,4 @@ class CategoryDetailView(RetrieveUpdateAPIView): permission_classes = [IsStaffUser] serializer_class = CategoryDetailSerializer - queryset = Category.objects.all().select_related() + queryset = Category.objects.all() From ac3afb4067afeeb57c7659b469d0f1d49ced8644 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Wed, 11 Dec 2024 21:41:22 +0200 Subject: [PATCH 06/16] format --- .../tests/test_admin_category.py | 25 +++++++++---------- BackEnd/administration/views.py | 2 +- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/BackEnd/administration/tests/test_admin_category.py b/BackEnd/administration/tests/test_admin_category.py index 2936d4b42..0136cde55 100644 --- a/BackEnd/administration/tests/test_admin_category.py +++ b/BackEnd/administration/tests/test_admin_category.py @@ -1,7 +1,11 @@ from rest_framework import status from rest_framework.test import APITestCase -from administration.factories import AdminCategoryFactory, AdminUserFactory, AdminProfileFactory +from administration.factories import ( + AdminCategoryFactory, + AdminUserFactory, + AdminProfileFactory, +) from utils.dump_response import dump # noqa from profiles.models import Profile, Category, CustomUser @@ -21,8 +25,7 @@ def tearDown(self): CustomUser.objects.all().delete() AdminUserFactory.reset_sequence(0) AdminCategoryFactory.reset_sequence(0) - AdminProfileFactory.reset_sequence(0) - + AdminProfileFactory.reset_sequence(0) def test_get_category_users_not_staff(self): self.client.force_authenticate(self.user) @@ -33,7 +36,7 @@ def test_get_category_id_users_not_staff(self): self.client.force_authenticate(self.user) response = self.client.get(path="/api/admin/categories/1/") self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) - + class TestAdminCategoryAPIUserStaff(APITestCase): def setUp(self): @@ -50,8 +53,7 @@ def tearDown(self): CustomUser.objects.all().delete() AdminUserFactory.reset_sequence(0) AdminCategoryFactory.reset_sequence(0) - AdminProfileFactory.reset_sequence(0) - + AdminProfileFactory.reset_sequence(0) def test_get_categoryes_users_staff(self): self.client.force_authenticate(self.user) @@ -67,23 +69,20 @@ def test_get_categoryes_users_staff(self): }, ] - self.assertEqual( - data, response.json()["results"] - ) + self.assertEqual(data, response.json()["results"]) self.assertEqual(status.HTTP_200_OK, response.status_code) def test_get_categoryes_id_users_staff(self): self.client.force_authenticate(self.user) response = self.client.get(path="/api/admin/categories/3/") - data = {"name":"category 1"} + data = {"name": "category 1"} self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(data, response.json()) - def test_post_new_categoryes_users_staff(self): self.client.force_authenticate(self.user) - data = {"name":"category 11"} - response = self.client.post(path="/api/admin/categories/",data=data) + data = {"name": "category 11"} + response = self.client.post(path="/api/admin/categories/", data=data) self.assertEqual(status.HTTP_201_CREATED, response.status_code) self.assertEqual(response.json()["name"], data["name"]) self.assertIn("id", response.json()) diff --git a/BackEnd/administration/views.py b/BackEnd/administration/views.py index 830c2ec87..7fccee629 100644 --- a/BackEnd/administration/views.py +++ b/BackEnd/administration/views.py @@ -223,7 +223,7 @@ class ManageCategoriesView(ListCreateAPIView): filter_backends = [DjangoFilterBackend] filterset_class = CategoriesFilter pagination_class = ListPagination - queryset = Category.objects.all().order_by("id") + queryset = Category.objects.all().order_by("id") class CategoryDetailView(RetrieveUpdateAPIView): From cd7adfd64bb7c02f7e256bc44220026c4edc75aa Mon Sep 17 00:00:00 2001 From: romanmyko Date: Thu, 12 Dec 2024 22:19:56 +0200 Subject: [PATCH 07/16] Categories test CRUD --- BackEnd/administration/serializers.py | 22 ++++++++-------- .../tests/test_admin_category.py | 25 ++++++++++++++++++- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 666ab0a65..cd4eb93c6 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -1,5 +1,6 @@ from django.contrib.auth import get_user_model from rest_framework import serializers +from rest_framework.validators import UniqueValidator from utils.administration.feedback_category import FeedbackCategory from authentication.models import CustomUser from profiles.models import ( @@ -217,19 +218,18 @@ class FeedbackSerializer(serializers.Serializer): class ManageCategoriesSerializer(serializers.ModelSerializer): + name = serializers.CharField( + validators=[ + UniqueValidator( + queryset=Category.objects.all(), + message="Category with this name already exists.", + ) + ] + ) + class Meta: model = Category - fields = ( - "id", - "name", - ) - - def validate_name(self, value): - if Category.objects.filter(name=value).exists(): - raise serializers.ValidationError( - "Category with this name already exists." - ) - return value + fields = ("id", "name") class CategoryDetailSerializer(serializers.ModelSerializer): diff --git a/BackEnd/administration/tests/test_admin_category.py b/BackEnd/administration/tests/test_admin_category.py index 0136cde55..0b901e405 100644 --- a/BackEnd/administration/tests/test_admin_category.py +++ b/BackEnd/administration/tests/test_admin_category.py @@ -6,7 +6,6 @@ AdminUserFactory, AdminProfileFactory, ) -from utils.dump_response import dump # noqa from profiles.models import Profile, Category, CustomUser @@ -86,3 +85,27 @@ def test_post_new_categoryes_users_staff(self): self.assertEqual(status.HTTP_201_CREATED, response.status_code) self.assertEqual(response.json()["name"], data["name"]) self.assertIn("id", response.json()) + + def test_post_unique_categoryes_users_staff(self): + self.client.force_authenticate(self.user) + data = {"name": "category 1"} + message = "Category with this name already exists." + response = self.client.post(path="/api/admin/categories/", data=data) + self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) + self.assertEqual(response.json()["name"][0], message) + + def test_put_categoryes_id_users_staff(self): + self.client.force_authenticate(self.user) + data = {"name": "category 1212"} + response = self.client.put(path="/api/admin/categories/14/", data=data) + self.assertEqual(status.HTTP_200_OK, response.status_code) + self.assertEqual(response.json()["name"], data["name"]) + + def test_patch_categoryes_id_users_staff(self): + self.client.force_authenticate(self.user) + data = {"name": "category 77"} + response = self.client.patch( + path="/api/admin/categories/7/", data=data + ) + self.assertEqual(status.HTTP_200_OK, response.status_code) + self.assertEqual(response.json()["name"], data["name"]) From 93b90269c01fefa606f1d85427dc0166521cb935 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Thu, 12 Dec 2024 22:33:33 +0200 Subject: [PATCH 08/16] doc --- BackEnd/administration/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BackEnd/administration/views.py b/BackEnd/administration/views.py index 9caadd75b..9006a907c 100644 --- a/BackEnd/administration/views.py +++ b/BackEnd/administration/views.py @@ -235,7 +235,7 @@ class ManageCategoriesView(ListCreateAPIView): ### Ordering: - Use the `ordering` parameter to sort the results. - - Example: `/manage_categori/?ordering=id` (ascending by ID) or `/manage_categori/?ordering=-id` (descending by ID). + - Example: `/categories/?ordering=id` (ascending by ID) or `/categories/?ordering=-id` (descending by ID). ### Filters: - Filters are applied using `DjangoFilterBackend`. All the above query parameters are supported for filtering. From dbc68db59e2805d15604d4c47bfd9d145ae4cd51 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Fri, 13 Dec 2024 20:09:56 +0200 Subject: [PATCH 09/16] correction categoties --- BackEnd/administration/filters.py | 2 +- BackEnd/administration/tests/test_admin_category.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BackEnd/administration/filters.py b/BackEnd/administration/filters.py index 1346318f7..dfe18feb6 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -47,7 +47,7 @@ def filter_is_deleted(self, queryset, name, value): class CategoriesFilter(FilterSet): """ - manage categori filter + manage categories filter """ id = filters.CharFilter(lookup_expr="icontains") diff --git a/BackEnd/administration/tests/test_admin_category.py b/BackEnd/administration/tests/test_admin_category.py index 0b901e405..e33666299 100644 --- a/BackEnd/administration/tests/test_admin_category.py +++ b/BackEnd/administration/tests/test_admin_category.py @@ -54,7 +54,7 @@ def tearDown(self): AdminCategoryFactory.reset_sequence(0) AdminProfileFactory.reset_sequence(0) - def test_get_categoryes_users_staff(self): + def test_get_categories_users_staff(self): self.client.force_authenticate(self.user) response = self.client.get(path="/api/admin/categories/") data = [ @@ -71,14 +71,14 @@ def test_get_categoryes_users_staff(self): self.assertEqual(data, response.json()["results"]) self.assertEqual(status.HTTP_200_OK, response.status_code) - def test_get_categoryes_id_users_staff(self): + def test_get_categories_id_users_staff(self): self.client.force_authenticate(self.user) response = self.client.get(path="/api/admin/categories/3/") data = {"name": "category 1"} self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(data, response.json()) - def test_post_new_categoryes_users_staff(self): + def test_post_new_categories_users_staff(self): self.client.force_authenticate(self.user) data = {"name": "category 11"} response = self.client.post(path="/api/admin/categories/", data=data) @@ -86,7 +86,7 @@ def test_post_new_categoryes_users_staff(self): self.assertEqual(response.json()["name"], data["name"]) self.assertIn("id", response.json()) - def test_post_unique_categoryes_users_staff(self): + def test_post_unique_categories_users_staff(self): self.client.force_authenticate(self.user) data = {"name": "category 1"} message = "Category with this name already exists." @@ -94,14 +94,14 @@ def test_post_unique_categoryes_users_staff(self): self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) self.assertEqual(response.json()["name"][0], message) - def test_put_categoryes_id_users_staff(self): + def test_put_categories_id_users_staff(self): self.client.force_authenticate(self.user) data = {"name": "category 1212"} response = self.client.put(path="/api/admin/categories/14/", data=data) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(response.json()["name"], data["name"]) - def test_patch_categoryes_id_users_staff(self): + def test_patch_categories_id_users_staff(self): self.client.force_authenticate(self.user) data = {"name": "category 77"} response = self.client.patch( From a54e667c642431f1d0192724f335cc38daca8d90 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Sun, 15 Dec 2024 14:48:35 +0200 Subject: [PATCH 10/16] Rename views and serializer --- BackEnd/administration/serializers.py | 2 +- BackEnd/administration/urls.py | 4 ++-- BackEnd/administration/views.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index cd4eb93c6..ca0c6a8bc 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -217,7 +217,7 @@ class FeedbackSerializer(serializers.Serializer): ) -class ManageCategoriesSerializer(serializers.ModelSerializer): +class CategoriesListSerializer(serializers.ModelSerializer): name = serializers.CharField( validators=[ UniqueValidator( diff --git a/BackEnd/administration/urls.py b/BackEnd/administration/urls.py index 392693802..83e19e306 100644 --- a/BackEnd/administration/urls.py +++ b/BackEnd/administration/urls.py @@ -11,7 +11,7 @@ ModerationEmailView, FeedbackView, CreateAdminUserView, - ManageCategoriesView, + CategoriesListView, CategoryDetailView, SendMessageView, ) @@ -39,7 +39,7 @@ path("admin_create/", CreateAdminUserView.as_view(), name="admin-create"), path( "categories/", - ManageCategoriesView.as_view(), + CategoriesListView.as_view(), name="categories", ), path( diff --git a/BackEnd/administration/views.py b/BackEnd/administration/views.py index 9006a907c..6b2463246 100644 --- a/BackEnd/administration/views.py +++ b/BackEnd/administration/views.py @@ -26,7 +26,7 @@ AdminUserDetailSerializer, AutoModerationHoursSerializer, ModerationEmailSerializer, - ManageCategoriesSerializer, + CategoriesListSerializer, CategoryDetailSerializer, StatisticsSerializer, ) @@ -227,7 +227,7 @@ def perform_create(self, serializer): send_email_feedback(email, message, category) -class ManageCategoriesView(ListCreateAPIView): +class CategoriesListView(ListCreateAPIView): """ Manage categories ### Query Parameters: @@ -242,7 +242,7 @@ class ManageCategoriesView(ListCreateAPIView): """ permission_classes = [IsStaffUser] - serializer_class = ManageCategoriesSerializer + serializer_class = CategoriesListSerializer filter_backends = [DjangoFilterBackend] filterset_class = CategoriesFilter pagination_class = ListPagination From 2da00064ddf2ef455a961e034813629442d95496 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Sun, 15 Dec 2024 15:15:26 +0200 Subject: [PATCH 11/16] filter ID --- BackEnd/administration/filters.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/BackEnd/administration/filters.py b/BackEnd/administration/filters.py index dfe18feb6..635e6c28b 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -1,5 +1,10 @@ from django_filters import filters from django_filters.rest_framework import FilterSet +from django.db.models import CharField +from django.db.models.functions import Cast +from profiles.models import ( + Category, +) class UsersFilter(FilterSet): @@ -46,11 +51,7 @@ def filter_is_deleted(self, queryset, name, value): class CategoriesFilter(FilterSet): - """ - manage categories filter - """ - - id = filters.CharFilter(lookup_expr="icontains") + id = filters.CharFilter(method="filter_partial_id") name = filters.CharFilter(lookup_expr="icontains") ordering = filters.OrderingFilter( fields=( @@ -58,3 +59,12 @@ class CategoriesFilter(FilterSet): ("name", "name"), ) ) + + def filter_partial_id(self, queryset, name, value): + return queryset.annotate(id_str=Cast("id", CharField())).filter( + id_str__icontains=value + ) + + class Meta: + model = Category + fields = ["id", "name"] From 791dcfabd59383d89141adb7a2f63ed43f6a3045 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Sun, 15 Dec 2024 20:10:14 +0200 Subject: [PATCH 12/16] correct test --- .../tests/test_admin_category.py | 57 ++++++++----------- .../tests/test_admin_profiles.py | 15 ++--- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/BackEnd/administration/tests/test_admin_category.py b/BackEnd/administration/tests/test_admin_category.py index e33666299..8d8255a4b 100644 --- a/BackEnd/administration/tests/test_admin_category.py +++ b/BackEnd/administration/tests/test_admin_category.py @@ -4,27 +4,21 @@ from administration.factories import ( AdminCategoryFactory, AdminUserFactory, - AdminProfileFactory, ) -from profiles.models import Profile, Category, CustomUser + +from utils.dump_response import dump # noqa +from utils.unittest_helper import AnyInt, AnyStr class TestAdminCategoryAPIUserNotStaff(APITestCase): + maxDiff = None + def setUp(self): self.user = AdminUserFactory( is_staff=False, is_active=True, ) - self.name = AdminCategoryFactory() - - def tearDown(self): - super().tearDown() - Category.objects.all().delete() - Profile.objects.all().delete() - CustomUser.objects.all().delete() - AdminUserFactory.reset_sequence(0) - AdminCategoryFactory.reset_sequence(0) - AdminProfileFactory.reset_sequence(0) + self.category = AdminCategoryFactory() def test_get_category_users_not_staff(self): self.client.force_authenticate(self.user) @@ -38,74 +32,73 @@ def test_get_category_id_users_not_staff(self): class TestAdminCategoryAPIUserStaff(APITestCase): + maxDiff = None + def setUp(self): self.user = AdminUserFactory( is_staff=True, is_active=True, ) - self.name = AdminCategoryFactory.create_batch(2) - - def tearDown(self): - super().tearDown() - Category.objects.all().delete() - Profile.objects.all().delete() - CustomUser.objects.all().delete() - AdminUserFactory.reset_sequence(0) - AdminCategoryFactory.reset_sequence(0) - AdminProfileFactory.reset_sequence(0) + self.categories = AdminCategoryFactory.create_batch(2) def test_get_categories_users_staff(self): self.client.force_authenticate(self.user) response = self.client.get(path="/api/admin/categories/") data = [ { - "id": 5, - "name": "category 1", + "id": AnyInt(), + "name": AnyStr(), }, { - "id": 6, - "name": "category 2", + "id": AnyInt(), + "name": AnyStr(), }, ] - self.assertEqual(data, response.json()["results"]) self.assertEqual(status.HTTP_200_OK, response.status_code) def test_get_categories_id_users_staff(self): self.client.force_authenticate(self.user) response = self.client.get(path="/api/admin/categories/3/") - data = {"name": "category 1"} + data = {"name": AnyStr()} self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(data, response.json()) def test_post_new_categories_users_staff(self): self.client.force_authenticate(self.user) - data = {"name": "category 11"} + data = {"name": "some category"} response = self.client.post(path="/api/admin/categories/", data=data) self.assertEqual(status.HTTP_201_CREATED, response.status_code) self.assertEqual(response.json()["name"], data["name"]) self.assertIn("id", response.json()) def test_post_unique_categories_users_staff(self): + self.existing_name = AdminCategoryFactory.create( + name="existing category" + ) self.client.force_authenticate(self.user) - data = {"name": "category 1"} + data = {"name": "existing category"} message = "Category with this name already exists." response = self.client.post(path="/api/admin/categories/", data=data) self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) self.assertEqual(response.json()["name"][0], message) def test_put_categories_id_users_staff(self): + self.category = AdminCategoryFactory.create() self.client.force_authenticate(self.user) data = {"name": "category 1212"} - response = self.client.put(path="/api/admin/categories/14/", data=data) + response = self.client.put( + path=f"/api/admin/categories/{self.category.id}/", data=data + ) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(response.json()["name"], data["name"]) def test_patch_categories_id_users_staff(self): + self.category = AdminCategoryFactory.create() self.client.force_authenticate(self.user) data = {"name": "category 77"} response = self.client.patch( - path="/api/admin/categories/7/", data=data + path=f"/api/admin/categories/{self.category.id}/", data=data ) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(response.json()["name"], data["name"]) diff --git a/BackEnd/administration/tests/test_admin_profiles.py b/BackEnd/administration/tests/test_admin_profiles.py index c4d4fd36d..24bb4a27b 100644 --- a/BackEnd/administration/tests/test_admin_profiles.py +++ b/BackEnd/administration/tests/test_admin_profiles.py @@ -6,6 +6,7 @@ AdminProfileFactory, ) +from utils.unittest_helper import AnyInt, AnyStr from utils.dump_response import dump # noqa @@ -52,14 +53,14 @@ def test_get_profiles_structure_json(self): response = self.client.get(path="/api/admin/profiles/") data = [ { - "id": 4, + "id": AnyInt(), "name": "Test person", "is_registered": True, "is_startup": True, "person": { - "name": "Test person 7", - "surname": "Test person 7 surname", - "email": "test7@test.com", + "name": AnyStr(), + "surname": AnyStr(), + "email": AnyStr(), "is_active": True, "is_staff": True, "is_superuser": False, @@ -89,9 +90,9 @@ def test_get_profile_id_authenticated(self): "categories": [], "activities": [], "person": { - "name": "Test person 1", - "surname": "Test person 1 surname", - "email": "test1@test.com", + "name": AnyStr(), + "surname": AnyStr(), + "email": AnyStr(), "is_active": True, "is_staff": True, "is_superuser": False, From 285ae7687a0641485bccc7759a009530cf263379 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Sun, 15 Dec 2024 21:04:37 +0200 Subject: [PATCH 13/16] filter correct --- BackEnd/administration/filters.py | 23 +++++++------------ .../tests/test_admin_category.py | 4 ---- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/BackEnd/administration/filters.py b/BackEnd/administration/filters.py index 635e6c28b..25365c538 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -1,10 +1,5 @@ from django_filters import filters from django_filters.rest_framework import FilterSet -from django.db.models import CharField -from django.db.models.functions import Cast -from profiles.models import ( - Category, -) class UsersFilter(FilterSet): @@ -16,7 +11,7 @@ class UsersFilter(FilterSet): /?ordering=id asc or /?ordering=-id desc """ - id = filters.CharFilter(lookup_expr="icontains") + id = filters.CharFilter(method="filter_partial_id") surname = filters.CharFilter(lookup_expr="icontains") email = filters.CharFilter(lookup_expr="icontains") is_active = filters.CharFilter(lookup_expr="icontains") @@ -35,6 +30,9 @@ def filter_is_deleted(self, queryset, name, value): queryset = queryset.filter(email__startswith="is_deleted_") return queryset + def filter_partial_id(self, queryset, name, value): + return queryset.filter(id__icontains=value) + ordering = filters.OrderingFilter( fields=( ("name", "name"), @@ -53,18 +51,13 @@ def filter_is_deleted(self, queryset, name, value): class CategoriesFilter(FilterSet): id = filters.CharFilter(method="filter_partial_id") name = filters.CharFilter(lookup_expr="icontains") + + def filter_partial_id(self, queryset, name, value): + return queryset.filter(id__icontains=value) + ordering = filters.OrderingFilter( fields=( ("id", "id"), ("name", "name"), ) ) - - def filter_partial_id(self, queryset, name, value): - return queryset.annotate(id_str=Cast("id", CharField())).filter( - id_str__icontains=value - ) - - class Meta: - model = Category - fields = ["id", "name"] diff --git a/BackEnd/administration/tests/test_admin_category.py b/BackEnd/administration/tests/test_admin_category.py index 8d8255a4b..987813e86 100644 --- a/BackEnd/administration/tests/test_admin_category.py +++ b/BackEnd/administration/tests/test_admin_category.py @@ -11,8 +11,6 @@ class TestAdminCategoryAPIUserNotStaff(APITestCase): - maxDiff = None - def setUp(self): self.user = AdminUserFactory( is_staff=False, @@ -32,8 +30,6 @@ def test_get_category_id_users_not_staff(self): class TestAdminCategoryAPIUserStaff(APITestCase): - maxDiff = None - def setUp(self): self.user = AdminUserFactory( is_staff=True, From e6a536d5029ed01ce2b593914baab2553f22612e Mon Sep 17 00:00:00 2001 From: romanmyko Date: Mon, 16 Dec 2024 09:17:17 +0200 Subject: [PATCH 14/16] filter v1.0.3 --- BackEnd/administration/filters.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/BackEnd/administration/filters.py b/BackEnd/administration/filters.py index 25365c538..7d5c74d72 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -11,7 +11,7 @@ class UsersFilter(FilterSet): /?ordering=id asc or /?ordering=-id desc """ - id = filters.CharFilter(method="filter_partial_id") + id = filters.NumberFilter(lookup_expr="icontains") surname = filters.CharFilter(lookup_expr="icontains") email = filters.CharFilter(lookup_expr="icontains") is_active = filters.CharFilter(lookup_expr="icontains") @@ -30,9 +30,6 @@ def filter_is_deleted(self, queryset, name, value): queryset = queryset.filter(email__startswith="is_deleted_") return queryset - def filter_partial_id(self, queryset, name, value): - return queryset.filter(id__icontains=value) - ordering = filters.OrderingFilter( fields=( ("name", "name"), @@ -49,12 +46,8 @@ def filter_partial_id(self, queryset, name, value): class CategoriesFilter(FilterSet): - id = filters.CharFilter(method="filter_partial_id") + id = filters.NumberFilter(lookup_expr="icontains") name = filters.CharFilter(lookup_expr="icontains") - - def filter_partial_id(self, queryset, name, value): - return queryset.filter(id__icontains=value) - ordering = filters.OrderingFilter( fields=( ("id", "id"), From 1e8fc4e897906e101c52d4538e8c92a3dfd1b91f Mon Sep 17 00:00:00 2001 From: romanmyko Date: Mon, 16 Dec 2024 09:47:34 +0200 Subject: [PATCH 15/16] filter v1.0.4 --- BackEnd/administration/filters.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BackEnd/administration/filters.py b/BackEnd/administration/filters.py index 7d5c74d72..596060563 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -11,12 +11,12 @@ class UsersFilter(FilterSet): /?ordering=id asc or /?ordering=-id desc """ - id = filters.NumberFilter(lookup_expr="icontains") + id = filters.NumberFilter(lookup_expr="contains") surname = filters.CharFilter(lookup_expr="icontains") email = filters.CharFilter(lookup_expr="icontains") - is_active = filters.CharFilter(lookup_expr="icontains") - is_staff = filters.CharFilter(lookup_expr="icontains") - is_superuser = filters.CharFilter(lookup_expr="icontains") + is_active = filters.BooleanFilter() + is_staff = filters.BooleanFilter() + is_superuser = filters.BooleanFilter() is_deleted = filters.BooleanFilter(method="filter_is_deleted") company_name = filters.CharFilter( field_name="profile__name", lookup_expr="icontains" @@ -46,7 +46,7 @@ def filter_is_deleted(self, queryset, name, value): class CategoriesFilter(FilterSet): - id = filters.NumberFilter(lookup_expr="icontains") + id = filters.NumberFilter(lookup_expr="contains") name = filters.CharFilter(lookup_expr="icontains") ordering = filters.OrderingFilter( fields=( From 2a939c525ac495588a57d2c680ad6804878f4638 Mon Sep 17 00:00:00 2001 From: romanmyko Date: Mon, 16 Dec 2024 09:56:12 +0200 Subject: [PATCH 16/16] filter v1.0.5 --- BackEnd/administration/filters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BackEnd/administration/filters.py b/BackEnd/administration/filters.py index 596060563..a025bca6a 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -17,7 +17,7 @@ class UsersFilter(FilterSet): is_active = filters.BooleanFilter() is_staff = filters.BooleanFilter() is_superuser = filters.BooleanFilter() - is_deleted = filters.BooleanFilter(method="filter_is_deleted") + is_deleted = filters.BooleanFilter(method="is_deleted_filter") company_name = filters.CharFilter( field_name="profile__name", lookup_expr="icontains" ) @@ -25,7 +25,7 @@ class UsersFilter(FilterSet): field_name="profile__created_at", lookup_expr="icontains" ) - def filter_is_deleted(self, queryset, name, value): + def is_deleted_filter(self, queryset, name, value): if value: queryset = queryset.filter(email__startswith="is_deleted_") return queryset