diff --git a/district/migrations/0010_districttags.py b/district/migrations/0010_districttags.py new file mode 100644 index 0000000000000000000000000000000000000000..57066ec1061188a3bb8003993cd2adf2c3de766a --- /dev/null +++ b/district/migrations/0010_districttags.py @@ -0,0 +1,53 @@ +# Generated by Django 3.1.1 on 2020-10-20 03:30 + +import django.db.models.deletion +import wagtailmetadata.models +from django.db import migrations, models + +import shared.models + + +class Migration(migrations.Migration): + + dependencies = [ + ("wagtailimages", "0022_uploadedimage"), + ("wagtailcore", "0052_pagelogentry"), + ("district", "0009_auto_20201014_1343"), + ] + + operations = [ + migrations.CreateModel( + name="DistrictTags", + fields=[ + ( + "page_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="wagtailcore.page", + ), + ), + ( + "search_image", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to="wagtailimages.image", + verbose_name="Search image", + ), + ), + ], + options={"verbose_name": "Stránka s tagy",}, + bases=( + shared.models.SharedSubpageMixin, + wagtailmetadata.models.MetadataMixin, + "wagtailcore.page", + models.Model, + ), + ), + ] diff --git a/district/models.py b/district/models.py index 2ac741319cf42be50e02ab0ecc568456df5930d7..9f6f459088d81c65507d480788dcc9add4a3860a 100644 --- a/district/models.py +++ b/district/models.py @@ -109,6 +109,7 @@ class DistrictHomePage(MetadataPageMixin, Page): "shared.PeoplePage", "DistrictArticles", "DistrictContact", + "DistrictTags", ] ### OTHERS @@ -116,21 +117,28 @@ class DistrictHomePage(MetadataPageMixin, Page): class Meta: verbose_name = "Web mĂstnĂho sdruĹľenĂ" + def _first_subpage_of_type(self, page_type): + return self.get_descendants().type(page_type).live().specific()[0] + @property def articles(self): return self.get_descendants().type(Article).live().specific() @property def articles_page(self): - return self.get_descendants().type(DistrictArticles).live().specific()[0] + return self._first_subpage_of_type(DistrictArticles) @property def people_page(self): - return self.get_descendants().type(PeoplePage).live().specific()[0] + return self._first_subpage_of_type(PeoplePage) @property def contact_page(self): - return self.get_descendants().type(DistrictContact).live().specific()[0] + return self._first_subpage_of_type(DistrictContact) + + @property + def tags_page(self): + return self._first_subpage_of_type(DistrictTags) @property def root_page(self): @@ -189,3 +197,26 @@ class DistrictContact(SharedSubpageMixin, MetadataPageMixin, Page): class Meta: verbose_name = "Kontakty" + + +class DistrictTags(SharedSubpageMixin, MetadataPageMixin, Page): + + settings_panels = [] + + class Meta: + verbose_name = "Stránka s tagy" + + def get_context(self, request): + context = super().get_context(request) + + # Natrid clanky do hashtable dle tagu (v template by se to delalo podstatne hur) + tags = {} + for x in self.root_page.articles_page.get_children().live().specific(): + for y in x.tags.all(): + try: + tags[y.name].append(x) + except KeyError: + tags[y.name] = [x] + + context["tags"] = tags + return context diff --git a/district/templates/district/district_tags.html b/district/templates/district/district_tags.html new file mode 100644 index 0000000000000000000000000000000000000000..e4feb3fe87705a02883e09b8ee833a2649668d4f --- /dev/null +++ b/district/templates/district/district_tags.html @@ -0,0 +1,26 @@ +{% extends "district/base.html" %} + +{% block content %} +<main> + + <h1 class="head-alt-md md:head-alt-lg max-w-5xl mb-4 mt-5">{{ page }}</h1> + + <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"> + {% for tag, articles in tags.items %} + + <section class="card"> + <div class="card__body p-4"> + <h3 class="head-heavy-xs mb-2" id="{{ tag }}">{{ tag }}</h3> + <ul class="unordered-list unordered-list--linked unordered-list--dense leading-normal font-light text-sm"> + {% for x in articles %} + <li><a href="{{ x.url }}">{{ x }}</a></li> + {% endfor %} + </ul> + </div> + </section> + + {% endfor %} + </div> + +</main> +{% endblock %} diff --git a/district/templates/shared/article.html b/district/templates/shared/article.html index 4e326584b3a0c23d8560259efe4873f6813c8bee..a792a5be3dfa18067d285920222100321755e203 100644 --- a/district/templates/shared/article.html +++ b/district/templates/shared/article.html @@ -27,7 +27,7 @@ <div class="my-4"> {% for tag in page.tags.all %} - <a href="/tags/#{{ tag}}" class="btn btn--grey-125 btn--condensed" ><div class="btn__body ">{{ tag }}</div></a> + <a href="{{ page.root_page.tags_page.url }}#{{ tag}}" class="btn btn--grey-125 btn--condensed" ><div class="btn__body ">{{ tag }}</div></a> {% endfor %} </div> diff --git a/shared/templates/shared/article_preview.html b/shared/templates/shared/article_preview.html index 0a46e88aea09a64f7d1644a8e4b21766672a08a2..a2826abe7146668f09244b313df7019f41c6d356 100644 --- a/shared/templates/shared/article_preview.html +++ b/shared/templates/shared/article_preview.html @@ -45,7 +45,7 @@ <p class="card-body-text flex-grow text-white">{{article.perex}}</p> <div class="inline-block-nogap mt-4"> {% for tag in article.tags.all %} - <a href="/tags/#{{ tag }}" class="btn article-card__category-button btn--condensed text-sm font-light btn--grey-700 p-0" > + <a href="{{ page.root_page.tags_page.url }}#{{ tag }}" class="btn article-card__category-button btn--condensed text-sm font-light btn--grey-700 p-0" > <div class="btn__body">{{ tag }}</div> </a> {% endfor %}