From 19fc399b9b60a31b5046d5b919ccf0f20f68fa38 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 8 Dec 2024 00:54:06 +0200 Subject: [PATCH 01/27] Added additional fields to admin company list serializer --- BackEnd/administration/serializers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 24cda9beb..7ece0a316 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -121,6 +121,9 @@ class Meta: "phone", "edrpou", "address", + "status", + "updated_at", + "created_at", "is_deleted", ) From a64bf61d88620d33ec8b1aeadcfb6a6536b8f4d4 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 8 Dec 2024 00:54:37 +0200 Subject: [PATCH 02/27] Added additional fields to admin company list serializer --- BackEnd/administration/serializers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 7ece0a316..62b8fdc72 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -114,6 +114,7 @@ class Meta: "name", "is_registered", "is_startup", + "is_fop", "person", "person_position", "regions", From 1ff0cd4848f8628cd730b9e07e323bdf3035f605 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 8 Dec 2024 01:34:12 +0200 Subject: [PATCH 03/27] Added company type field to profiles serializer --- BackEnd/administration/serializers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 62b8fdc72..3e9cc5c3a 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -106,6 +106,7 @@ def get_company_name(self, obj) -> bool: class AdminCompanyListSerializer(serializers.ModelSerializer): person = AdminUserDetailSerializer(read_only=True) regions = AdminRegionSerializer(many=True, read_only=True) + company_type = serializers.SerializerMethodField() class Meta: model = Profile @@ -126,8 +127,16 @@ class Meta: "updated_at", "created_at", "is_deleted", + "company_type" ) + def get_company_type(self, obj): + if obj.is_fop: + return "ФОП" + elif obj.is_startup: + return "Стартап" + return None + class AdminCompanyDetailSerializer(serializers.ModelSerializer): person = AdminUserDetailSerializer(read_only=True) From dfdc7389d2cfb9df4afa068bbb595ceacb776fdb Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 8 Dec 2024 01:35:33 +0200 Subject: [PATCH 04/27] Deleted is_fop and is_startup from the profiles serializer --- BackEnd/administration/serializers.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 3e9cc5c3a..7d067c078 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -114,8 +114,6 @@ class Meta: "id", "name", "is_registered", - "is_startup", - "is_fop", "person", "person_position", "regions", From 6db21f0839ec4b045e94f95754473c70bff2057c Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 8 Dec 2024 01:37:00 +0200 Subject: [PATCH 05/27] Added read_only to field "company_type" profiles serializer --- BackEnd/administration/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 7d067c078..e91f311a6 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -106,7 +106,7 @@ def get_company_name(self, obj) -> bool: class AdminCompanyListSerializer(serializers.ModelSerializer): person = AdminUserDetailSerializer(read_only=True) regions = AdminRegionSerializer(many=True, read_only=True) - company_type = serializers.SerializerMethodField() + company_type = serializers.SerializerMethodField(read_only=True) class Meta: model = Profile From acf85d0844c82bdcbb3fd04b48742eec1907c31a Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 8 Dec 2024 01:52:14 +0200 Subject: [PATCH 06/27] Added categories to the companies' serializer --- BackEnd/administration/serializers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index e91f311a6..36799ec7a 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -4,7 +4,7 @@ from authentication.models import CustomUser from profiles.models import ( Profile, - Region, + Region, Category, ) from utils.administration.create_password import generate_password from utils.administration.send_email import send_email_about_admin_registration @@ -21,6 +21,14 @@ class Meta: "name_ukr", ) +class CategoriesSerializer(serializers.ModelSerializer): + class Meta: + model = Category + fields = ( + "id", + "name", + ) + class AdminRegistrationSerializer(serializers.Serializer): email = serializers.EmailField( @@ -107,6 +115,7 @@ class AdminCompanyListSerializer(serializers.ModelSerializer): person = AdminUserDetailSerializer(read_only=True) regions = AdminRegionSerializer(many=True, read_only=True) company_type = serializers.SerializerMethodField(read_only=True) + categories = CategoriesSerializer(many=True, read_only=True) class Meta: model = Profile @@ -125,7 +134,8 @@ class Meta: "updated_at", "created_at", "is_deleted", - "company_type" + "company_type", + "categories", ) def get_company_type(self, obj): From 35598acded2661013e546506f362712f8f67a865 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 8 Dec 2024 19:55:27 +0200 Subject: [PATCH 07/27] Added representative field to AdminCompanyListSerializer --- BackEnd/administration/serializers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 36799ec7a..da6b2705e 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -136,6 +136,7 @@ class Meta: "is_deleted", "company_type", "categories", + "representative" ) def get_company_type(self, obj): @@ -145,6 +146,11 @@ def get_company_type(self, obj): return "Стартап" return None + def get_representative(self, obj): + if obj.person: + return f'{obj.name} {obj.surname}' + return None + class AdminCompanyDetailSerializer(serializers.ModelSerializer): person = AdminUserDetailSerializer(read_only=True) From 73b1774ca7e5d8a3976c7037a6f4beffbbda3d88 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 8 Dec 2024 19:57:06 +0200 Subject: [PATCH 08/27] Added representative field to AdminCompanyListSerializer --- BackEnd/administration/serializers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index da6b2705e..21a5851cf 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -116,6 +116,7 @@ class AdminCompanyListSerializer(serializers.ModelSerializer): regions = AdminRegionSerializer(many=True, read_only=True) company_type = serializers.SerializerMethodField(read_only=True) categories = CategoriesSerializer(many=True, read_only=True) + representative = serializers.SerializerMethodField(read_only=True) class Meta: model = Profile From 973298ab1e5923aff20c72f0c626e436ceb172ee Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 8 Dec 2024 19:58:38 +0200 Subject: [PATCH 09/27] Added representative field to AdminCompanyListSerializer --- BackEnd/administration/serializers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 21a5851cf..05ad546c2 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -137,7 +137,7 @@ class Meta: "is_deleted", "company_type", "categories", - "representative" + "representative", ) def get_company_type(self, obj): @@ -149,7 +149,7 @@ def get_company_type(self, obj): def get_representative(self, obj): if obj.person: - return f'{obj.name} {obj.surname}' + return f'{obj.person.name} {obj.person.surname}' return None From 906e94c1e7891d92d6dc48a2fdebe0f1ee972c60 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 12 Dec 2024 02:10:26 +0200 Subject: [PATCH 10/27] Updated view for profiles admin --- BackEnd/administration/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/BackEnd/administration/views.py b/BackEnd/administration/views.py index 52db67f0a..cf211c5ed 100644 --- a/BackEnd/administration/views.py +++ b/BackEnd/administration/views.py @@ -1,3 +1,5 @@ +from django.db.models.functions import Concat +from django.db.models import F, Value, CharField from django.http import JsonResponse from django.views import View from drf_spectacular.utils import ( @@ -85,10 +87,21 @@ class ProfilesListView(ListAPIView): permission_classes = [IsStaffUser] pagination_class = ListPagination serializer_class = AdminCompanyListSerializer + filter_backends = [DjangoFilterBackend] + filterset_class = ProfilesFilter queryset = ( Profile.objects.select_related("person") .prefetch_related("regions", "categories", "activities") .order_by("id") + .annotate( + representative=Concat( + F("person__name"), + Value(" "), + F("person__surname"), + output_field=CharField(), + ) + ) + .order_by("id") ) From 2e480239221abe92fd4cac3540b66b0e8fbd0aab Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 12 Dec 2024 02:11:00 +0200 Subject: [PATCH 11/27] Updated filter for profiles admin --- BackEnd/administration/filters.py | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/BackEnd/administration/filters.py b/BackEnd/administration/filters.py index 2a522ddc5..874a9ccb6 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -43,3 +43,36 @@ def filter_is_deleted(self, queryset, name, value): ("profile__created_at", "registration_date"), ) ) + + +class ProfilesFilter(FilterSet): + """ + Filters + /?name= , /?representative= , /?official_name= , /?phone= , /?address= , + /?created_at= , /?updated_at= , + Ordering sample: + /?ordering=id asc or /?ordering=-id desc + """ + name = filters.CharFilter(lookup_expr="icontains") + representative = filters.CharFilter( + field_name="representative", lookup_expr="icontains" + ) + official_name = filters.CharFilter(lookup_expr="icontains") + phone = filters.CharFilter(lookup_expr="icontains") + address = filters.CharFilter(lookup_expr="icontains") + created_at = filters.DateFilter(lookup_expr="icontains") + updated_at = filters.DateFilter(lookup_expr="icontains") + + ordering = filters.OrderingFilter( + fields=( + ("name", "name"), + ("is_registered", "is_registered"), + ("representative", "representative"), + ("official_name", "official_name"), + ("phone", "phone"), + ("address", "address"), + ("status", "status"), + ("created_at", "created_at"), + ("updated_at", "updated_at"), + ) + ) From 536939bc1cd396919663d90ce35f7191c627ec66 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 12 Dec 2024 11:05:45 +0200 Subject: [PATCH 12/27] Fixed company type admin company list serializer --- BackEnd/administration/serializers.py | 8 +++++--- BackEnd/administration/views.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 05ad546c2..4bc8e4233 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -141,9 +141,11 @@ class Meta: ) def get_company_type(self, obj): - if obj.is_fop: - return "ФОП" - elif obj.is_startup: + if obj.is_startup and obj.is_registered: + return "Компанія і стартап" + if obj.is_registered: + return "Компанія" + if obj.is_startup: return "Стартап" return None diff --git a/BackEnd/administration/views.py b/BackEnd/administration/views.py index cf211c5ed..04687ee03 100644 --- a/BackEnd/administration/views.py +++ b/BackEnd/administration/views.py @@ -34,7 +34,7 @@ from utils.administration.send_email_notification import send_email_to_user from django_filters.rest_framework import DjangoFilterBackend -from .filters import UsersFilter +from .filters import UsersFilter, ProfilesFilter class UsersListView(ListAPIView): From 08c3d867495e5e7218474f7b4dd46ceb92980d0a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 12 Dec 2024 11:07:55 +0200 Subject: [PATCH 13/27] Fixed activities admin company list serializer --- BackEnd/administration/serializers.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 4bc8e4233..41fecaf3d 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -4,7 +4,7 @@ from authentication.models import CustomUser from profiles.models import ( Profile, - Region, Category, + Region, Category, Activity, ) from utils.administration.create_password import generate_password from utils.administration.send_email import send_email_about_admin_registration @@ -21,9 +21,9 @@ class Meta: "name_ukr", ) -class CategoriesSerializer(serializers.ModelSerializer): +class ActivitiesSerializer(serializers.ModelSerializer): class Meta: - model = Category + model = Activity fields = ( "id", "name", @@ -115,7 +115,7 @@ class AdminCompanyListSerializer(serializers.ModelSerializer): person = AdminUserDetailSerializer(read_only=True) regions = AdminRegionSerializer(many=True, read_only=True) company_type = serializers.SerializerMethodField(read_only=True) - categories = CategoriesSerializer(many=True, read_only=True) + activities = ActivitiesSerializer(many=True, read_only=True) representative = serializers.SerializerMethodField(read_only=True) class Meta: @@ -136,7 +136,7 @@ class Meta: "created_at", "is_deleted", "company_type", - "categories", + "activities", "representative", ) From dd88d58d3a302c3f8cf18a02d7739cb861a21c7a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 12 Dec 2024 11:11:25 +0200 Subject: [PATCH 14/27] Added business entity --- BackEnd/administration/serializers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 41fecaf3d..e86dd2b96 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -117,6 +117,7 @@ class AdminCompanyListSerializer(serializers.ModelSerializer): company_type = serializers.SerializerMethodField(read_only=True) activities = ActivitiesSerializer(many=True, read_only=True) representative = serializers.SerializerMethodField(read_only=True) + business_entity = serializers.SerializerMethodField(read_only=True) class Meta: model = Profile @@ -127,7 +128,7 @@ class Meta: "person", "person_position", "regions", - "official_name", + "business_entity", "phone", "edrpou", "address", @@ -154,6 +155,11 @@ def get_representative(self, obj): return f'{obj.person.name} {obj.person.surname}' return None + def get_business_entity(self, obj): + if obj.is_fop: + return "ФОП" + return "Юридична особа" + class AdminCompanyDetailSerializer(serializers.ModelSerializer): person = AdminUserDetailSerializer(read_only=True) From fc649e4093e4f76e1deddfe3f7c30b2f06f951d5 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 13 Dec 2024 19:33:17 +0200 Subject: [PATCH 15/27] Added search functionality to profiles and users backend --- BackEnd/administration/views.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/BackEnd/administration/views.py b/BackEnd/administration/views.py index 04687ee03..f907e6711 100644 --- a/BackEnd/administration/views.py +++ b/BackEnd/administration/views.py @@ -7,6 +7,7 @@ OpenApiExample, OpenApiResponse, ) +from rest_framework.filters import SearchFilter from rest_framework.generics import ( ListAPIView, RetrieveUpdateDestroyAPIView, @@ -57,7 +58,8 @@ class UsersListView(ListAPIView): permission_classes = [IsStaffUser] pagination_class = ListPagination serializer_class = AdminUserListSerializer - filter_backends = [DjangoFilterBackend] + filter_backends = [DjangoFilterBackend, SearchFilter] + search_fields = ['name', 'surname', 'email', 'company_name'] filterset_class = UsersFilter queryset = CustomUser.objects.select_related("profile").order_by("id") @@ -81,13 +83,13 @@ def destroy(self, request, *args, **kwargs): class ProfilesListView(ListAPIView): """ - List of profiles. + View to list profiles with optional filtering and ordering. """ - permission_classes = [IsStaffUser] pagination_class = ListPagination serializer_class = AdminCompanyListSerializer - filter_backends = [DjangoFilterBackend] + filter_backends = [DjangoFilterBackend, SearchFilter] + search_fields = ["name", "representative", "updated_at", "created_at", "address", "phone"] filterset_class = ProfilesFilter queryset = ( Profile.objects.select_related("person") From ac8d32644b9391c0d2db13c32fb7fd0b52a1d3ae Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 18 Dec 2024 14:31:34 +0200 Subject: [PATCH 16/27] deleted unnecessary search functionality backend admin panel --- BackEnd/administration/views.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/BackEnd/administration/views.py b/BackEnd/administration/views.py index f907e6711..a10870a60 100644 --- a/BackEnd/administration/views.py +++ b/BackEnd/administration/views.py @@ -7,7 +7,6 @@ OpenApiExample, OpenApiResponse, ) -from rest_framework.filters import SearchFilter from rest_framework.generics import ( ListAPIView, RetrieveUpdateDestroyAPIView, @@ -58,8 +57,7 @@ class UsersListView(ListAPIView): permission_classes = [IsStaffUser] pagination_class = ListPagination serializer_class = AdminUserListSerializer - filter_backends = [DjangoFilterBackend, SearchFilter] - search_fields = ['name', 'surname', 'email', 'company_name'] + filter_backends = [DjangoFilterBackend] filterset_class = UsersFilter queryset = CustomUser.objects.select_related("profile").order_by("id") @@ -88,8 +86,7 @@ class ProfilesListView(ListAPIView): permission_classes = [IsStaffUser] pagination_class = ListPagination serializer_class = AdminCompanyListSerializer - filter_backends = [DjangoFilterBackend, SearchFilter] - search_fields = ["name", "representative", "updated_at", "created_at", "address", "phone"] + filter_backends = [DjangoFilterBackend] filterset_class = ProfilesFilter queryset = ( Profile.objects.select_related("person") @@ -103,7 +100,6 @@ class ProfilesListView(ListAPIView): output_field=CharField(), ) ) - .order_by("id") ) From 4620bb3423b5ce767c0d04adeeb29afd45463e89 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 18 Dec 2024 14:45:50 +0200 Subject: [PATCH 17/27] Reformated backend profiles admin --- BackEnd/administration/serializers.py | 29 +++++++------------ .../utils/administration/profiles/profiles.py | 20 +++++++++++++ 2 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 BackEnd/utils/administration/profiles/profiles.py diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index e86dd2b96..3f387258a 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -6,6 +6,8 @@ Profile, Region, Category, Activity, ) +from utils.administration.profiles.profiles import get_company_type_as_string, get_representative_as_string, \ + get_business_entity_as_string from utils.administration.create_password import generate_password from utils.administration.send_email import send_email_about_admin_registration from .models import AutoModeration, ModerationEmail @@ -141,26 +143,17 @@ class Meta: "representative", ) - def get_company_type(self, obj): - if obj.is_startup and obj.is_registered: - return "Компанія і стартап" - if obj.is_registered: - return "Компанія" - if obj.is_startup: - return "Стартап" - return None - - def get_representative(self, obj): - if obj.person: - return f'{obj.person.name} {obj.person.surname}' - return None - - def get_business_entity(self, obj): - if obj.is_fop: - return "ФОП" - return "Юридична особа" + @staticmethod + def get_company_type(obj) -> str: + return get_company_type_as_string(obj) + @staticmethod + def get_representative(obj): + return get_representative_as_string(obj) + @staticmethod + def get_business_entity(obj): + return get_business_entity_as_string(obj) class AdminCompanyDetailSerializer(serializers.ModelSerializer): person = AdminUserDetailSerializer(read_only=True) categories = serializers.SlugRelatedField( diff --git a/BackEnd/utils/administration/profiles/profiles.py b/BackEnd/utils/administration/profiles/profiles.py new file mode 100644 index 000000000..f1d531867 --- /dev/null +++ b/BackEnd/utils/administration/profiles/profiles.py @@ -0,0 +1,20 @@ +def get_company_type_as_string(obj): + if obj.is_startup and obj.is_registered: + return "Компанія і стартап" + if obj.is_registered: + return "Компанія" + if obj.is_startup: + return "Стартап" + return None + + +def get_representative_as_string(obj): + if obj.person: + return f'{obj.person.name} {obj.person.surname}' + return None + + +def get_business_entity_as_string(obj): + if obj.is_fop: + return "ФОП" + return "Юридична особа" From eb016280ce30382eeaf93d23c5810c98b4e304f2 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 18 Dec 2024 23:24:55 +0200 Subject: [PATCH 18/27] Adjusted profiles filter administration --- 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 874a9ccb6..14b580c08 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -60,8 +60,8 @@ class ProfilesFilter(FilterSet): official_name = filters.CharFilter(lookup_expr="icontains") phone = filters.CharFilter(lookup_expr="icontains") address = filters.CharFilter(lookup_expr="icontains") - created_at = filters.DateFilter(lookup_expr="icontains") - updated_at = filters.DateFilter(lookup_expr="icontains") + created_at = filters.DateFilter() + updated_at = filters.DateFilter() ordering = filters.OrderingFilter( fields=( From 8e62d95a10cd33561bf8b14715755a20bcde9820 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 18 Dec 2024 23:26:08 +0200 Subject: [PATCH 19/27] Adjusted users filter administration --- 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 14b580c08..103cdecba 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -21,8 +21,8 @@ class UsersFilter(FilterSet): company_name = filters.CharFilter( field_name="profile__name", lookup_expr="icontains" ) - registration_date = filters.CharFilter( - field_name="profile__created_at", lookup_expr="icontains" + registration_date = filters.DateFilter( + field_name="profile__created_at", ) def filter_is_deleted(self, queryset, name, value): From 100b5b8dac9cd81ca698b8719eea8d64442f4e91 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 18 Dec 2024 23:27:04 +0200 Subject: [PATCH 20/27] Adjusted AdminCompanyListSerializer --- BackEnd/administration/serializers.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 3f387258a..761456815 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -23,6 +23,7 @@ class Meta: "name_ukr", ) + class ActivitiesSerializer(serializers.ModelSerializer): class Meta: model = Activity @@ -143,17 +144,16 @@ class Meta: "representative", ) - @staticmethod - def get_company_type(obj) -> str: + def get_company_type(self, obj) -> str: return get_company_type_as_string(obj) - @staticmethod - def get_representative(obj): + def get_representative(self, obj): return get_representative_as_string(obj) - @staticmethod - def get_business_entity(obj): + def get_business_entity(self, obj): return get_business_entity_as_string(obj) + + class AdminCompanyDetailSerializer(serializers.ModelSerializer): person = AdminUserDetailSerializer(read_only=True) categories = serializers.SlugRelatedField( From 41949791ed780e0882167237992d8a2b258dd79c Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 19 Dec 2024 00:13:01 +0200 Subject: [PATCH 21/27] Renamed methods in AdminCompanyListSerializer --- BackEnd/administration/serializers.py | 16 ++++++++-------- .../utils/administration/profiles/profiles.py | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 761456815..2ed389035 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -4,10 +4,10 @@ from authentication.models import CustomUser from profiles.models import ( Profile, - Region, Category, Activity, + Region, Activity, ) -from utils.administration.profiles.profiles import get_company_type_as_string, get_representative_as_string, \ - get_business_entity_as_string +from utils.administration.profiles.profiles import format_company_type, format_representative, \ + format_business_entity from utils.administration.create_password import generate_password from utils.administration.send_email import send_email_about_admin_registration from .models import AutoModeration, ModerationEmail @@ -145,13 +145,13 @@ class Meta: ) def get_company_type(self, obj) -> str: - return get_company_type_as_string(obj) + return format_company_type(obj) - def get_representative(self, obj): - return get_representative_as_string(obj) + def get_representative(self, obj) -> str: + return format_representative(obj) - def get_business_entity(self, obj): - return get_business_entity_as_string(obj) + def get_business_entity(self, obj) -> str: + return format_business_entity(obj) class AdminCompanyDetailSerializer(serializers.ModelSerializer): diff --git a/BackEnd/utils/administration/profiles/profiles.py b/BackEnd/utils/administration/profiles/profiles.py index f1d531867..1c3c06b63 100644 --- a/BackEnd/utils/administration/profiles/profiles.py +++ b/BackEnd/utils/administration/profiles/profiles.py @@ -1,4 +1,4 @@ -def get_company_type_as_string(obj): +def format_company_type(obj): if obj.is_startup and obj.is_registered: return "Компанія і стартап" if obj.is_registered: @@ -8,13 +8,13 @@ def get_company_type_as_string(obj): return None -def get_representative_as_string(obj): +def format_representative(obj): if obj.person: return f'{obj.person.name} {obj.person.surname}' return None -def get_business_entity_as_string(obj): +def format_business_entity(obj): if obj.is_fop: return "ФОП" return "Юридична особа" From a8150618f1f91f786196208b344ff6a6561e2f69 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 20 Dec 2024 13:11:15 +0200 Subject: [PATCH 22/27] Deleted repetitive representative functional admin profiles serializer --- BackEnd/administration/serializers.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 0d9347925..37fdf22c0 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -121,7 +121,7 @@ class AdminCompanyListSerializer(serializers.ModelSerializer): regions = AdminRegionSerializer(many=True, read_only=True) company_type = serializers.SerializerMethodField(read_only=True) activities = ActivitiesSerializer(many=True, read_only=True) - representative = serializers.SerializerMethodField(read_only=True) + representative = serializers.CharField(read_only=True) business_entity = serializers.SerializerMethodField(read_only=True) class Meta: @@ -149,9 +149,6 @@ class Meta: def get_company_type(self, obj) -> str: return format_company_type(obj) - def get_representative(self, obj) -> str: - return format_representative(obj) - def get_business_entity(self, obj) -> str: return format_business_entity(obj) From dc6b835ca8b5a6f9f378b684652307e0075e29d1 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 20 Dec 2024 14:56:56 +0200 Subject: [PATCH 23/27] Deleted unuseful fields admin profiles serializer --- BackEnd/administration/serializers.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 37fdf22c0..23f11878b 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -118,7 +118,6 @@ def get_company_name(self, obj) -> bool: class AdminCompanyListSerializer(serializers.ModelSerializer): person = AdminUserDetailSerializer(read_only=True) - regions = AdminRegionSerializer(many=True, read_only=True) company_type = serializers.SerializerMethodField(read_only=True) activities = ActivitiesSerializer(many=True, read_only=True) representative = serializers.CharField(read_only=True) @@ -129,13 +128,9 @@ class Meta: fields = ( "id", "name", - "is_registered", "person", - "person_position", - "regions", "business_entity", "phone", - "edrpou", "address", "status", "updated_at", From 3540e78fafd3ebe35b31e8758c6febd004682da6 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 22 Dec 2024 23:34:51 +0200 Subject: [PATCH 24/27] Worked with serializer and renamed module name in profiles --- BackEnd/administration/serializers.py | 3 +-- .../profiles/{profiles.py => profiles_functions.py} | 0 2 files changed, 1 insertion(+), 2 deletions(-) rename BackEnd/utils/administration/profiles/{profiles.py => profiles_functions.py} (100%) diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index 23f11878b..f02404d6c 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -8,8 +8,7 @@ Region, Activity, Category, ) -from utils.administration.profiles.profiles import format_company_type, format_representative, \ - format_business_entity +from utils.administration.profiles.profiles_functions import format_company_type, format_business_entity from utils.administration.create_password import generate_password from utils.administration.send_email import send_email_about_admin_registration from .models import AutoModeration, ModerationEmail diff --git a/BackEnd/utils/administration/profiles/profiles.py b/BackEnd/utils/administration/profiles/profiles_functions.py similarity index 100% rename from BackEnd/utils/administration/profiles/profiles.py rename to BackEnd/utils/administration/profiles/profiles_functions.py From 6846a6fb19a850cb854c36d430bb43338965fecf Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 22 Dec 2024 23:41:08 +0200 Subject: [PATCH 25/27] Deleted unused functionality --- BackEnd/utils/administration/profiles/profiles_functions.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/BackEnd/utils/administration/profiles/profiles_functions.py b/BackEnd/utils/administration/profiles/profiles_functions.py index 1c3c06b63..fb8552333 100644 --- a/BackEnd/utils/administration/profiles/profiles_functions.py +++ b/BackEnd/utils/administration/profiles/profiles_functions.py @@ -8,12 +8,6 @@ def format_company_type(obj): return None -def format_representative(obj): - if obj.person: - return f'{obj.person.name} {obj.person.surname}' - return None - - def format_business_entity(obj): if obj.is_fop: return "ФОП" From b05292b8c448c83c33553680adbd65b9d5062068 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 23 Dec 2024 01:33:10 +0200 Subject: [PATCH 26/27] Fixed tests profiles --- BackEnd/administration/tests/test_admin_profiles.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/BackEnd/administration/tests/test_admin_profiles.py b/BackEnd/administration/tests/test_admin_profiles.py index 24bb4a27b..6034f47d6 100644 --- a/BackEnd/administration/tests/test_admin_profiles.py +++ b/BackEnd/administration/tests/test_admin_profiles.py @@ -55,8 +55,6 @@ def test_get_profiles_structure_json(self): { "id": AnyInt(), "name": "Test person", - "is_registered": True, - "is_startup": True, "person": { "name": AnyStr(), "surname": AnyStr(), @@ -66,11 +64,14 @@ def test_get_profiles_structure_json(self): "is_superuser": False, "company_name": True, }, - "person_position": "Test person position", - "regions": [], - "official_name": "Test official name", + "business_entity": AnyStr(), + "status": AnyStr(), + "updated_at": AnyStr(), + "created_at": AnyStr(), + "company_type": AnyStr(), + "activities": [], + "representative": AnyStr(), "phone": "380112909099", - "edrpou": "10000003", "address": "Test Country, Test City, St. Test, 1", "is_deleted": False, } From 065d594baee356f8079663fb077c5d1eabe19929 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 23 Dec 2024 01:34:34 +0200 Subject: [PATCH 27/27] Formatted files --- BackEnd/administration/filters.py | 1 + BackEnd/administration/serializers.py | 8 ++++++-- BackEnd/administration/views.py | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/BackEnd/administration/filters.py b/BackEnd/administration/filters.py index 2ed3235e6..926ef6e34 100644 --- a/BackEnd/administration/filters.py +++ b/BackEnd/administration/filters.py @@ -53,6 +53,7 @@ class ProfilesFilter(FilterSet): Ordering sample: /?ordering=id asc or /?ordering=-id desc """ + name = filters.CharFilter(lookup_expr="icontains") representative = filters.CharFilter( field_name="representative", lookup_expr="icontains" diff --git a/BackEnd/administration/serializers.py b/BackEnd/administration/serializers.py index f02404d6c..4c23de294 100644 --- a/BackEnd/administration/serializers.py +++ b/BackEnd/administration/serializers.py @@ -5,10 +5,14 @@ from authentication.models import CustomUser from profiles.models import ( Profile, - Region, Activity, + Region, + Activity, Category, ) -from utils.administration.profiles.profiles_functions import format_company_type, format_business_entity +from utils.administration.profiles.profiles_functions import ( + format_company_type, + format_business_entity, +) from utils.administration.create_password import generate_password from utils.administration.send_email import send_email_about_admin_registration from .models import AutoModeration, ModerationEmail diff --git a/BackEnd/administration/views.py b/BackEnd/administration/views.py index 67bdb4c8e..af6dfb650 100644 --- a/BackEnd/administration/views.py +++ b/BackEnd/administration/views.py @@ -92,6 +92,7 @@ class ProfilesListView(ListAPIView): """ View to list profiles with optional filtering and ordering. """ + permission_classes = [IsStaffUser] pagination_class = ListPagination serializer_class = AdminCompanyListSerializer