Skip to content

Commit

Permalink
Add public methods in admin and staff permission , Feat : Add KPI stats
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Oct 15, 2024
1 parent 5c6d632 commit da9eddf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions backend/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
UsersView,
download_training_data,
geojson2osmconverter,
get_kpi_stats,
publish_training,
run_task_status,
)
Expand Down Expand Up @@ -73,6 +74,7 @@
"workspace/download/<path:lookup_dir>/", TrainingWorkspaceDownloadView.as_view()
),
path("workspace/<path:lookup_dir>/", TrainingWorkspaceView.as_view()),
path("kpi/stats/", get_kpi_stats, name="get_kpi_stats"),
]
if settings.ENABLE_PREDICTION_API:
urlpatterns.append(path("prediction/", PredictionView.as_view()))
21 changes: 19 additions & 2 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,23 @@ class BannerViewSet(viewsets.ModelViewSet):

def get_queryset(self):
now = timezone.now()
return Banner.objects.filter(is_active=True, start_date__lte=now).filter(
return Banner.objects.filter(start_date__lte=now).filter(
end_date__gte=now
) | Banner.objects.filter(is_active=True, end_date__isnull=True)
) | Banner.objects.filter(end_date__isnull=True)


@api_view(["GET"])
def get_kpi_stats(request):
total_models_with_status_published = Model.objects.filter(status=0).count()
total_registered_users = OsmUser.objects.count()
total_approved_predictions = ApprovedPredictions.objects.count()
total_feedback_labels = FeedbackLabel.objects.count()

data = {
"total_models_published": total_models_with_status_published,
"total_registered_users": total_registered_users,
"total_accepted_predictions": total_approved_predictions,
"total_feedback_labels": total_feedback_labels,
}

return Response(data)
6 changes: 6 additions & 0 deletions backend/login/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ def has_object_permission(self, request, view, obj):

class IsAdminUser(permissions.BasePermission):
def has_permission(self, request, view):
public_methods = getattr(view, "public_methods", [])
if request.method in public_methods:
return True
return (
request.user and request.user.is_authenticated and request.user.is_superuser
)


class IsStaffUser(permissions.BasePermission):
def has_permission(self, request, view):
public_methods = getattr(view, "public_methods", [])
if request.method in public_methods:
return True
return request.user and request.user.is_authenticated and request.user.is_staff

0 comments on commit da9eddf

Please sign in to comment.