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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
Maják
Commits
4ef59983
Verified
Commit
4ef59983
authored
1 year ago
by
jindra12
Browse files
Options
Downloads
Patches
Plain Diff
Adapt district main page to shared articles
#210
parent
fda46db5
No related branches found
No related tags found
2 merge requests
!816
Release
,
!801
Prepare basic shared tags
Pipeline
#13790
passed
1 year ago
Stage: build
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
district/models.py
+11
-10
11 additions, 10 deletions
district/models.py
shared/models.py
+7
-12
7 additions, 12 deletions
shared/models.py
with
18 additions
and
22 deletions
district/models.py
+
11
−
10
View file @
4ef59983
...
...
@@ -70,11 +70,13 @@ CONTENT_BLOCKS = DEFAULT_CONTENT_BLOCKS + [
class
DistrictHomePage
(
RoutablePageMixin
,
MenuMixin
,
ExtendedMetadataHomePageMixin
,
MetadataPageMixin
,
CalendarMixin
,
FooterMixin
,
ArticlesMixin
,
Page
,
):
### FIELDS
...
...
@@ -235,6 +237,7 @@ class DistrictHomePage(
FieldPanel
(
"
subheader
"
),
FieldPanel
(
"
content
"
),
FieldPanel
(
"
articles_title
"
),
FieldPanel
(
"
shared_tags
"
),
FieldPanel
(
"
election_countdown_datetime
"
),
FieldPanel
(
"
show_calendar_on_hp
"
),
]
...
...
@@ -330,6 +333,10 @@ class DistrictHomePage(
class
Meta
:
verbose_name
=
"
Oblastní sdružení
"
@route
(
r
"
^sdilene/$
"
,
name
=
"
shared
"
)
def
shared
(
self
,
request
):
return
self
.
setup_article_page_context
(
request
)
def
_first_subpage_of_type
(
self
,
page_type
)
->
Page
or
None
:
try
:
return
self
.
get_descendants
().
type
(
page_type
).
live
().
specific
()[
0
]
...
...
@@ -338,13 +345,9 @@ class DistrictHomePage(
@property
def
articles
(
self
):
return
(
self
.
get_descendants
()
.
type
(
DistrictArticlePage
)
.
live
()
.
specific
()
.
order_by
(
"
-districtarticlepage__date
"
)[:
6
]
)
return
self
.
append_all_shared_articles
(
DistrictArticlePage
.
objects
.
descendant_of
(
self
)
)[:
6
]
@property
def
articles_page
(
self
):
...
...
@@ -616,9 +619,7 @@ class DistrictArticlesPage(
"""
return
self
.
search_tags_by_article_id
(
site_article_ids
,
custom_query_to_values
=
lambda
query
:
query
.
annotate
(
count
=
models
.
Count
(
"
slug
"
)
)
tags_model_query
=
lambda
query
:
query
.
annotate
(
count
=
models
.
Count
(
"
slug
"
))
.
order_by
(
"
slug
"
)
.
values
(
"
name
"
,
"
slug
"
,
"
count
"
),
)
...
...
This diff is collapsed.
Click to expand it.
shared/models.py
+
7
−
12
View file @
4ef59983
...
...
@@ -298,16 +298,11 @@ class ArticlesMixin(models.Model):
content_panels
=
Page
.
content_panels
+
[
FieldPanel
(
"
shared_tags
"
)]
def
determine_page_type
(
self
):
DistrictArticlesPage
=
apps
.
get_model
(
app_label
=
"
district.DistrictArticlesPage
"
)
UniwebArticlesIndexPage
=
apps
.
get_model
(
app_label
=
"
uniweb.UniwebArticlesIndexPage
"
)
MainArticlesPage
=
apps
.
get_model
(
app_label
=
"
main.MainArticlesPage
"
)
if
isinstance
(
self
,
DistrictArticlesPage
):
if
self
.
_meta
.
app_label
==
"
district
"
:
return
SharedArticlesPageType
.
DISTRICT
elif
isinstance
(
self
,
UniwebArticlesIndexPage
)
:
elif
self
.
_meta
.
app_label
==
"
uniweb
"
:
return
SharedArticlesPageType
.
UNIWEB
elif
isinstance
(
self
,
MainArticlesPage
)
:
elif
self
.
_meta
.
app_label
==
"
main
"
:
return
SharedArticlesPageType
.
MAIN
def
append_all_shared_articles_query
(
...
...
@@ -534,7 +529,7 @@ class ArticlesMixin(models.Model):
return
self
.
get_article_page_by_slug
(
slug
).
serve
(
request
)
def
search_tags_by_article_id
(
self
,
site_article_ids
:
list
,
additional_query
=
None
,
custom_query_to_values
=
None
self
,
site_article_ids
:
list
,
additional_query
=
None
,
tags_model_query
=
None
):
DistrictArticleTag
=
apps
.
get_model
(
app_label
=
"
district.DistrictArticleTag
"
)
UniwebArticleTag
=
apps
.
get_model
(
app_label
=
"
uniweb.UniwebArticleTag
"
)
...
...
@@ -557,11 +552,11 @@ class ArticlesMixin(models.Model):
union
=
district_tags
.
union
(
uniweb_tags
).
union
(
main_tags
)
union
=
union
.
values_list
(
"
id
"
)
union
=
union
.
values_list
(
"
tag_id
"
,
flat
=
True
)
tag_query
=
Tag
.
objects
.
filter
(
id__in
=
union
)
if
custom_query_to_values
is
not
None
:
tag_query
=
custom_query_to_values
(
tag_query
)
if
tags_model_query
is
not
None
:
tag_query
=
tags_model_query
(
tag_query
)
return
tag_query
...
...
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