def put(self, request, assignment_id,format=None): assignment = self.get_object(assignment_id) serializer = AssignmentSerializer(assignment, data=request.DATA) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def delete_course_assignment(self, request, pk=None): course = self.get_object() title = request.data.get('title') # Buscar assignments por título # TODO: Filtrar por fecha de creación for assignment in Assignment.objects.filter(title=title, course=course).all(): assignment.delete() return Response(AssignmentSerializer(assignment).data)
def create_course_assignment(self, request, pk=None): course = self.get_object() for enrollment in course.enrollment_set.all(): assignment = enrollment.student.assignment_set.create( title=request.data.get('title'), description=request.data.get('description'), deadline=request.data.get('deadline'), assignment_file=request.data.get('assignment_file'), course=course) return Response(AssignmentSerializer(assignment).data)
def update_course_assignment(self, request, pk=None): course = self.get_object() title = request.data.get('title') # Buscar assignments por título # TODO: Filtrar por fecha de creación Assignment.objects.filter(title=title, course=course).update( title=request.data.get('title'), description=request.data.get('description'), score=request.data.get('score'), deadline=request.data.get('deadline'), assignment_file=request.data.get('assignment_file'), course=request.data.get('course')) for assignment in Assignment.objects.filter(title=title, course=course).all(): assignment.save() return Response(AssignmentSerializer(assignment).data)
def post(self, request, format=None): serializer = AssignmentSerializer(data=request.DATA) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) def put(self, request, assignment_id,format=None): assignment = self.get_object(assignment_id) serializer = AssignmentSerializer(assignment, data=request.DATA) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) def delete(self, request, assignment_id, format=None): assignment = self.get_object(assignment_id) assignment.delete() return Response(status=status.HTTP_204_NO_CONTENT)
def assignments(self, request, pk=None): course = self.get_object() queryset = course.assignment_set.all() assignments = AssignmentSerializer(queryset, many=True).data return Response(assignments)
def get(self, request, format=None): assignments = Assignment.object.all() serializer = AssignmentSerializer(assignments, many=True)