Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Pagination for quiz app #34

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions AlgoPhantomBackend/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions AlgoPhantomBackend/.idea/AlgoPhantomBackend.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions AlgoPhantomBackend/.idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions AlgoPhantomBackend/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions AlgoPhantomBackend/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions AlgoPhantomBackend/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions AlgoPhantomBackend/AlgoPhantomBackend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""

import os
from .local_settings import *
# from .local_settings import *

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -162,6 +162,6 @@
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = EMAIL_HOST_PASSWORD
# EMAIL_HOST_USER = EMAIL_HOST_USER
# EMAIL_HOST_PASSWORD = EMAIL_HOST_PASSWORD
DATA_UPLOAD_MAX_NUMBER_FIELDS = 10240
5 changes: 5 additions & 0 deletions AlgoPhantomBackend/quiz/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from rest_framework.pagination import PageNumberPagination
class QuizPagePagination(PageNumberPagination):
page_size_query_param = 'page_size'

MAX_PAGINATE_BY: 100
3 changes: 0 additions & 3 deletions AlgoPhantomBackend/quiz/tests.py

This file was deleted.

Empty file.
20 changes: 20 additions & 0 deletions AlgoPhantomBackend/quiz/tests/test_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.test import TestCase
from quiz.models import Quizzes,Category
from django.utils import timezone


# models test

class QuizTest(TestCase):


def setUp(self):
self.category = Category.objects.create(name="quiz")
self.quiz = Quizzes.objects.create(
title='quiz',
category=self.category,
)

def test_course_category(self):
quiz = Quizzes.objects.get(title='quiz')
self.assertEqual(quiz.category_id, self.category.id)
15 changes: 7 additions & 8 deletions AlgoPhantomBackend/quiz/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.shortcuts import render
from rest_framework import generics
from rest_framework.response import Response
from .models import *
from rest_framework import status
from .serializers import *
from rest_framework.generics import ListAPIView
from rest_framework.views import APIView
from .pagination import QuizPagePagination

class Quiz(generics.ListAPIView):

Expand All @@ -19,9 +20,7 @@ def get(self, request, format=None, **kwargs):
return Response(serializer.data)


class QuizQuestion(APIView):

def get(self, request, format=None, **kwargs):
quiz = Question.objects.filter(quiz__title__icontains=kwargs['topic'])
serializer = QuestionSerializer(quiz, many=True)
return Response(serializer.data)
class QuizQuestion(ListAPIView):
pagination_class = QuizPagePagination
serializer_class = QuestionSerializer
queryset = Question.objects.all()