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

uniweb: Article tags

parent eecd0e50
No related branches found
No related tags found
2 merge requests!187Release,!186Uniweb články
Pipeline #2443 passed
# Generated by Django 3.1.6 on 2021-02-17 12:16
import django.db.models.deletion
import modelcluster.contrib.taggit
import modelcluster.fields
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("taggit", "0003_taggeditem_add_unique_index"),
("uniweb", "0013_auto_20210217_1130"),
]
operations = [
migrations.CreateModel(
name="UniwebArticleTag",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"content_object",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
to="uniweb.uniwebarticlepage",
),
),
(
"tag",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="uniweb_uniwebarticletag_items",
to="taggit.tag",
),
),
],
options={
"abstract": False,
},
),
migrations.AddField(
model_name="uniwebarticlepage",
name="tags",
field=modelcluster.contrib.taggit.ClusterTaggableManager(
blank=True,
help_text="A comma-separated list of tags.",
through="uniweb.UniwebArticleTag",
to="taggit.Tag",
verbose_name="Tags",
),
),
]
......@@ -2,12 +2,17 @@ from django import forms
from django.core.paginator import Paginator
from django.db import models
from django.utils.translation import gettext_lazy
from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey
from taggit.models import TaggedItemBase
from wagtail.admin.edit_handlers import (
FieldPanel,
HelpPanel,
MultiFieldPanel,
ObjectList,
PublishingPanel,
StreamFieldPanel,
TabbedInterface,
)
from wagtail.contrib.table_block.blocks import TableBlock
from wagtail.core import blocks
......@@ -242,6 +247,10 @@ class UniwebContentMixin(models.Model):
abstract = True
class UniwebArticleTag(TaggedItemBase):
content_object = ParentalKey("uniweb.UniwebArticlePage", on_delete=models.CASCADE)
class UniwebHomePage(Page, UniwebContentMixin, MetadataPageMixin):
### FIELDS
......@@ -285,9 +294,21 @@ class UniwebHomePage(Page, UniwebContentMixin, MetadataPageMixin):
FieldPanel("narrow_layout"),
],
"nastavení webu",
)
]
menu_panels = [StreamFieldPanel("top_menu")]
edit_handler = TabbedInterface(
[
ObjectList(content_panels, heading=gettext_lazy("Content")),
ObjectList(promote_panels, heading=gettext_lazy("Promote")),
ObjectList(
settings_panels, heading=gettext_lazy("Settings"), classname="settings"
),
StreamFieldPanel("top_menu"),
ObjectList(menu_panels, heading="Menu"),
]
)
### RELATIONS
......@@ -332,8 +353,8 @@ class UniwebFlexiblePage(Page, UniwebContentMixin, SubpageMixin, MetadataPageMix
### RELATIONS
parent_page_types = ["uniweb.UniwebHomePage"]
subpage_types = []
parent_page_types = ["uniweb.UniwebHomePage", "uniweb.UniwebFlexiblePage"]
subpage_types = ["uniweb.UniwebFlexiblePage"]
### OTHERS
......@@ -373,20 +394,29 @@ class UniwebArticlesIndexPage(Page, SubpageMixin, MetadataPageMixin):
def get_context(self, request):
context = super().get_context(request)
num = request.GET.get("page")
tag = request.GET.get("tag")
articles = (
self.get_children().live().specific().order_by("-uniwebarticlepage__date")
)
num = request.GET.get("page")
if tag is not None:
articles = articles.filter(uniwebarticlepage__tags__name=tag)
context["articles"] = Paginator(articles, ARTICLES_PER_PAGE).get_page(num)
context["tags"] = UniwebArticleTag.tags_for(UniwebArticlePage)
context["active_tag"] = tag
return context
class UniwebArticlePage(Page, ArticleMixin, SubpageMixin, MetadataPageMixin):
### FIELDS
tags = ClusterTaggableManager(through=UniwebArticleTag, blank=True)
### PANELS
content_panels = ArticleMixin.content_panels
content_panels = ArticleMixin.content_panels + [FieldPanel("tags")]
promote_panels = [
MultiFieldPanel(
......
......@@ -21,17 +21,15 @@
{% endif %}
</div>
{# TODO tags #}
{% comment %}
{% if page.has_tags %}
<div class="my-4">
<button class="btn btn--grey-125 btn--condensed">
<div class="btn__body ">Kategorie 1</div>
</button>
<button class="btn btn--grey-125 btn--condensed">
<div class="btn__body ">Kategorie 2</div>
</button>
{% for tag in page.tags.all %}
<a href="{% pageurl page.tag_filter_page %}?tag={{ tag }}" class="btn btn--grey-125 btn--condensed">
<div class="btn__body ">{{ tag }}</div>
</a>
{% endfor %}
</div>
{% endcomment %}
{% endif %}
</div>
<figure class="figure">
......
{% extends "uniweb/base.html" %}
{% load wagtailcore_tags %}
{% block content %}
<section>
<h1 class="head-alt-md md:head-alt-lg max-w-5xl mb-4">{{ page.title }}</h1>
{# TODO tags #}
{% comment %}
{% if tags %}
<nav>
<button class="btn btn--grey-125 btn--condensed">
<div class="btn__body ">Zobrazit vše</div>
</button>
<button class="btn btn--grey-125 btn--condensed">
<div class="btn__body ">Kategorie 1</div>
</button>
<button class="btn btn--grey-125 btn--condensed">
<div class="btn__body ">Kategorie 2</div>
</button>
<button class="btn btn--grey-125 btn--condensed">
<div class="btn__body ">Kategorie 3</div>
</button>
{% if active_tag %}
<a href="{% pageurl page %}" class="btn btn--grey-125 btn--condensed">
<div class="btn__body ">zobrazit vše</div>
</a>
{% endif %}
{% for tag in tags %}
<a href="{% pageurl page %}?tag={{ tag }}"
class="btn {% if tag.name == active_tag %}btn--grey-500{% else %}btn--grey-125{% endif %} btn--condensed">
<div class="btn__body ">{{ tag }}</div>
</a>
{% endfor %}
</nav>
{% endcomment %}
{% endif %}
<hr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment