From a97b2b5b15ae06c8a3043bd9dfb01bef7ea5afd3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomi=20Valentov=C3=A1?= <git@imaniti.org>
Date: Tue, 6 Aug 2024 20:32:41 +0200
Subject: [PATCH] fix tag loading

---
 district/forms.py                                          | 7 ++++---
 elections/templates/elections/elections_articles_page.html | 2 +-
 uniweb/forms.py                                            | 6 +++---
 uniweb/templates/uniweb/uniweb_articles_index_page.html    | 2 +-
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/district/forms.py b/district/forms.py
index cf75cf00..32038916 100644
--- a/district/forms.py
+++ b/district/forms.py
@@ -62,9 +62,10 @@ class DistrictArticlesPageForm(SharedArticlesPageForm, JekyllImportForm):
         self.fields["shared_tags"].queryset = SharedTag.objects.order_by("name")
 
         if self.instance.pk:
-            # Get tags assigned to child DistrictArticlePage instances
-            valid_tag_ids = DistrictArticleTag.objects.filter(
+            valid_tag_ids = list(DistrictArticleTag.objects.filter(
                 content_object__in=self.instance.get_children().specific()
-            ).values_list('tag_id', flat=True).distinct()
+            ).values_list('tag_id', flat=True).distinct().all())
+
+            valid_tag_ids += list(self.instance.shared_tags.all())
             
             self.fields['displayed_tags'].queryset = DistrictArticleTag.objects.filter(id__in=valid_tag_ids).order_by("tag__name")
\ No newline at end of file
diff --git a/elections/templates/elections/elections_articles_page.html b/elections/templates/elections/elections_articles_page.html
index 6fd46685..6a0f9e8c 100644
--- a/elections/templates/elections/elections_articles_page.html
+++ b/elections/templates/elections/elections_articles_page.html
@@ -2,7 +2,7 @@
 
 {% block content %}
   {% include 'styleguide2/includes/organisms/layout/elections/navbar.html' with selected_item=page.get_menu_title %}
-  {% include 'styleguide2/includes/organisms/header/elections/articles_header.html' with title=page.title tags=tags %}
+  {% include 'styleguide2/includes/organisms/header/elections/articles_header.html' with show_tags=page.show_tags title=page.title tags=tags %}
 
   <main role="main">
     {% include 'styleguide2/includes/organisms/articles/main_articles_timeline.html' %}
diff --git a/uniweb/forms.py b/uniweb/forms.py
index 59ca31ca..94b293c4 100644
--- a/uniweb/forms.py
+++ b/uniweb/forms.py
@@ -32,6 +32,6 @@ class UniwebArticlesPageForm(SharedArticlesPageForm, WagtailAdminPageForm):
         if self.instance.pk:
             valid_tag_ids = UniwebArticleTag.objects.filter(
                 content_object__in=self.instance.get_children().specific()
-            ).values_list('tag_id', flat=True).distinct()
-            
-            self.fields['displayed_tags'].queryset = UniwebArticleTag.objects.filter(id__in=valid_tag_ids).order_by("tag__name")
\ No newline at end of file
+            ).values_list('id', flat=True).distinct()
+
+            self.fields['displayed_tags'].queryset = UniwebArticleTag.objects.filter(id__in=valid_tag_ids).order_by("tag__name").distinct("tag__name")
\ No newline at end of file
diff --git a/uniweb/templates/uniweb/uniweb_articles_index_page.html b/uniweb/templates/uniweb/uniweb_articles_index_page.html
index 6e6c2c11..1e1a317e 100644
--- a/uniweb/templates/uniweb/uniweb_articles_index_page.html
+++ b/uniweb/templates/uniweb/uniweb_articles_index_page.html
@@ -4,7 +4,7 @@
 {% block content %}
 
 {% include 'styleguide2/includes/organisms/layout/district/navbar.html' with selected_item=page.get_menu_title %}
-{% include 'styleguide2/includes/organisms/header/articles_header.html' with title=page.title tags=tags %}
+{% include 'styleguide2/includes/organisms/header/articles_header.html' with title=page.title tags=tags show_tags=page.show_tags %}
 
 <main role="main">
   {% include 'styleguide2/includes/organisms/articles/main_articles_timeline.html' %}
-- 
GitLab