Example #1
0
 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)
Example #2
0
 def add_existing_quiz(self, request, pk=None):
     concept = get_object_or_404(Concept, pk=pk)
     self.check_object_permissions(request, concept.group.course)
     quiz = get_object_or_404(Quiz, int(request.DATA['pk']))
     concept.playlist = typed_playlist.append(quiz.id, concept.playlist, 1)
     concept.quizzes.add(quiz)
     concept.save()
     return Response(ConceptSerializer(concept).data)
Example #3
0
 def add_existing_document(self, request, pk=None):
     concept = get_object_or_404(Concept, pk=pk)
     self.check_object_permissions(request, concept.group.course)
     document = get_object_or_404(Document, int(request.DATA['pk']))
     concept.playlist = typed_playlist.append(document.id, concept.playlist,
                                              2)
     concept.pages.add(document)
     concept.save()
     return Response(ConceptSerializer(concept).data)
Example #4
0
 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)
Example #5
0
 def concepts(self, request, pk=None):
     """
         Function to get all the concepts in a course
     """
     group = get_object_or_404(Group, pk=pk)
     self.check_object_permissions(request=request, obj=group.course)
     concepts = Concept.objects.filter(group=group)
     serializer = ConceptSerializer(concepts, many=True)
     if len(serializer.data) == 0:
         return Response([])
     _playlist = playlist.to_array(group.playlist)
     N = len(_playlist)
     ordered_data = [""] * N
     for i in range(N):
         ordered_data[i] = serializer.data[_playlist[i][1]]
     return Response(ordered_data)
Example #6
0
 def published_concepts(self, request, pk=None):
     """
         Function to get all the concepts in a course
     """
     group = get_object_or_404(Group, pk=pk)
     self.check_object_permissions(request=request, obj=group.course)
     concepts = Concept.objects.filter(group=group)
     _playlist = playlist.to_array(group.playlist)
     N = len(_playlist)
     ordered_data = []
     for i in range(N):
         concept = concepts[_playlist[i][1]]
         if concept.is_published:
             #  TODO: check if append does not take O(n) time
             ordered_data.append(concept)
     serializer = ConceptSerializer(ordered_data, many=True)
     return Response(serializer.data)
Example #7
0
 def delete_element(self, request, pk=None):
     concept = get_object_or_404(Concept, pk=pk)
     self.check_object_permissions(request, concept.group.course)
     _id = int(request.DATA['id'])
     _type = int(request.DATA['type'])
     print "old playlist was : ", concept.playlist
     print "will delete ", _id, " ", _type
     new_playlist = typed_playlist.delete(concept.playlist, _id, _type)
     print "new plalist is : ", new_playlist
     if new_playlist is not False:
         concept.playlist = new_playlist
         if _type == 0:
             self.remove_video(concept, _id)
         elif _type == 1:
             self.remove_quiz(concept, _id)
         elif _type == 2:
             self.remove_document(concept, _id)
         concept.save()
     return Response(ConceptSerializer(concept).data)
Example #8
0
 def add_element(self, request, pk=None):
     concept = get_object_or_404(Concept, pk=pk)
     self.check_object_permissions(request, concept.group.course)
     concept.playlist.append()
     return Response(ConceptSerializer(concept))