Browse Source

Add reset assignment endpoint

pull/2261/head
Hironsan 1 year ago
parent
commit
6ef85df00f
2 changed files with 16 additions and 2 deletions
  1. 3
      backend/examples/urls.py
  2. 15
      backend/examples/views/assignment.py

3
backend/examples/urls.py

@ -1,6 +1,6 @@
from django.urls import path
from .views.assignment import AssignmentDetail, AssignmentList
from .views.assignment import AssignmentDetail, AssignmentList, ResetAssignment
from .views.comment import CommentDetail, CommentList
from .views.example import ExampleDetail, ExampleList
from .views.example_state import ExampleStateList
@ -8,6 +8,7 @@ from .views.example_state import ExampleStateList
urlpatterns = [
path(route="assignments", view=AssignmentList.as_view(), name="assignment_list"),
path(route="assignments/<uuid:assignment_id>", view=AssignmentDetail.as_view(), name="assignment_detail"),
path(route="assignments/reset", view=ResetAssignment.as_view(), name="assignment_reset"),
path(route="examples", view=ExampleList.as_view(), name="example_list"),
path(route="examples/<int:example_id>", view=ExampleDetail.as_view(), name="example_detail"),
path(route="comments", view=CommentList.as_view(), name="comment_list"),

15
backend/examples/views/assignment.py

@ -1,7 +1,8 @@
from django.shortcuts import get_object_or_404
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters, generics
from rest_framework import filters, generics, status
from rest_framework.permissions import IsAuthenticated
from rest_framework.views import APIView, Response
from examples.models import Assignment
from examples.serializers import AssignmentSerializer
@ -33,3 +34,15 @@ class AssignmentDetail(generics.RetrieveUpdateDestroyAPIView):
serializer_class = AssignmentSerializer
lookup_url_kwarg = "assignment_id"
permission_classes = [IsAuthenticated & (IsProjectAdmin | IsProjectStaffAndReadOnly)]
class ResetAssignment(APIView):
permission_classes = [IsAuthenticated & IsProjectAdmin]
@property
def project(self):
return get_object_or_404(Project, pk=self.kwargs["project_id"])
def delete(self, *args, **kwargs):
Assignment.objects.filter(project=self.project).delete()
return Response(status=status.HTTP_204_NO_CONTENT)
Loading…
Cancel
Save