Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
4c62ed7e
Verified
Commit
4c62ed7e
authored
Jul 19, 2023
by
jindra12
Browse files
Options
Downloads
Patches
Plain Diff
Unify paginator use
#210
parent
7132f43f
Branches
Branches containing commit
No related tags found
2 merge requests
!816
Release
,
!801
Prepare basic shared tags
Pipeline
#13848
passed
Jul 19, 2023
Stage: build
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
district/models.py
+8
-13
8 additions, 13 deletions
district/models.py
main/models.py
+4
-8
4 additions, 8 deletions
main/models.py
shared/models.py
+12
-2
12 additions, 2 deletions
shared/models.py
uniweb/models.py
+4
-3
4 additions, 3 deletions
uniweb/models.py
with
28 additions
and
26 deletions
district/models.py
+
8
−
13
View file @
4c62ed7e
...
...
@@ -4,7 +4,6 @@ from functools import cached_property
from
django.core.cache
import
cache
from
django.core.exceptions
import
ValidationError
from
django.core.paginator
import
Paginator
from
django.db
import
models
from
django.http
import
HttpResponseNotFound
,
HttpResponseRedirect
from
django.shortcuts
import
render
...
...
@@ -543,13 +542,12 @@ class DistrictArticlesPage(
def
get_context
(
self
,
request
):
context
=
super
().
get_context
(
request
)
context
[
"
articles
"
]
=
self
.
materialize_shared_articles_query
(
Paginator
(
context
[
"
articles
"
]
=
self
.
get_page_with_shared_articles
(
self
.
append_all_shared_articles_query
(
DistrictArticlePage
.
objects
.
child_of
(
self
)
),
self
.
max_items
,
).
get_page
(
request
.
GET
.
get
(
"
page
"
)
)
request
.
GET
.
get
(
"
page
"
)
,
)
return
context
...
...
@@ -615,11 +613,8 @@ class DistrictArticlesPage(
)
return
{
"
article_page_list
"
:
self
.
materialize_shared_articles_query
(
Paginator
(
article_page_qs
,
self
.
max_items
,
).
get_page
(
request
.
GET
.
get
(
"
page
"
))
"
article_page_list
"
:
self
.
get_page_with_shared_articles
(
article_page_qs
,
self
.
max_items
,
request
.
GET
.
get
(
"
page
"
)
),
"
tag
"
:
tag
,
}
...
...
...
...
This diff is collapsed.
Click to expand it.
main/models.py
+
4
−
8
View file @
4c62ed7e
...
...
@@ -501,16 +501,14 @@ class MainArticlesPage(
return
JsonResponse
(
data
=
data
,
safe
=
False
)
def
get_articles_response
(
self
,
request
):
article_pag
inator
=
Paginator
(
article_pag
e
=
self
.
get_page_with_shared_articles
(
self
.
append_all_shared_articles_query
(
MainArticlePage
.
objects
.
filter
(
article_type
=
ARTICLE_TYPES
.
PRESS_RELEASE
),
).
order_by
(
"
union_date
"
,
"
union_title
"
),
10
,
)
article_page
=
self
.
materialize_shared_articles_query
(
article_paginator
.
get_page
(
request
.
GET
.
get
(
"
page
"
,
1
))
request
.
GET
.
get
(
"
page
"
,
1
),
)
context
=
{
"
article_data_list
"
:
article_page
.
object_list
}
html_content
=
render
(
...
...
@@ -523,7 +521,7 @@ class MainArticlesPage(
return
JsonResponse
(
data
=
data
,
safe
=
False
)
def
get_all_articles_search_response
(
self
,
request
):
article_pag
inator
=
Paginator
(
article_pag
e
=
self
.
get_page_with_shared_articles
(
self
.
append_all_shared_articles_query
(
MainArticlePage
.
objects
.
search
(
request
.
GET
[
"
q
"
],
...
...
@@ -531,9 +529,7 @@ class MainArticlesPage(
)
),
10
,
)
article_page
=
self
.
materialize_shared_articles_query
(
article_paginator
.
get_page
(
request
.
GET
.
get
(
"
page
"
,
1
))
request
.
GET
.
get
(
"
page
"
,
1
),
)
context
=
{
"
article_data_list
"
:
article_page
.
object_list
}
html_content
=
render
(
...
...
...
...
This diff is collapsed.
Click to expand it.
shared/models.py
+
12
−
2
View file @
4c62ed7e
...
...
@@ -3,10 +3,10 @@ from enum import Enum
from
functools
import
reduce
from
django.apps
import
apps
from
django.core.paginator
import
Paginator
from
django.db
import
models
from
django.db.models
import
Q
from
django.db.models.expressions
import
ExpressionWrapper
,
F
,
Value
from
django.db.models.functions
import
Coalesce
from
django.db.models.expressions
import
F
,
Value
from
django.utils
import
timezone
from
modelcluster.fields
import
ParentalKey
,
ParentalManyToManyField
from
taggit.models
import
ItemBase
,
Tag
,
TagBase
...
...
@@ -545,6 +545,16 @@ class ArticlesMixin(models.Model):
)
)
def
get_page_with_shared_articles
(
self
,
query
:
models
.
QuerySet
,
page_size
:
int
,
page
:
int
):
return
self
.
materialize_shared_articles_query
(
Paginator
(
query
,
page_size
,
).
get_page
(
page
)
)
def
append_all_shared_articles
(
self
,
previous_query
:
models
.
QuerySet
|
None
=
None
,
custom_article_query
=
None
):
...
...
...
...
This diff is collapsed.
Click to expand it.
uniweb/models.py
+
4
−
3
View file @
4c62ed7e
...
...
@@ -2,7 +2,6 @@ import random
from
captcha.fields
import
CaptchaField
from
django
import
forms
from
django.core.paginator
import
Paginator
from
django.db
import
models
from
django.utils.translation
import
gettext_lazy
from
modelcluster.contrib.taggit
import
ClusterTaggableManager
...
...
@@ -566,8 +565,10 @@ class UniwebArticlesIndexPage(
else
articles
,
)
context
[
"
articles
"
]
=
self
.
materialize_shared_articles_query
(
Paginator
(
articles
,
ARTICLES_PER_PAGE
).
get_page
(
num
)
context
[
"
articles
"
]
=
self
.
get_page_with_shared_articles
(
articles
,
ARTICLES_PER_PAGE
,
num
,
)
context
[
"
tags
"
]
=
self
.
search_tags_by_unioned_id_query
(
articles_ids
)
context
[
"
active_tag
"
]
=
tag
...
...
...
...
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
sign in
to comment