From 97a7f853e8075e857be759d60c845a8db2f50b68 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexa=20Valentov=C3=A1?= <git@imaniti.org>
Date: Tue, 13 May 2025 17:59:02 +0200
Subject: [PATCH] Update sorting, move button to switch open/closed job
 positions

---
 main/models.py                                       | 12 ++++++++++--
 main/templates/main/main_careers_page.html           | 12 ++++++------
 shared/models/main.py                                | 11 +++++++----
 .../organisms/articles/article_links_block.html      |  2 +-
 .../organisms/articles/article_list_block.html       |  2 +-
 5 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/main/models.py b/main/models.py
index 90baea388..b56d30c04 100644
--- a/main/models.py
+++ b/main/models.py
@@ -489,13 +489,21 @@ class MainCareersPage(
 
         current_date = date.today()
 
-        if not show_closed:
+        if show_closed:
+            filter = filter & models.Q(closing_date__lt=current_date)
+        else:
             filter = filter & models.Q(closing_date__gte=current_date)
 
         if category is not None:
             filter = filter & models.Q(category=category)
 
-        return MainCareerPage.objects.child_of(self).filter(filter).live().all()
+        return (
+            MainCareerPage.objects.child_of(self)
+            .filter(filter)
+            .order_by("-created_date")
+            .live()
+            .all()
+        )
 
     class Meta:
         verbose_name = "Kariéry"
diff --git a/main/templates/main/main_careers_page.html b/main/templates/main/main_careers_page.html
index bc921775c..403a31a88 100644
--- a/main/templates/main/main_careers_page.html
+++ b/main/templates/main/main_careers_page.html
@@ -13,6 +13,12 @@
 
             <main role="main" class="mb-20">
                 <div class="container--wide">
+                    {% if not show_closed %}
+                        <a class="underline" href="?show_closed=true">Zobrazit uzavřené</a>
+                    {% else %}
+                        <a class="underline" href="?show_closed=false">Skrýt uzavřené</a>
+                    {% endif %}
+
                     <template v-if="isCurrentView('all')">
                         {% get_career_pages page show_closed as career_pages %}
 
@@ -42,12 +48,6 @@
                             {% endif %}
                         </template>
                     {% endfor %}
-
-                    {% if not show_closed %}
-                        <a class="underline" href="?show_closed=true">Zobrazit uzavřené</a>
-                    {% else %}
-                        <a class="underline" href="?show_closed=false">Skrýt uzavřené</a>
-                    {% endif %}
                 </div>
             </main>
         </ui-view-provider>
diff --git a/shared/models/main.py b/shared/models/main.py
index e8bf06fc1..0195e217a 100644
--- a/shared/models/main.py
+++ b/shared/models/main.py
@@ -1747,7 +1747,10 @@ class MainArticlePageMixin(
                 articles_with_same_tags = list(
                     all_articles_in_same_web.filter(
                         tags__in=self.get_tags,
-                    ).distinct().specific().all()
+                    )
+                    .distinct()
+                    .specific()
+                    .all()
                 )
 
                 picked_articles = []
@@ -1784,9 +1787,9 @@ class MainArticlePageMixin(
                         picked_articles
                     )
                     main_web_articles = list(
-                        MainArticlePage.objects.distinct().all().specific()[
-                            : needed_supplementary_articles_num - 1
-                        ]
+                        MainArticlePage.objects.distinct()
+                        .all()
+                        .specific()[: needed_supplementary_articles_num - 1]
                     )
 
                     picked_articles += main_web_articles
diff --git a/shared/templates/styleguide2/includes/organisms/articles/article_links_block.html b/shared/templates/styleguide2/includes/organisms/articles/article_links_block.html
index c4476eb2e..05fd7e77a 100644
--- a/shared/templates/styleguide2/includes/organisms/articles/article_links_block.html
+++ b/shared/templates/styleguide2/includes/organisms/articles/article_links_block.html
@@ -4,4 +4,4 @@
       {% include 'styleguide2/includes/molecules/articles/article_title_preview.html' %}
     {% endfor %}
   </div>
-{% endif %}
\ No newline at end of file
+{% endif %}
diff --git a/shared/templates/styleguide2/includes/organisms/articles/article_list_block.html b/shared/templates/styleguide2/includes/organisms/articles/article_list_block.html
index 2df949daf..a10c8204a 100644
--- a/shared/templates/styleguide2/includes/organisms/articles/article_list_block.html
+++ b/shared/templates/styleguide2/includes/organisms/articles/article_list_block.html
@@ -15,4 +15,4 @@
       {% include 'styleguide2/includes/molecules/articles/article_timeline_preview.html' %}
     {% endfor %}
   </div>
-{% endif %}
\ No newline at end of file
+{% endif %}
-- 
GitLab