Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1003 admin backend management with search and filter capabilities #1026

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
19fc399
Added additional fields to admin company list serializer
AlexanderSychev2005 Dec 7, 2024
a64bf61
Added additional fields to admin company list serializer
AlexanderSychev2005 Dec 7, 2024
1ff0cd4
Added company type field to profiles serializer
AlexanderSychev2005 Dec 7, 2024
dfdc738
Deleted is_fop and is_startup from the profiles serializer
AlexanderSychev2005 Dec 7, 2024
6db21f0
Added read_only to field "company_type" profiles serializer
AlexanderSychev2005 Dec 7, 2024
acf85d0
Added categories to the companies' serializer
AlexanderSychev2005 Dec 7, 2024
35598ac
Added representative field to AdminCompanyListSerializer
AlexanderSychev2005 Dec 8, 2024
73b1774
Added representative field to AdminCompanyListSerializer
AlexanderSychev2005 Dec 8, 2024
973298a
Added representative field to AdminCompanyListSerializer
AlexanderSychev2005 Dec 8, 2024
906e94c
Updated view for profiles admin
AlexanderSychev2005 Dec 12, 2024
2e48023
Updated filter for profiles admin
AlexanderSychev2005 Dec 12, 2024
536939b
Fixed company type admin company list serializer
AlexanderSychev2005 Dec 12, 2024
08c3d86
Fixed activities admin company list serializer
AlexanderSychev2005 Dec 12, 2024
dd88d58
Added business entity
AlexanderSychev2005 Dec 12, 2024
fc649e4
Added search functionality to profiles and users backend
AlexanderSychev2005 Dec 13, 2024
ac8d326
deleted unnecessary search functionality backend admin panel
AlexanderSychev2005 Dec 18, 2024
4620bb3
Reformated backend profiles admin
AlexanderSychev2005 Dec 18, 2024
eb01628
Adjusted profiles filter administration
AlexanderSychev2005 Dec 18, 2024
8e62d95
Adjusted users filter administration
AlexanderSychev2005 Dec 18, 2024
100b5b8
Adjusted AdminCompanyListSerializer
AlexanderSychev2005 Dec 18, 2024
4194979
Renamed methods in AdminCompanyListSerializer
AlexanderSychev2005 Dec 18, 2024
2ca7879
Merge branch 'refs/heads/develop' into 1003-admin-backend-management-…
AlexanderSychev2005 Dec 19, 2024
a815061
Deleted repetitive representative functional admin profiles serializer
AlexanderSychev2005 Dec 20, 2024
dc6b835
Deleted unuseful fields admin profiles serializer
AlexanderSychev2005 Dec 20, 2024
3540e78
Worked with serializer and renamed module name in profiles
AlexanderSychev2005 Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions BackEnd/administration/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 is_deleted_filter(self, queryset, name, value):
Expand All @@ -45,6 +45,39 @@ def is_deleted_filter(self, queryset, name, value):
)


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()
updated_at = filters.DateFilter()

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"),
)
)


class CategoriesFilter(FilterSet):
id = filters.NumberFilter(lookup_expr="contains")
name = filters.CharFilter(lookup_expr="icontains")
Expand Down
36 changes: 28 additions & 8 deletions BackEnd/administration/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from authentication.models import CustomUser
from profiles.models import (
Profile,
Region,
Region, Activity,
Category,
)
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
Expand All @@ -24,6 +25,15 @@ class Meta:
)


class ActivitiesSerializer(serializers.ModelSerializer):
class Meta:
model = Activity
fields = (
"id",
"name",
)


class AdminRegistrationSerializer(serializers.Serializer):
email = serializers.EmailField(
write_only=True,
Expand Down Expand Up @@ -107,25 +117,35 @@ 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)
business_entity = serializers.SerializerMethodField(read_only=True)

class Meta:
model = Profile
fields = (
"id",
"name",
"is_registered",
"is_startup",
"person",
"person_position",
"regions",
"official_name",
"business_entity",
"phone",
"edrpou",
"address",
"status",
"updated_at",
"created_at",
"is_deleted",
"company_type",
"activities",
"representative",
)

def get_company_type(self, obj) -> str:
return format_company_type(obj)

def get_business_entity(self, obj) -> str:
return format_business_entity(obj)


class AdminCompanyDetailSerializer(serializers.ModelSerializer):
person = AdminUserDetailSerializer(read_only=True)
Expand Down
17 changes: 14 additions & 3 deletions BackEnd/administration/views.py
Original file line number Diff line number Diff line change
@@ -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 django.db.models import Count, Q
Expand Down Expand Up @@ -39,7 +41,7 @@
from utils.administration.send_email_feedback import send_email_feedback

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

Expand Down Expand Up @@ -88,16 +90,25 @@ 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]
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(),
)
)
)


Expand Down
20 changes: 20 additions & 0 deletions BackEnd/utils/administration/profiles/profiles_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def format_company_type(obj):
if obj.is_startup and obj.is_registered:
return "Компанія і стартап"
if obj.is_registered:
return "Компанія"
if obj.is_startup:
return "Стартап"
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 "ФОП"
return "Юридична особа"
Loading