Skip to content
Snippets Groups Projects
Verified Commit 4ef59983 authored by jindra12's avatar jindra12
Browse files

Adapt district main page to shared articles

parent fda46db5
Branches
No related tags found
2 merge requests!816Release,!801Prepare basic shared tags
Pipeline #13790 passed
......@@ -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"),
)
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment