Beispiel #1
0
def ViewSubject(request, pk):
    subject = Subject.objects.get(id=pk)
    if subject.author.user.id == request.user.id:
        serializer = SubjectSerializer(subject)
        return Response(serializer.data)
    else:
        return Response({"message": "you're unauthorized"}, status=403)
Beispiel #2
0
def SubjectListIndex(request):
    subjects = Subject.objects.all()
    paginator = PageNumberPagination()
    paginator.page_size = 10
    result_page = paginator.paginate_queryset(subjects, request)
    serializer = SubjectSerializer(result_page, many=True)
    for i in range(len(serializer.data)):
        serializer.data[i]['author']['user'].pop('password')
    return paginator.get_paginated_response(serializer.data)
Beispiel #3
0
def MySubjects(request):
    student = StudentProfile.objects.get(user_id=request.user.id)
    courses_enrolled = Enrollment.objects.filter(
        student=student).order_by('-id')
    subjects = []
    for c in courses_enrolled:
        if c.course.subject not in subjects:
            subjects.append(c.course.subject)
    serializer = SubjectSerializer(subjects, many=True)
    for i in range(len(serializer.data)):
        serializer.data[i]['author']['user'].pop('password')
    return Response(serializer.data)
Beispiel #4
0
def TeacherSubject(request):
    teacher = TeacherProfile.objects.get(user_id=request.user.id)
    subject = Subject.objects.filter(author=teacher).order_by('-id')
    print(subject)
    filterset = SubjectFilter(request.GET, queryset=subject)
    if filterset.is_valid():
        queryset = filterset.qs
    paginator = PageNumberPagination()
    paginator.page_size = 5
    result_page = paginator.paginate_queryset(queryset, request)
    serializer = SubjectSerializer(result_page, many=True)
    for i in range(len(serializer.data)):
        serializer.data[i]['author']['user'].pop('password')
    return paginator.get_paginated_response(serializer.data)
Beispiel #5
0
def LatestSubjects(request):
    subjects = Subject.objects.order_by("-id")[:3]
    serializer = SubjectSerializer(subjects, many=True)
    for i in range(len(serializer.data)):
        serializer.data[i]['author']['user'].pop('password')
    return Response(serializer.data)
Beispiel #6
0
def UpdateSubject(request, pk):
    subject = Subject.objects.get(id=pk)
    serializer = SubjectSerializer(instance=subject, data=request.data)
    if serializer.is_valid():
        serializer.save()
    return Response(serializer.data)
Beispiel #7
0
def ViewSubjectStudent(request, pk):
    subject = Subject.objects.get(id=pk)
    serializer = SubjectSerializer(subject)
    return Response(serializer.data)
Beispiel #8
0
def CreateSubject(request, pk):
    author = TeacherProfile.objects.get(user_id=pk)
    serializer = SubjectSerializer(data=request.data)
    if serializer.is_valid():
        serializer.save(author=author)
    return Response(serializer.data)