Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Backend
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
swp-unisport
team-warumkeinrust
Backend
Commits
6888f31c
Commit
6888f31c
authored
3 years ago
by
borzechof99
Browse files
Options
Downloads
Patches
Plain Diff
Fixes Pagination for react-admin to get data
Co-authored-by:
Dominik Pietrak
<
dominip89@mi.fu-berlin.de
>
parent
4b80bd61
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
unisportomat/quiz/pagination.py
+3
-31
3 additions, 31 deletions
unisportomat/quiz/pagination.py
unisportomat/unisportomat/settings.py
+4
-15
4 additions, 15 deletions
unisportomat/unisportomat/settings.py
with
7 additions
and
46 deletions
unisportomat/quiz/pagination.py
+
3
−
31
View file @
6888f31c
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
This diff is collapsed.
Click to expand it.
unisportomat/unisportomat/settings.py
+
4
−
15
View file @
6888f31c
...
...
@@ -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
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment