def add_group(self, request, pk=None): _course = get_object_or_404(Course, pk=pk) self.check_object_permissions(request, _course) serializer = AddGroupSerializer(data=request.DATA) if serializer.is_valid(): if request.FILES == {}: group = Group( course=_course, title=serializer.data['title'], description=serializer.data['description'] ) else: group = Group( course=_course, title=serializer.data['title'], description=serializer.data['description'], image=request.FILES['image'] ) group.save() _course.playlist = playlist.append(group.id, _course.playlist) _course.save() return Response(GroupSerializer(group).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def add_concept(self, request, pk=None): group = get_object_or_404(Group, pk=pk) self.check_object_permissions(request, group.course) serializer = ConceptSerializer(data=request.DATA) if serializer.is_valid(): document = Document( title='dummy', description='dummy' ) document.save() concept = Concept( group=group, title_document=document, title=serializer.data['title'], description=serializer.data['description'] ) if request.FILES != {}: concept.image = request.FILES['image'] concept.save() group.playlist = playlist.append(concept.id, group.playlist) group.save() return Response(ConceptSerializer(concept).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def add_page(self, request, pk=None): _course = get_object_or_404(Course, pk=pk) self.check_object_permissions(request, _course) serializer = DocumentSerializer(data=request.DATA) if serializer.is_valid(): document = Document(title=serializer.data['title'], is_heading=True, description=serializer.data['description']) document.save() _course.pages.add(document) _course.page_playlist = playlist.append(document.id, _course.page_playlist) _course.save() return Response(DocumentSerializer(document).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def add_page(self, request, pk=None): _course = get_object_or_404(Course, pk=pk) self.check_object_permissions(request, _course) serializer = DocumentSerializer(data=request.DATA) if serializer.is_valid(): document = Document( title=serializer.data['title'], is_heading=True, description=serializer.data['description'] ) document.save() _course.pages.add(document) _course.page_playlist = playlist.append( document.id, _course.page_playlist) _course.save() return Response(DocumentSerializer(document).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def add_section(self, request, pk=None): document = get_object_or_404(Document, pk=pk) serializer = AddSectionSerializer(data=request.DATA) if serializer.is_valid(): if request.FILES and request.FILES['file']: section = Section(document=document, title=serializer.data['title'], description=serializer.data['description'], file=request.FILES['file']) else: section = Section(document=document, title=serializer.data['title'], description=serializer.data['description']) section.save() document.playlist = playlist.append(section.id, document.playlist) document.save() return Response(SectionSerializer(section).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def add_concept(self, request, pk=None): group = get_object_or_404(Group, pk=pk) self.check_object_permissions(request, group.course) serializer = ConceptSerializer(data=request.DATA) if serializer.is_valid(): document = Document(title='dummy', description='dummy') document.save() concept = Concept(group=group, title_document=document, title=serializer.data['title'], description=serializer.data['description']) if request.FILES != {}: concept.image = request.FILES['image'] concept.save() group.playlist = playlist.append(concept.id, group.playlist) group.save() return Response(ConceptSerializer(concept).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def add_group(self, request, pk=None): _course = get_object_or_404(Course, pk=pk) self.check_object_permissions(request, _course) serializer = AddGroupSerializer(data=request.DATA) if serializer.is_valid(): if request.FILES == {}: group = Group(course=_course, title=serializer.data['title'], description=serializer.data['description']) else: group = Group(course=_course, title=serializer.data['title'], description=serializer.data['description'], image=request.FILES['image']) group.save() _course.playlist = playlist.append(group.id, _course.playlist) _course.save() return Response(GroupSerializer(group).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)
def add_section(self, request, pk=None): document = get_object_or_404(Document, pk=pk) serializer = AddSectionSerializer(data=request.DATA) if serializer.is_valid(): if request.FILES and request.FILES['file']: section = Section( document=document, title=serializer.data['title'], description=serializer.data['description'], file=request.FILES['file']) else: section = Section( document=document, title=serializer.data['title'], description=serializer.data['description']) section.save() document.playlist = playlist.append(section.id, document.playlist) document.save() return Response(SectionSerializer(section).data) else: content = serializer.errors return Response(content, status.HTTP_400_BAD_REQUEST)