Skip to content
Snippets Groups Projects
Commit b2f7a4d6 authored by jarmil's avatar jarmil Committed by jan.bednarik
Browse files

Stranka s tagy

parent 7dfb4aff
No related branches found
No related tags found
No related merge requests found
# 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,
),
),
]
...@@ -109,6 +109,7 @@ class DistrictHomePage(MetadataPageMixin, Page): ...@@ -109,6 +109,7 @@ class DistrictHomePage(MetadataPageMixin, Page):
"shared.PeoplePage", "shared.PeoplePage",
"DistrictArticles", "DistrictArticles",
"DistrictContact", "DistrictContact",
"DistrictTags",
] ]
### OTHERS ### OTHERS
...@@ -116,21 +117,28 @@ class DistrictHomePage(MetadataPageMixin, Page): ...@@ -116,21 +117,28 @@ class DistrictHomePage(MetadataPageMixin, Page):
class Meta: class Meta:
verbose_name = "Web místního sdružení" 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 @property
def articles(self): def articles(self):
return self.get_descendants().type(Article).live().specific() return self.get_descendants().type(Article).live().specific()
@property @property
def articles_page(self): def articles_page(self):
return self.get_descendants().type(DistrictArticles).live().specific()[0] return self._first_subpage_of_type(DistrictArticles)
@property @property
def people_page(self): def people_page(self):
return self.get_descendants().type(PeoplePage).live().specific()[0] return self._first_subpage_of_type(PeoplePage)
@property @property
def contact_page(self): 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 @property
def root_page(self): def root_page(self):
...@@ -189,3 +197,26 @@ class DistrictContact(SharedSubpageMixin, MetadataPageMixin, Page): ...@@ -189,3 +197,26 @@ class DistrictContact(SharedSubpageMixin, MetadataPageMixin, Page):
class Meta: class Meta:
verbose_name = "Kontakty" 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
{% 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 %}
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<div class="my-4"> <div class="my-4">
{% for tag in page.tags.all %} {% 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 %} {% endfor %}
</div> </div>
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
<p class="card-body-text flex-grow text-white">{{article.perex}}</p> <p class="card-body-text flex-grow text-white">{{article.perex}}</p>
<div class="inline-block-nogap mt-4"> <div class="inline-block-nogap mt-4">
{% for tag in article.tags.all %} {% 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> <div class="btn__body">{{ tag }}</div>
</a> </a>
{% endfor %} {% endfor %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment