diff --git a/unisportomat/quiz/pagination.py b/unisportomat/quiz/pagination.py new file mode 100644 index 0000000000000000000000000000000000000000..385a0610f6095cde89299ff5e4ebd25251083f6b --- /dev/null +++ b/unisportomat/quiz/pagination.py @@ -0,0 +1,17 @@ +""" +Adds the ability paginate content provided via REST API. +Can either be given as an argument in a model +or be given globally via settings.py. +""" + +from rest_framework.pagination import PageNumberPagination + + +class PageNumberWithPageSizePagination(PageNumberPagination): + """ + This pagination style accepts a single number page number + in the request query parameters. + SOURCE: https://github.com/bmihelac/ra-data-django-rest-framework + """ + + page_size_query_param = "page_size" diff --git a/unisportomat/unisportomat/settings.py b/unisportomat/unisportomat/settings.py index 803efec84cc414384ef995e2d8436b6e0e4fd3fa..72731568e76fd6cfe619885c283f1fb8e157354e 100644 --- a/unisportomat/unisportomat/settings.py +++ b/unisportomat/unisportomat/settings.py @@ -32,6 +32,8 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + "corsheaders", # CORS Headers should be as high as possible. + "rest_framework", # "quiz.apps.QuizConfig", "django.contrib.admin", "django.contrib.auth", @@ -39,12 +41,11 @@ INSTALLED_APPS = [ "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", - "rest_framework", - "corsheaders", "quiz", ] MIDDLEWARE = [ + "corsheaders.middleware.CorsMiddleware", # CORS Middleware should be as high as possible. "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", @@ -52,9 +53,14 @@ MIDDLEWARE = [ "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", - "corsheaders.middleware.CorsMiddleware", ] +# SOURCE: https://github.com/bmihelac/ra-data-django-rest-framework +REST_FRAMEWORK = { + "DEFAULT_PAGINATION_CLASS": "quiz.pagination.PageNumberWithPageSizePagination", + "PAGE_SIZE": 10, +} + ROOT_URLCONF = "unisportomat.urls" TEMPLATES = [