Skip to content

Commit fd86f08

Browse files
committed
fix custom view implementation for class choices
1 parent 34e4c29 commit fd86f08

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

core/urls.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@
7676
path('projects/<uuid:pk>/join/', views.ProjectViewSet.as_view({'post': 'join'}), name='project-join'),
7777
path('projects/<uuid:pk>/impacts/', views.ProjectViewSet.as_view({'get': 'impacts'}), name='project-impacts'),
7878
path('projects/<uuid:project_id>/add-class/<uuid:class_id>/', views.add_class_to_project, name='add-class-to-project'),
79-
80-
# =================================================================
81-
# CUSTOM CLASS ENDPOINTS
82-
# =================================================================
83-
path('classes/class-choices/', views.get_class_choices, name='class-choices'),
8479

8580
# =================================================================
8681
# CUSTOM SCHOOL ENDPOINTS

core/views.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Handles all REST API endpoints for the application
44
"""
55

6+
import logging
67
from django.shortcuts import get_object_or_404
78
from django.contrib.auth import authenticate
89
from django.db.models import Count, Sum, Q
@@ -49,10 +50,11 @@
4950
CanManageProjectParticipants, CanUploadProjectProgress
5051
)
5152
from .filters import ProjectFilter, SchoolFilter, EnvironmentalImpactFilter
52-
from rest_framework.permissions import AllowAny
5353
from rest_framework import serializers
5454
from rest_framework.exceptions import PermissionDenied
5555

56+
logger = logging.getLogger(__name__)
57+
5658

5759
# =============================================================================
5860
# AUTHENTICATION & LOGIN VIEWS (Grouped at the top for clarity)
@@ -397,6 +399,15 @@ class ClassViewSet(viewsets.ModelViewSet):
397399
filterset_fields = ['school']
398400
search_fields = ['name']
399401

402+
@action(detail=False, methods=['get'], url_path='class-choices')
403+
def class_choices(self, request):
404+
"""Return available class name choices"""
405+
choices = [
406+
{"value": choice[0], "label": choice[1]}
407+
for choice in Class.ClassName.choices
408+
]
409+
return Response(choices)
410+
400411

401412
# =============================================================================
402413
# PROFILE VIEWSETS
@@ -1249,15 +1260,4 @@ def check_school_exists(request):
12491260
})
12501261

12511262

1252-
@api_view(['GET'])
1253-
@permission_classes([permissions.AllowAny])
1254-
def get_class_choices(request):
1255-
"""Return available class name choices"""
1256-
choices = [
1257-
{"value": choice[0], "label": choice[1]}
1258-
for choice in Class.ClassName.choices
1259-
]
1260-
return Response(choices)
1261-
1262-
12631263
from .additional_views import *

0 commit comments

Comments
 (0)