Commit 26782fbf authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Add view to get MyCourses info

parent 7d4d6446
...@@ -8,6 +8,7 @@ from .views import ( ...@@ -8,6 +8,7 @@ from .views import (
ProfessorMessageViewSet, ProfessorMessageViewSet,
ProfessorMessageReadViewSet, ProfessorMessageReadViewSet,
ProfessorGlobalMessageViewSet, ProfessorGlobalMessageViewSet,
MyCoursesViewSet
) )
from .course_material.views import CourseMaterialViewSet, CourseMaterialFileViewSet from .course_material.views import CourseMaterialViewSet, CourseMaterialFileViewSet
from .import_export.views import ExportCourseView, ImportCourseView from .import_export.views import ExportCourseView, ImportCourseView
...@@ -40,6 +41,7 @@ from courses.stats.views import ( ...@@ -40,6 +41,7 @@ from courses.stats.views import (
router = routers.SimpleRouter(trailing_slash=False) router = routers.SimpleRouter(trailing_slash=False)
router.register(r'course', CourseViewSet, base_name='course') router.register(r'course', CourseViewSet, base_name='course')
router.register(r'my-courses', MyCoursesViewSet, base_name='my-courses')
router.register(r'course_material', CourseMaterialViewSet, base_name='course_material') router.register(r'course_material', CourseMaterialViewSet, base_name='course_material')
router.register(r'course_material_file', CourseMaterialFileViewSet, base_name='course_material_file') router.register(r'course_material_file', CourseMaterialFileViewSet, base_name='course_material_file')
......
...@@ -7,7 +7,7 @@ from rest_framework.response import Response ...@@ -7,7 +7,7 @@ from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import list_route from rest_framework.decorators import list_route
from .models import (Course, CourseProfessor, ProfessorMessage, ProfessorMessageRead, Class) from .models import (Course, CourseProfessor, CourseStudent, ProfessorMessage, ProfessorMessageRead, Class)
from .serializers import (CourseSerializer, BasicCourseProfessorSerializer, from .serializers import (CourseSerializer, BasicCourseProfessorSerializer,
ProfessorMessageSerializer, ProfessorMessageReadSerializer, ProfessorMessageSerializer, ProfessorMessageReadSerializer,
) )
...@@ -95,6 +95,22 @@ class CourseViewSet(viewsets.ModelViewSet): ...@@ -95,6 +95,22 @@ class CourseViewSet(viewsets.ModelViewSet):
return data return data
class MyCoursesViewSet(viewsets.ModelViewSet):
model = Course
queryset = Course.objects.all()
serializer_class = CourseSerializer
permission_classes = (IsProfessorCoordinatorOrAdminPermissionOrReadOnly,)
def get_queryset(self):
queryset = super(MyCoursesViewSet, self).get_queryset()
user = self.request.user
course_students = CourseStudent.objects.filter(user__id=user.id).prefetch_related('course')
courses_id = list(course_students.values_list('course__id', flat=True))
queryset = self.queryset.filter(id__in=courses_id)
return queryset
class BaseCourseProfessorViewSet(viewsets.ModelViewSet): class BaseCourseProfessorViewSet(viewsets.ModelViewSet):
model = CourseProfessor model = CourseProfessor
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment