diff --git a/district/models.py b/district/models.py index 235c42c2411882d1e43ef351f52c42b50547e413..ebe030164be9a03e60be8e6ad91df68b890e1805 100644 --- a/district/models.py +++ b/district/models.py @@ -456,17 +456,11 @@ class DistrictArticlePage( return cleaned_data - @property - def get_tags(self): - if self.shared_from is not None: - return self.articles_page.search_tags_by_unioned_id_query([self]) - return self.tags.all - def get_context(self, request): context = super().get_context(request) context["related_articles"] = ( self.get_siblings(inclusive=False) - .live() # TODO? filtrovat na stejné tagy? + .live() # TODO? filtrovat na stejné tagy? nebo sdílené články? .specific() .order_by("-districtarticlepage__date")[:3] ) diff --git a/main/models.py b/main/models.py index 0bceaf7fc29df28502c5e36d063efc09612c3720..46c03417feda4fdf2071989779e2bfed1ed8506d 100644 --- a/main/models.py +++ b/main/models.py @@ -234,10 +234,8 @@ class MainHomePage( .order_by("-date")[:3] ) - articles_for_article_section = ( + articles_for_article_section = self.append_all_shared_articles( MainArticlePage.objects.filter(article_type=ARTICLE_TYPES.PRESS_RELEASE) - .live() - .order_by("-date") ) context["article_main"] = ( articles_for_article_section[0] if articles_for_article_section else None @@ -475,12 +473,14 @@ class MainArticlesPage( article_type=ARTICLE_TYPES.WORK_TIMELINE ).live().count() > len(article_timeline_list) - article_list = ( + article_list = self.append_all_shared_articles_query( MainArticlePage.objects.filter(article_type=ARTICLE_TYPES.PRESS_RELEASE) - .order_by("-date") - .live()[:11] - ) # dám LIMIT +1, abych věděl, jestli má cenu show_next - ctx["article_article_list"] = article_list[:10] + )[ + :11 + ] # dám LIMIT +1, abych věděl, jestli má cenu show_next + ctx["article_article_list"] = self.materialize_shared_articles_query( + article_list[:10] + ) ctx["show_next_article"] = len(article_list) > 10 return ctx @@ -682,12 +682,6 @@ class MainArticlePage( class Meta: verbose_name = "Aktualita" - @property - def get_tags(self): - if self.shared_from is not None: - return self.articles_page.search_tags_by_unioned_id_query([self]) - return self.tags.all - # def get_context(self, request): chceme/nechceme? # context = super().get_context(request) # context["related_articles"] = ( diff --git a/main/templates/main/includes/article_carousel_item.html b/main/templates/main/includes/article_carousel_item.html index 46e0739075f8a9d251fa47232cb7764449d4fe0f..cfb1cb81d68106b5c2adb2bc348fe59461b17328 100644 --- a/main/templates/main/includes/article_carousel_item.html +++ b/main/templates/main/includes/article_carousel_item.html @@ -3,17 +3,29 @@ <div> <div class="flex max-w-md items-start xl:mr-2"> {% image article_item.image fill-144x144 as image %} - <a href="{{ article_item.url }}" class="mr-4 shrink-0"> + {% if article.shared_from %} + <a href="{{ page.url }}sdilene?sdilene={{ article.slug|urlencode }}" rel="noindex" class="mr-4 shrink-0"> + {% else %} + <a href="{{ article_item.url }}" class="mr-4 shrink-0"> + {% endif %} <img src="{{ image.url }}" alt="" class="w-16 xl:w-36"> </a> <div class="flex flex-col justify-between items-start"> <span class="text-green-500 mb-2">{{ article_item.date | date }}</span> - <a href="{{ article_item.url }}" class="font-alt leading-5 text-base uppercase lg:text-base mb-2"> + {% if article.shared_from %} + <a href="{{ page.url }}sdilene?sdilene={{ article.slug|urlencode }}" rel="noindex" class="font-alt leading-5 text-base uppercase lg:text-base mb-2"> + {% else %} + <a href="{{ article_item.url }}" class="font-alt leading-5 text-base uppercase lg:text-base mb-2"> + {% endif %} {{ article_item.title }} </a> - {% include 'main/includes/href_button.html' with btn_link=article_item.url btn_text="Zjistit více" %} + {% if article_item.shared_from %} + {% include 'main/includes/href_button.html' with btn_link="{{ page.url }}sdilene?sdilene={{ article_item.slug|urlencode }}" btn_text="Zjistit více" noindex=True %} + {% else %} + {% include 'main/includes/href_button.html' with btn_link=article_item.url btn_text="Zjistit více" %} + {% endif %} </div> </div> </div> diff --git a/main/templates/main/includes/href_button.html b/main/templates/main/includes/href_button.html index 12579d75e1335d1df915c69d9e338d741895b49f..6f83e5517bedc40ff8913ca13f013453e12d7fbc 100644 --- a/main/templates/main/includes/href_button.html +++ b/main/templates/main/includes/href_button.html @@ -1,4 +1,4 @@ -<a href="{{ btn_link }}" class="btn btn--black btn--to-yellow-500 btn--hoveractive uppercase {{ extra_classes }}"> +<a href="{{ btn_link }}"{% if noindex %} rel="noindex" {% endif %}class="btn btn--black btn--to-yellow-500 btn--hoveractive uppercase {{ extra_classes }}"> <span class="btn__body-wrap"> <span class="btn__body text-lg lg:text-base {{ size_classes | default_if_none:"" }}"> {{ btn_text | default_if_none:"Číst dále" }} diff --git a/main/templates/main/includes/person_article_preview.html b/main/templates/main/includes/person_article_preview.html index 89ead97385706b76cd6108ecf846cad86de6f9a5..d75d4d71a59b854fcba0888c0b6770866f5f2423 100644 --- a/main/templates/main/includes/person_article_preview.html +++ b/main/templates/main/includes/person_article_preview.html @@ -20,7 +20,12 @@ <span class="bg-violet-600 mb-1 mr-1 px-2 py-2">{{ tag }}</span> {% endfor %} </div> - <a href="{{ article_page.url }}"> + {% if article_page.shared_from %} + <a href="{{ page.url }}sdilene?sdilene={{ article_page.slug|urlencode }}" rel="noindex"> + {% else %} + <a href="{{ article_page.url }}"> + {% endif %} + <h4 class="head-3xl mb-4"> {{ article_page.title }} </h4> @@ -28,7 +33,11 @@ <p class="mb-6"> {{ article_page.perex }} </p> + {% if article_page.shared_from %} + {% include 'main/includes/href_button.html' with btn_link="{{ page.url }}sdilene?sdilene={{ article_page.slug|urlencode }}" btn_text="Číst dále" noindex=True %} + {% else %} {% include 'main/includes/href_button.html' with btn_link=article_page.url btn_text="Číst dále" %} + {% endif %} </div> </div> {% endfor %} diff --git a/main/templates/main/includes/small_article_preview.html b/main/templates/main/includes/small_article_preview.html index ea40cacb15b8d63b61a349496518164fe7d66b33..0dce780eff82813ef8aae6114e332143d3f6d561 100644 --- a/main/templates/main/includes/small_article_preview.html +++ b/main/templates/main/includes/small_article_preview.html @@ -13,7 +13,11 @@ <h4 class="font-alt leading-5 text-base uppercase lg:text-base mb-2"> {{ article_page.title }} </h4> - {% include 'main/includes/href_button.html' with btn_link=article_page.url btn_text="Číst dále" %} + {% if article_page.shared_from %} + {% include 'main/includes/href_button.html' with btn_link="{{ page.url }}sdilene?sdilene={{ article_page.slug|urlencode }}" btn_text="Číst dále" noindex=True %} + {% else %} + {% include 'main/includes/href_button.html' with btn_link=article_page.url btn_text="Číst dále" %} + {% endif %} </div> </div> {% endfor %} diff --git a/shared/models.py b/shared/models.py index c7941d4c5ef9d7c0f509eff0d8493b8ea51302c1..1116749c8a01a9297ea0673486cc7f212c451272 100644 --- a/shared/models.py +++ b/shared/models.py @@ -1,4 +1,5 @@ import logging +from collections import namedtuple from enum import Enum from functools import reduce @@ -107,6 +108,12 @@ class ArticleMixin(models.Model): return self.shared_from.get_specific().root_page + @property + def get_tags(self): + if self.shared_from is not None: + return self.articles_page.search_tags_by_unioned_id_query([self]) + return self.tags.all + @classmethod def has_tags(cls): try: @@ -115,10 +122,6 @@ class ArticleMixin(models.Model): return False return True - def tag_filter_page(self): - """Page used for filtering by tags in url like `?tag=foo`.""" - return self.get_parent() - def get_meta_image(self): if hasattr(self, "search_image") and self.search_image: return self.search_image @@ -577,6 +580,22 @@ class ArticlesMixin(models.Model): articles: list, tags_model_query=None, ): + if isinstance(articles, models.QuerySet): + TmpArticle = namedtuple( + "TemporaryArticle", field_names=["page_ptr", "shared_type"] + ) + TmpPrimaryKey = namedtuple("TemporaryPk", field_names=["id"]) + articles = list( + map( + lambda unioned: TmpArticle( + page_ptr=TmpPrimaryKey(id=unioned["union_page_ptr_id"]), + shared_type=unioned["union_shared_type"], + ), + articles.values( + "union_page_ptr_id", "union_shared_type", "union_date" + ), + ) + ) own_page_type = self.determine_page_type() get_ids_by_page_type = lambda page_type: list( map( @@ -613,11 +632,9 @@ class ArticlesMixin(models.Model): return tag_query - def search_tags_by_tag_name(self, tag: str): + def filter_by_tag_name(self, tag: str): return { - "uniwebarticlepage__tags__name": tag, - "districtarticlepage__tags__name": tag, - "mainarticlepage__tags__name": tag, + "tags__name": tag, } class Meta: diff --git a/shared/templates/styleguide/2.3.x/article_card.html b/shared/templates/styleguide/2.3.x/article_card.html index 8b98e342554f6b484c810ba0b301b5bc441c77ed..b8361e7d12d9f12babad016d33e63a9d5096f8f8 100644 --- a/shared/templates/styleguide/2.3.x/article_card.html +++ b/shared/templates/styleguide/2.3.x/article_card.html @@ -4,7 +4,11 @@ <link itemprop="mainEntityOfPage" href="{% pageurl article %}"> <div class="article-card-cover"> - <a href="{% pageurl article %}" itemprop="image" itemtype="http://schema.org/ImageObject" itemscope=""> + {% if article.shared_from %} + <a href="{{ page.url }}sdilene?sdilene={{ article.slug|urlencode }}" rel="noindex" itemprop="image" itemtype="http://schema.org/ImageObject" itemscope=""> + {% else %} + <a href="{% pageurl article %}" itemprop="image" itemtype="http://schema.org/ImageObject" itemscope=""> + {% endif %} {% image article.image width-800 as img %} <img src="{{ img.url }}" alt="{{ article.title }}"> <meta itemprop="url" content="{{ img.url }}"> @@ -44,7 +48,7 @@ {% if article.has_tags %} <div class="inline-block-nogap mt-4"> {% for tag in article.get_tags %} - <a href="{% pageurl article.tag_filter_page %}?tag={{ tag }}" class="btn article-card__category-button btn--grey-125 btn--condensed text-sm font-light"> + <a href="{% pageurl article.articles_page %}?tag={{ tag }}" class="btn article-card__category-button btn--grey-125 btn--condensed text-sm font-light"> <div class="btn__body ">{{ tag }}</div> </a> {% endfor %} diff --git a/uniweb/models.py b/uniweb/models.py index 0f951727e75a96f4641e353b1eed92793e9ea315..668be1e754755c06386c3d088c3fbeb71a330498 100644 --- a/uniweb/models.py +++ b/uniweb/models.py @@ -547,12 +547,12 @@ class UniwebArticlesIndexPage( num = request.GET.get("page") tag = request.GET.get("tag") - tag_params = self.search_tags_by_tag_name(tag) + tag_params = self.filter_by_tag_name(tag) own_children = UniwebArticlePage.objects.child_of(self) articles = self.append_all_shared_articles_query( - own_children, + own_children if tag is None else own_children.filter(**tag_params), custom_article_query=lambda articles: articles.filter(**tag_params) if tag is not None else articles, @@ -602,12 +602,6 @@ class UniwebArticlePage( class Meta: verbose_name = "Článek" - @property - def get_tags(self): - if self.shared_from is not None: - return self.articles_page.search_tags_by_unioned_id_query([self]) - return self.tags.all - def get_context(self, request): context = super().get_context(request) context["related_articles"] = ( diff --git a/uniweb/templates/uniweb/uniweb_article_page.html b/uniweb/templates/uniweb/uniweb_article_page.html index 483fa3aa466f2e85d6d45b5625be5c6656aaf125..6f12882106778cb2b5c4b56a229e85a0bb8f8fb8 100644 --- a/uniweb/templates/uniweb/uniweb_article_page.html +++ b/uniweb/templates/uniweb/uniweb_article_page.html @@ -24,7 +24,7 @@ {% if page.has_tags %} <div class="my-4"> {% for tag in page.get_tags %} - <a href="{% pageurl page.tag_filter_page %}?tag={{ tag }}" class="btn btn--grey-125 btn--condensed"> + <a href="{% pageurl page.articles_page %}?tag={{ tag }}" class="btn btn--grey-125 btn--condensed"> <div class="btn__body ">{{ tag }}</div> </a> {% endfor %}