Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GraceDB Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Michael Coughlin
GraceDB Server
Commits
468cdac9
Commit
468cdac9
authored
6 years ago
by
Tanner Prestegard
Committed by
GraceDB
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
updating pagination
parent
6033463e
No related branches found
Branches containing commit
Tags
gracedb-2.31.0
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gracedb/superevents/api/paginators.py
+41
-0
41 additions, 0 deletions
gracedb/superevents/api/paginators.py
gracedb/superevents/api/views.py
+2
-2
2 additions, 2 deletions
gracedb/superevents/api/views.py
with
43 additions
and
2 deletions
gracedb/superevents/api/paginators.py
+
41
−
0
View file @
468cdac9
from
rest_framework
import
pagination
from
rest_framework.response
import
Response
import
urllib
from
collections
import
OrderedDict
import
logging
logger
=
logging
.
getLogger
(
__name__
)
# TP (30 Apr 2018):
# This module has a bunch of hacked together pagination which is intended
# to match the existing "pagination" of the events API. We should definitely
# redo both APIs to do something reasonable and consistent when we have a
# chance.
def
BasePaginationFactory
(
links_dict
=
True
,
results_name
=
'
results
'
):
class
CustomBasePagination
(
pagination
.
PageNumberPagination
):
...
...
@@ -53,3 +60,37 @@ class CustomLogTagPagination(pagination.PageNumberPagination):
])
return
Response
(
output
)
class
CustomSupereventPagination
(
pagination
.
LimitOffsetPagination
):
default_limit
=
3
limit_query_param
=
'
count
'
offset_query_param
=
'
start
'
def
get_paginated_response
(
self
,
data
):
numRows
=
self
.
count
# Get base URI
base_uri
=
self
.
request
.
build_absolute_uri
(
self
.
request
.
path
)
# Construct custom link for "last" page
last
=
max
(
0
,
(
numRows
/
self
.
limit
))
*
self
.
limit
param_dict
=
{
'
start
'
:
last
,
self
.
limit_query_param
:
self
.
limit
,
}
last_uri
=
base_uri
+
'
?
'
+
urllib
.
urlencode
(
param_dict
)
output
=
OrderedDict
([
(
'
numRows
'
,
numRows
),
(
'
superevents
'
,
data
),
(
'
links
'
,
OrderedDict
([
(
'
self
'
,
self
.
request
.
build_absolute_uri
()),
(
'
next
'
,
self
.
get_next_link
()),
(
'
previous
'
,
self
.
get_previous_link
()),
(
'
first
'
,
base_uri
),
(
'
last
'
,
last_uri
),
])),
])
return
Response
(
output
)
This diff is collapsed.
Click to expand it.
gracedb/superevents/api/views.py
+
2
−
2
View file @
468cdac9
...
...
@@ -24,7 +24,7 @@ from events.api.backends import LigoAuthentication
from
.mixins
import
GetParentSupereventMixin
from
.paginators
import
BasePaginationFactory
,
CustomLabelPagination
,
\
CustomLogTagPagination
CustomLogTagPagination
,
CustomSupereventPagination
from
.serializers
import
SupereventSerializer
,
SupereventUpdateSerializer
,
\
SupereventEventSerializer
,
SupereventLabelSerializer
,
\
SupereventLogSerializer
,
SupereventLogTagSerializer
,
\
...
...
@@ -44,7 +44,7 @@ class SupereventViewSet(viewsets.ModelViewSet):
"""
queryset
=
Superevent
.
objects
.
all
()
serializer_class
=
SupereventSerializer
pagination_class
=
BasePaginationFactory
(
results_name
=
'
superevents
'
)
pagination_class
=
CustomSupereventPagination
lookup_field
=
SUPEREVENT_LOOKUP_FIELD
lookup_value_regex
=
SUPEREVENT_LOOKUP_REGEX
...
...
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