diff --git a/unisportomat/quiz/pagination.py b/unisportomat/quiz/pagination.py index 4c97001168db739fd930f158b0452d2009681cf1..56b16cfd1f4f58694ad268f00b5725bd6620b242 100644 --- a/unisportomat/quiz/pagination.py +++ b/unisportomat/quiz/pagination.py @@ -1,36 +1,8 @@ -from collections import OrderedDict -from rest_framework.response import Response from rest_framework.pagination import PageNumberPagination -class ReactAdminPagination(PageNumberPagination): - page_query_param = "page" - page_size_query_param = "perPage" - - def get_paginated_response(self, data): - count = self.page.paginator.count - item_starting_index = self.page.start_index() - 1 - item_ending_index = self.page.end_index() - 1 - - content_range = "items {0}-{1}/{2}".format( - item_starting_index, item_ending_index, count - ) - - # headers = {"Content-Range": content_range} - headers = {"x-total-count": count} - - return Response( - OrderedDict( - [ - ("x-total-count", count), - ("next", self.get_next_link()), - ("previous", self.get_previous_link()), - ("results", data), - ] - ), - headers=headers, - ) - - class PageNumberWithPageSizePagination(PageNumberPagination): page_size_query_param = "page_size" + + +# SOURCE: https://github.com/bmihelac/ra-data-django-rest-framework diff --git a/unisportomat/unisportomat/settings.py b/unisportomat/unisportomat/settings.py index 1850ecff69f816c509dfa187f65f780b8b2e4659..9360de8f778422b5830dcf6928928035ff320469 100644 --- a/unisportomat/unisportomat/settings.py +++ b/unisportomat/unisportomat/settings.py @@ -3,7 +3,7 @@ Django settings for unisportomat project. Generated by 'django-admin startproject' using Django 3.2. -For more information on this file, see +For more information on this file, see https://docs.djangoproject.com/en/3.2/topics/settings/ For the full list of settings and their values, see @@ -32,7 +32,7 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ - "corsheaders", + "corsheaders", # CORS Headers should be as high as possible. "rest_framework", # "quiz.apps.QuizConfig", "django.contrib.admin", @@ -45,7 +45,7 @@ INSTALLED_APPS = [ ] MIDDLEWARE = [ - "corsheaders.middleware.CorsMiddleware", + "corsheaders.middleware.CorsMiddleware", # CORS Middleware should be as high as possible. "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", @@ -55,18 +55,7 @@ MIDDLEWARE = [ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] -# CORS_ALLOW_HEADERS = [ -# "x-total-count", -# "accept-encoding", -# "authorization", -# "content-type", -# "dnt", -# "origin", -# "user-agent", -# "x-csrftoken", -# "x-requested-with", -# ] - +# SOURCE: https://github.com/bmihelac/ra-data-django-rest-framework REST_FRAMEWORK = { "DEFAULT_PAGINATION_CLASS": "quiz.pagination.PageNumberWithPageSizePagination", "PAGE_SIZE": 10,