Skip to content
Snippets Groups Projects
Commit 939024e5 authored by Tomi Valentová's avatar Tomi Valentová
Browse files

fix tag display / filtering

parent 1fd57d62
Branches
Tags
2 merge requests!1114fix tag display / filtering,!1113fix tag display / filtering
Pipeline #19408 passed
Showing
with 214 additions and 28 deletions
......@@ -66,6 +66,7 @@ class DistrictArticlesPageForm(SharedArticlesPageForm, JekyllImportForm):
content_object__in=self.instance.get_children().specific()
).values_list('tag_id', flat=True).distinct().all())
valid_tag_ids += list(self.instance.shared_tags.all())
valid_shared_tag_ids = self.instance.shared_tags.values_list('id', flat=True).distinct().all()
self.fields['displayed_tags'].queryset = DistrictArticleTag.objects.filter(id__in=valid_tag_ids).order_by("tag__name").distinct("tag__name")
self.fields['displayed_shared_tags'].queryset = SharedTag.objects.filter(id__in=valid_shared_tag_ids).order_by("name").distinct("name")
\ No newline at end of file
# Generated by Django 5.0.7 on 2024-08-08 12:30
import modelcluster.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('district', '0270_alter_districtarticlespage_show_tags'),
('shared', '0010_alter_octopusperson_photo'),
]
operations = [
migrations.AddField(
model_name='districtarticlespage',
name='displayed_shared_tags',
field=modelcluster.fields.ParentalManyToManyField(blank=True, related_name='+', to='shared.sharedtag', verbose_name='Pro sdílení mezi weby'),
),
migrations.AlterField(
model_name='districtarticlespage',
name='displayed_tags',
field=modelcluster.fields.ParentalManyToManyField(blank=True, related_name='+', to='district.districtarticletag', verbose_name='Z tohoto oblastního webu'),
),
]
......@@ -305,8 +305,15 @@ class DistrictArticlesPage(MainArticlesPageMixin):
displayed_tags = ParentalManyToManyField(
"district.DistrictArticleTag",
verbose_name="Zobrazené štítky",
help_text="Pokud nejsou žádné štítky vybrané, zobrazí se nejpoužívanějších 30.",
verbose_name="Z tohoto oblastního webu",
related_name="+",
blank=True,
)
displayed_shared_tags = ParentalManyToManyField(
"shared.SharedTag",
verbose_name="Sdílecí",
related_name="+",
blank=True,
)
......
# Generated by Django 5.0.7 on 2024-08-08 12:30
import modelcluster.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('elections', '0053_alter_electionsarticlespage_show_tags'),
('shared', '0010_alter_octopusperson_photo'),
]
operations = [
migrations.AddField(
model_name='electionsarticlespage',
name='displayed_shared_tags',
field=modelcluster.fields.ParentalManyToManyField(blank=True, related_name='+', to='shared.sharedtag', verbose_name='Pro sdílení mezi weby'),
),
migrations.AlterField(
model_name='electionsarticlespage',
name='displayed_tags',
field=modelcluster.fields.ParentalManyToManyField(blank=True, related_name='+', to='elections.electionsarticletag', verbose_name='Z tohoto webu'),
),
]
......@@ -132,8 +132,15 @@ class ElectionsArticlesPage(MainArticlesPageMixin):
displayed_tags = ParentalManyToManyField(
"elections.ElectionsArticleTag",
verbose_name="Zobrazené štítky",
help_text="Pokud nejsou žádné štítky vybrané, zobrazí se nejpoužívanějších 20.",
verbose_name="Z tohoto webu",
related_name="+",
blank=True,
)
displayed_shared_tags = ParentalManyToManyField(
"shared.SharedTag",
verbose_name="Sdílecí",
related_name="+",
blank=True,
)
......
# Generated by Django 5.0.7 on 2024-08-08 12:30
import modelcluster.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('main', '0113_alter_mainarticlespage_show_tags'),
('shared', '0010_alter_octopusperson_photo'),
]
operations = [
migrations.AddField(
model_name='mainarticlespage',
name='displayed_shared_tags',
field=modelcluster.fields.ParentalManyToManyField(blank=True, related_name='+', to='shared.sharedtag', verbose_name='Pro sdílení mezi weby'),
),
migrations.AlterField(
model_name='mainarticlespage',
name='displayed_tags',
field=modelcluster.fields.ParentalManyToManyField(blank=True, related_name='+', to='main.mainarticletag', verbose_name='Z tohoto webu'),
),
]
......@@ -138,8 +138,15 @@ class MainArticlesPage(MainArticlesPageMixin):
displayed_tags = ParentalManyToManyField(
"main.MainArticleTag",
verbose_name="Zobrazené štítky",
help_text="Pokud nejsou žádné štítky vybrané, zobrazí se nejpoužívanějších 20.",
verbose_name="Z tohoto webu",
related_name="+",
blank=True,
)
displayed_shared_tags = ParentalManyToManyField(
"shared.SharedTag",
verbose_name="Sdílecí",
related_name="+",
blank=True,
)
......
......@@ -81,10 +81,20 @@ class ArticlesPageForm(ClusterForm):
displayed_tags = TagModelChoiceField(
queryset=None,
required=False,
label="Zobrazené štítky",
help_text="Pokud nejsou žádné štítky vybrané, zobrazí se nejpoužívanějších 30.",
label="Z tohoto webu",
widget=CheckboxSelectMultiple
)
displayed_shared_tags = ModelMultipleChoiceField(
queryset=None,
required=False,
label="Sdílecí",
help_text=(
"Aby se zde zobrazily štítky, je nutné nejdříve vybrat "
"odebírané štítky v sekci níže a publikovat stránku."
),
widget=CheckboxSelectMultiple
)
shared_tags = ModelMultipleChoiceField(
queryset=None,
required=False,
......
......@@ -655,6 +655,7 @@ class ArticlesMixin:
Materializes article query as article type corresponding to the module from which
this function is run. Put query from append_all_shared_articles_query as results parameter.
"""
# To prevent circular deps, we get class models during runtime
page_type = self.determine_page_type()
......@@ -929,6 +930,8 @@ class ArticlesMixin:
class SharedTag(TagBase):
is_shared = True
class Meta:
verbose_name = "sdílený tag"
verbose_name_plural = "sdílené tagy"
......@@ -1271,6 +1274,11 @@ class MainArticlesPageMixin(
# NOTE: Must be defined in mixed-in models
raise NotImplementedError
@property
def displayed_shared_tags(self):
# NOTE: Must be defined in mixed-in models
raise NotImplementedError
last_import_log = models.TextField(
"Výstup z posledního importu", null=True, blank=True
)
......@@ -1306,7 +1314,16 @@ class MainArticlesPageMixin(
content_panels = Page.content_panels + [
FieldPanel("perex"),
FieldPanel("show_tags"),
MultiFieldPanel(
[
HelpPanel(
"Pokud nejsou žádné štítky vybrané, zobrazí se nejpoužívanějších 30."
),
FieldPanel("displayed_tags"),
FieldPanel("displayed_shared_tags"),
],
heading="Zobrazené štítky"
),
FieldPanel("shared_tags"),
]
promote_panels = make_promote_panels()
......@@ -1338,16 +1355,25 @@ class MainArticlesPageMixin(
def get_base_shared_articles_query(self, filter: models.Q):
return self.materialize_shared_articles_query(
self.append_all_shared_articles_query(
(
self.root_page.article_page_model.objects.filter(filter)
.live()
.child_of(self)
.all()
).order_by("-union_timestamp")
),
custom_article_query=lambda query: query.filter(filter)
).order_by("-union_timestamp"),
)
def get_search_filters(self, request):
filter = models.Q()
if "shared_tag_id" in request.GET:
shared_tag = self.get_shared_filtered_tag(request)
if shared_tag is not None:
filter = filter & models.Q(shared_tags__id=shared_tag.id)
if "tag_id" in request.GET:
tag = self.get_filtered_tag(request)
......@@ -1359,6 +1385,15 @@ class MainArticlesPageMixin(
return filter
def get_shared_filtered_tag(self, request) -> SharedTag | None:
if "shared_tag_id" in request.GET:
try:
return SharedTag.objects.filter(id=int(request.GET["shared_tag_id"])).first()
except Exception:
pass
return None
def get_filtered_tag(self, request) -> Tag | None:
if "tag_id" in request.GET:
try:
......@@ -1381,6 +1416,11 @@ class MainArticlesPageMixin(
if filtered_tag is not None:
ctx["filtered_tag"] = filtered_tag
shared_filtered_tag = self.get_shared_filtered_tag(request)
if shared_filtered_tag is not None:
ctx["filtered_tag"] = shared_filtered_tag
search_query = self.get_search_query(request)
if search_query is not None:
......@@ -1401,13 +1441,14 @@ class MainArticlesPageMixin(
ctx["article_count"] = len(articles)
displayed_tags = self.displayed_tags.order_by("tag__name").all()
displayed_shared_tags = self.displayed_shared_tags.order_by("name").all()
if len(displayed_tags) != 0:
if len(displayed_tags) != 0 or len(displayed_shared_tags) != 0:
tags = [
tag.tag
for tag
in displayed_tags
]
] + list(displayed_shared_tags)
else:
tags = []
tag_count = {}
......
{% if tags_are_selectable %}
<a
href="?tag_id={{ id }}"
href="?{% if tag_is_shared %}shared_{% endif %}tag_id={{ id }}"
{% else %}
<span
{% endif %}
......
......@@ -18,12 +18,18 @@
</div>
<a href="{{ article.url }}" class="mb-2 underline-offset-4">
<h2 class="font-alt text-4xl">{{ article.title }}</h2>
<h2 class="font-alt text-4xl">
{{ article.title }}
</h2>
</a>
{% if article.tags %}
{% if article.shared_from and article.shared_tags %}
<div class="mb-6">
{% include 'styleguide2/includes/molecules/tags/inline_tags.html' with tags=article.get_tags tags_are_selectable=True %}
{% include 'styleguide2/includes/molecules/tags/inline_tags.html' with tags=article.shared_tags.all tags_are_selectable=True tag_is_shared=True %}
</div>
{% elif article.tags %}
<div class="mb-6">
{% include 'styleguide2/includes/molecules/tags/inline_tags.html' with tags=article.tags.all tags_are_selectable=True tag_is_shared=False %}
</div>
{% endif %}
......
......@@ -12,7 +12,7 @@
"
>
{% for tag in tags %}
{% include 'styleguide2/includes/atoms/tags/tag.html' with text=tag.name id=tag.id color_classes=tag_color_classes%}
{% include 'styleguide2/includes/atoms/tags/tag.html' with tag_is_shared=tag.is_shared text=tag.name id=tag.id color_classes=tag_color_classes %}
{% endfor %}
{% if extra_tag and extra_tag not in tags %}
......@@ -22,7 +22,7 @@
{% if filtered_tag %}
<a
href="?tag_id="
href="?"
class="
{% if reset_classes %}
{{ reset_classes }}
......
# Generated by Django 5.0.7 on 2024-08-08 12:30
import modelcluster.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('shared', '0010_alter_octopusperson_photo'),
('uniweb', '0108_alter_uniwebarticlesindexpage_show_tags'),
]
operations = [
migrations.AddField(
model_name='uniwebarticlesindexpage',
name='displayed_shared_tags',
field=modelcluster.fields.ParentalManyToManyField(blank=True, related_name='+', to='shared.sharedtag', verbose_name='Pro sdílení mezi weby'),
),
migrations.AlterField(
model_name='uniwebarticlesindexpage',
name='displayed_tags',
field=modelcluster.fields.ParentalManyToManyField(blank=True, related_name='+', to='uniweb.uniwebarticletag', verbose_name='Z tohoto webu'),
),
]
......@@ -340,8 +340,15 @@ class UniwebArticlesIndexPage(MainArticlesPageMixin):
displayed_tags = ParentalManyToManyField(
"uniweb.UniwebArticleTag",
verbose_name="Zobrazené štítky",
help_text="Pokud nejsou žádné štítky vybrané, zobrazí se nejpoužívanějších 20.",
verbose_name="Z tohoto webu",
related_name="+",
blank=True,
)
displayed_shared_tags = ParentalManyToManyField(
"shared.SharedTag",
verbose_name="Sdílecí",
related_name="+",
blank=True,
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment