Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
teknikattan-scoring-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tddd96-grupp1
teknikattan-scoring-system
Commits
03022b31
Commit
03022b31
authored
3 years ago
by
Victor Löfgren
Browse files
Options
Downloads
Patches
Plain Diff
Refactor paginate
parent
b0bf59fb
No related branches found
No related tags found
1 merge request
!161
Resolve "replace-restx-with-smorest"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/app/database/__init__.py
+21
-27
21 additions, 27 deletions
server/app/database/__init__.py
server/app/database/controller/search.py
+2
-6
2 additions, 6 deletions
server/app/database/controller/search.py
with
23 additions
and
33 deletions
server/app/database/__init__.py
+
21
−
27
View file @
03022b31
...
...
@@ -50,34 +50,28 @@ class ExtendedQuery(BaseQuery):
return
item
def
paginate_api
(
self
,
pagination_parameters
,
order_column
=
None
,
order
=
1
):
"""
When looking for lists of items this is used to only return a few of
them to allow for pagination.
:param page: Offset of the result
:type page: int
:param page_size: Amount of rows that will be retrieved from the query
:type page_size: int
:param order_column: Field of a DbModel in which the query shall order by
:type order_column: sqlalchemy.sql.schema.Column
:param order: If equals 1 then order by ascending otherwise order by descending
:type order: int
:return: A page/list of items with offset page*page_size and the total count of all rows ignoring page and page_size
:rtype: list, int
"""
if
order_column
:
self
=
self
.
order_by
(
order_column
if
order
==
1
else
order_column
.
desc
())
# def pagination(self, page=0, page_size=15, order_column=None, order=1):
# """
# When looking for lists of items this is used to only return a few of
# them to allow for pagination.
# :param page: Offset of the result
# :type page: int
# :param page_size: Amount of rows that will be retrieved from the query
# :type page_size: int
# :param order_column: Field of a DbModel in which the query shall order by
# :type order_column: sqlalchemy.sql.schema.Column
# :param order: If equals 1 then order by ascending otherwise order by descending
# :type order: int
# :return: A page/list of items with offset page*page_size and the total count of all rows ignoring page and page_size
# :rtype: list, int
# """
# query = self
# if order_column:
# if order == 1:
# query = query.order_by(order_column)
# else:
# query = query.order_by(order_column.desc())
# total = query.count()
# query = query.limit(page_size).offset(page * page_size)
# items = query.all()
# return items, total
pagination
=
self
.
paginate
(
page
=
pagination_parameters
.
page
,
per_page
=
pagination_parameters
.
page_size
)
pagination_parameters
.
item_count
=
pagination
.
total
return
pagination
.
items
# class Dictionary(TypeDecorator):
...
...
This diff is collapsed.
Click to expand it.
server/app/database/controller/search.py
+
2
−
6
View file @
03022b31
...
...
@@ -34,9 +34,7 @@ def user(
if
role_id
:
query
=
query
.
filter
(
User
.
role_id
==
role_id
)
pagination
=
query
.
paginate
(
page
=
pagination_parameters
.
page
,
per_page
=
pagination_parameters
.
page_size
)
pagination_parameters
.
item_count
=
pagination
.
total
return
pagination
.
items
return
query
.
paginate_api
(
pagination_parameters
)
def
competition
(
...
...
@@ -55,9 +53,7 @@ def competition(
if
city_id
:
query
=
query
.
filter
(
Competition
.
city_id
==
city_id
)
pagination
=
query
.
paginate
(
page
=
pagination_parameters
.
page
,
per_page
=
pagination_parameters
.
page_size
)
pagination_parameters
.
item_count
=
pagination
.
total
return
pagination
.
items
return
query
.
paginate_api
(
pagination_parameters
)
def
slide
(
...
...
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