Skip to content

Commit

Permalink
companies stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewakiv committed Dec 5, 2024
1 parent 2fca8d1 commit 680e7d7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
22 changes: 22 additions & 0 deletions BackEnd/administration/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.auth import get_user_model
from django.db.models import Q
from rest_framework import serializers
from utils.administration.feedback_category import FeedbackCategory
from authentication.models import CustomUser
Expand Down Expand Up @@ -213,3 +214,24 @@ class FeedbackSerializer(serializers.Serializer):
required=True,
error_messages={"required": "Please select a category."},
)


class StatisticsSerializer(serializers.Serializer):
companies_count = serializers.SerializerMethodField()
investors_count = serializers.SerializerMethodField()
startups_count = serializers.SerializerMethodField()
blocked_companies_count = serializers.SerializerMethodField()

def get_companies_count(self, obj) -> int:
return Profile.objects.filter(
Q(is_registered=True) | Q(is_startup=True)
).count()

def get_investors_count(self, obj) -> int:
return Profile.objects.filter(is_registered=True).count()

def get_startups_count(self, obj) -> int:
return Profile.objects.filter(is_startup=True).count()

def get_blocked_companies_count(self, obj) -> int:
return Profile.objects.filter(status='blocked').count()
6 changes: 6 additions & 0 deletions BackEnd/administration/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ContactsView,
ProfilesListView,
ProfileDetailView,
ProfileStatisticsView,
UsersListView,
UserDetailView,
AutoModerationHoursView,
Expand All @@ -19,6 +20,11 @@
path("users/<pk>/", UserDetailView.as_view(), name="user-detail"),
path("profiles/", ProfilesListView.as_view(), name="profile-list"),
path("profiles/<pk>/", ProfileDetailView.as_view(), name="profile-detail"),
path(
"companies/satistics/",
ProfileStatisticsView.as_view(),
name="profile-satistics",
),
path(
"automoderation/",
AutoModerationHoursView.as_view(),
Expand Down
35 changes: 35 additions & 0 deletions BackEnd/administration/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.http import JsonResponse
from django.views import View
from django.db.models import Q
from drf_spectacular.utils import (
extend_schema,
OpenApiExample,
Expand All @@ -8,6 +9,7 @@

from rest_framework.generics import (
ListAPIView,
RetrieveAPIView,
RetrieveUpdateDestroyAPIView,
RetrieveUpdateAPIView,
CreateAPIView,
Expand All @@ -22,6 +24,7 @@
AdminUserDetailSerializer,
AutoModerationHoursSerializer,
ModerationEmailSerializer,
StatisticsSerializer,
)
from administration.pagination import ListPagination
from administration.models import AutoModeration, ModerationEmail
Expand All @@ -34,6 +37,8 @@
from django_filters.rest_framework import DjangoFilterBackend
from .filters import UsersFilter

from rest_framework.permissions import AllowAny


class UsersListView(ListAPIView):
"""
Expand Down Expand Up @@ -104,6 +109,36 @@ class ProfileDetailView(RetrieveUpdateDestroyAPIView):
)


class ProfileStatisticsView(RetrieveAPIView):
"""
Count of companies
"""
queryset = Profile.objects.all()
permission_classes = [AllowAny]
serializer_class = StatisticsSerializer

def get_object(self):
return {}

# def get_serializer_context(self):
# context = super().get_serializer_context()
# context["companies_count"] = (
# self.get_queryset()
# .filter(Q(is_registered=True) | Q(is_startup=True))
# .count()
# )
# context["investors_count"] = (
# self.get_queryset().filter(is_registered=True).count()
# )
# context["startups_count"] = (
# self.get_queryset().filter(is_startup=True).count()
# )
# context["blocked_companies_count"] = (
# self.get_queryset().filter(status='blocked').count()
# )
# return context


@extend_schema(
request=AutoModerationHoursSerializer,
responses={
Expand Down

0 comments on commit 680e7d7

Please sign in to comment.