Commit aa9a225a authored by Matheus Miranda's avatar Matheus Miranda
Browse files

Merge branch 'develop' into 'master'

bring CourseAuthors code from legacy app

See merge request !71
parents 299aa66a 219a8ae5
......@@ -11,7 +11,8 @@ from .models import (
CourseTrack,
CourseStudent,
Unit,
Lesson
Lesson,
CourseAuthor,
)
from .certification.models import CertificateTemplate
......@@ -253,3 +254,33 @@ class LessonSerializer(serializers.ModelSerializer):
unit.activities.set(activities)
units.append(unit)
return units
class CourseAuthorSerializer(serializers.ModelSerializer):
user_info = SimpleUserSerializer(source='user', read_only=True)
# TODO Verificar se precisa mesmo desse course_info aqui, pois ele tem muitas infos
course_info = CourseSerializer(source='course', read_only=True)
class Meta:
fields = (
'id',
'course',
'course_info',
'name',
'get_name',
'biography',
'get_biography',
'picture',
'get_picture_url',
'user_info',
'user',
'position',
)
model = CourseAuthor
class CourseAuthorPictureSerializer(serializers.ModelSerializer):
class Meta:
fields = ('id', 'picture',)
model = CourseAuthor
......@@ -9,7 +9,11 @@ from .views import (
ProfessorMessageViewSet,
ProfessorMessageReadViewSet,
ProfessorGlobalMessageViewSet,
MyCoursesViewSet, LessonViewSet
MyCoursesViewSet,
LessonViewSet,
CourseAuthorViewSet,
CoursePictureUploadViewSet,
)
from .course_material.views import CourseMaterialViewSet, CourseMaterialFileViewSet
from .import_export.views import ExportCourseView, ImportCourseView
......
......@@ -8,11 +8,19 @@ from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import list_route
from .models import (Course, CourseProfessor, CourseStudent, ProfessorMessage,
ProfessorMessageRead, Class, Lesson)
from .serializers import (CourseSerializer, BasicCourseProfessorSerializer,
ProfessorMessageSerializer, ProfessorMessageReadSerializer,
LessonSerializer)
ProfessorMessageRead, Class, Lesson,
CourseAuthor,
)
from .serializers import (
CourseSerializer,
BasicCourseProfessorSerializer,
ProfessorMessageSerializer,
ProfessorMessageReadSerializer,
LessonSerializer,
CourseAuthorSerializer,
CourseAuthorPictureSerializer,
)
from courses.workspaces.serializers import CourseGroupSerializer
......@@ -282,3 +290,35 @@ class LessonViewSet(viewsets.ModelViewSet):
queryset = super(LessonViewSet, self).get_queryset()
course_id = self.kwargs['course_id']
return queryset.filter(status='published', course_id=course_id)
class CourseAuthorViewSet(viewsets.ModelViewSet):
model = CourseAuthor
queryset = CourseAuthor.objects.all()
lookup_field = 'id'
filter_fields = ('course', 'user',)
serializer_class = CourseAuthorSerializer
permission_classes = (IsProfessorCoordinatorOrAdminPermissionOrReadOnly, )
def pre_save(self, obj):
# Verify if current user is coordinator. The has_object_permission method is not called when creating objects,
# so we call it explicitly here. See: https://github.com/tomchristie/django-rest-framework/issues/1103
self.check_object_permissions(self.request, obj)
return super(CourseAuthorViewSet, self).pre_save(obj)
class CoursePictureUploadViewSet(viewsets.ModelViewSet):
model = CourseAuthor
queryset = CourseAuthor.objects.all()
lookup_field = 'id'
serializer_class = CourseAuthorPictureSerializer
def post(self, request, **kwargs):
course = self.get_object()
serializer = self.get_serializer(course, request.FILES)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=200)
else:
return Response(serializer.errors, status=400)
\ No newline at end of file
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