import - quotas dashbopard by product / quotas list by product
This commit is contained in:
@@ -15,6 +15,7 @@ from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||
from apps.core.pagination import CustomPageNumberPagination
|
||||
from apps.product import models as product_models
|
||||
from apps.product.exceptions import QuotaExpiredTimeException
|
||||
from apps.product.models import OrganizationQuotaStats
|
||||
from apps.product.services.quota_dashboard_service import QuotaDashboardService
|
||||
from apps.product.web.api.v1.serializers import quota_distribution_serializers
|
||||
from apps.product.web.api.v1.serializers import quota_serializers
|
||||
@@ -381,6 +382,66 @@ class QuotaViewSet(BaseViewSet, SoftDeleteMixin, QuotaDashboardService, viewsets
|
||||
|
||||
return Response(quota_dashboard)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=False,
|
||||
url_path='quotas_dashboard_by_product',
|
||||
url_name='quotas_dashboard_by_product',
|
||||
name='quotas_dashboard_by_product'
|
||||
)
|
||||
def quotas_dashboard_by_product(self, request):
|
||||
"""
|
||||
dashboard of all quotas & their information
|
||||
"""
|
||||
|
||||
org = get_organization_by_user(request.user)
|
||||
query_param = self.request.query_params # noqa
|
||||
|
||||
# filter by date
|
||||
start_date = query_param.get('start') if 'start' in query_param.keys() else None
|
||||
end_date = query_param.get('end') if 'end' in query_param.keys() else None
|
||||
|
||||
# get organization quota stats and get product ids
|
||||
org_quota_stat = OrganizationQuotaStats.objects.select_related('organization', 'quota').filter(
|
||||
organization=org
|
||||
) if not org.type.key == 'ADM' else OrganizationQuotaStats.objects.select_related('organization', 'quota').all()
|
||||
|
||||
products = {f'{stat.quota.product.name}': stat.quota.product.id for stat in org_quota_stat}
|
||||
|
||||
dashboard_data_by_product = self.get_dashboard_by_product(self, org, products)
|
||||
|
||||
return Response(dashboard_data_by_product)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=True,
|
||||
url_path='org_quota_stats_by_product',
|
||||
url_name='org_quota_stats_by_product',
|
||||
name='org_quota_stats_by_product'
|
||||
)
|
||||
def org_quota_stats_by_product(self, request, pk=None):
|
||||
"""
|
||||
list of quotas by product
|
||||
"""
|
||||
org = get_organization_by_user(request.user)
|
||||
query_param = self.request.query_params # noqa
|
||||
|
||||
# filter by date
|
||||
start_date = query_param.get('start') if 'start' in query_param.keys() else None
|
||||
end_date = query_param.get('end') if 'end' in query_param.keys() else None
|
||||
|
||||
queryset = self.filter_query(
|
||||
self.get_queryset(visibility_by_org_scope=True).filter(
|
||||
is_closed=False)) # return by search param or all objects
|
||||
|
||||
# paginate queryset
|
||||
page = self.paginate_queryset(
|
||||
queryset.filter(product_id=pk).order_by('-modify_date')
|
||||
)
|
||||
if page is not None: # noqa
|
||||
serializer = self.get_serializer(page, many=True, context={'org': org})
|
||||
return self.get_paginated_response(serializer.data)
|
||||
|
||||
@action(
|
||||
methods=['get'],
|
||||
detail=False,
|
||||
|
||||
Reference in New Issue
Block a user