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 9e0c49184f1e8757abc5028a695ad2c5eb9c5fdb..e41e8870fef01befcb256039eca5ed9ace7164a1 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", "modeltranslation", # Needs to be before django.contrib.admin because Admin Panel won't work otherwise "django.contrib.admin", @@ -40,12 +42,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", @@ -53,10 +54,15 @@ MIDDLEWARE = [ "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", - "corsheaders.middleware.CorsMiddleware", "django.middleware.locale.LocaleMiddleware", ] +# 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 = [ @@ -143,7 +149,7 @@ STATIC_URL = "/static/" DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" -CORS_ORITIN_WHITELIST = [ +CORS_ORIGIN_WHITELIST = [ "http://localhost:3000", # User Frontend "http://localhost:4000", # Admin Frontend ]