Esempio n. 1
0
def GetModulesMobile(request, pk):
    course = Course.objects.get(id=pk)
    user = User.objects.get(id=request.user.id)
    if user.is_teacher == False:
        e = Enrollment.objects.filter(course=course, student__user=user)
        if not e:
            return Response(
                {"message": "You have not enrolled for this course"},
                status=403)
    module = Module.objects.filter(course=course).order_by('id')
    serializer = ModuleSerializer(module, many=True)

    test = []

    for mod in serializer.data:
        mod_files = ModuleFile.objects.filter(module__id=mod['id'])
        ser = ModuleFileSerializer(mod_files, many=True)
        f = find(mod['module_content'])
        tempMod = {
            'id': mod['id'],
            'module_name': mod['module_name'],
            'module_content': {
                'video_url': f,
                'content': remove(mod['module_content']),
                'files': ser.data
            },
            'is_meeting': mod['is_meeting'],
            #'type': 0,
            'course': mod['course']
        }
        test.append(tempMod)

    return Response(test)
Esempio n. 2
0
def SingleModule(request, pk):
    module = Module.objects.get(id=pk)
    if module.course.author.user.id == request.user.id:
        serializer = ModuleSerializer(module)
        return Response(serializer.data)
    else:
        return Response({"message": "you're unauthorized"}, status=403)
Esempio n. 3
0
def UpdateZoomMeeting(request, pk):
    meeting = Zoom.objects.get(id=pk)
    module = Module.objects.get(id=meeting.module.id)
    serializer = ZoomSerializer(instance=meeting, data=request.data)
    module_serializer = ModuleSerializer(instance=module, data=request.data)
    if module_serializer.is_valid():
        module_serializer.save(is_meeting=True)
    if serializer.is_valid():
        serializer.save()
    return Response(serializer.data)
Esempio n. 4
0
def CreateZoomModule(request, pk):
    course = Course.objects.get(id=pk)
    if course.author.user.id == request.user.id:
        module = Module(course=course)
        if request.method == "POST":
            serializer = ModuleSerializer(module, data=request.data)
            if serializer.is_valid():
                serializer.save(is_meeting=True)
                return Response(serializer.data)
            return Response(serializer.errors, status=500)
    return Response({"message": "you're not authorized"}, status=403)
Esempio n. 5
0
def GetModules(request, pk):
    course = Course.objects.get(id=pk)
    user = User.objects.get(id=request.user.id)
    if user.is_teacher == False:
        e = Enrollment.objects.filter(course=course, student__user=user)
        if not e:
            return Response(
                {"message": "You have not enrolled for this course"},
                status=403)
    module = Module.objects.filter(course=course).order_by('id')
    serializer = ModuleSerializer(module, many=True)
    return Response(serializer.data)
Esempio n. 6
0
def UpdateModule(request, pk):
    module = Module.objects.get(id=pk)
    serializer = ModuleSerializer(instance=module, data=request.data)
    if serializer.is_valid():
        serializer.save()
    return Response(serializer.data)