diff --git a/scipost_django/forums/migrations/0012_alter_meeting_options.py b/scipost_django/forums/migrations/0012_alter_meeting_options.py new file mode 100644 index 0000000000000000000000000000000000000000..b9af8685b83f3bb96510c1727a02a5af78434c2b --- /dev/null +++ b/scipost_django/forums/migrations/0012_alter_meeting_options.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.16 on 2023-01-29 14:03 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('forums', '0011_alter_motion_accepted'), + ] + + operations = [ + migrations.AlterModelOptions( + name='meeting', + options={'ordering': ['-date_until']}, + ), + ] diff --git a/scipost_django/forums/models.py b/scipost_django/forums/models.py index 240934aec156fe88748f5aa839c95b41c313968c..212406cd603db2309d5596f1fe33acaf0901d0ca 100644 --- a/scipost_django/forums/models.py +++ b/scipost_django/forums/models.py @@ -149,6 +149,11 @@ class Meeting(Forum): ) objects = models.Manager() + class Meta: + ordering = [ + "-date_until", + ] + def __str__(self): return "%s, [%s to %s]" % ( self.forum, diff --git a/scipost_django/forums/templates/forums/forum_as_li.html b/scipost_django/forums/templates/forums/forum_as_li.html index 90415ecd23c4ffa3ae9984eaf423ec1680c8f9ad..b3a26a66a4f8b801f4791d61d1e308f92689b014 100644 --- a/scipost_django/forums/templates/forums/forum_as_li.html +++ b/scipost_django/forums/templates/forums/forum_as_li.html @@ -1,6 +1,6 @@ <li class="d-flex flex-wrap justify-content-between"> <a href="{{ forum.get_absolute_url }}">{{ forum }}</a> - <span class="badge bg-secondary rounded-pill">{% with nr_posts=forum.nr_posts %}{{ nr_posts }} post{{ nr_posts|pluralize }}{% endwith %}</span> + <span class="badge bg-primary rounded-pill">{% with nr_posts=forum.nr_posts %}{{ nr_posts }} post{{ nr_posts|pluralize }}{% endwith %}</span> {% if forum.child_forums.all|length > 0 %} <ul class="list-unstyled forumList"> {% for child in forum.child_forums.all %} diff --git a/scipost_django/forums/templates/forums/forum_list.html b/scipost_django/forums/templates/forums/forum_list.html index 457eccf5f40ca0f9f9f451a92a83a5c2b1a42016..d2efcda139d334caf6da29c9af544a784da03773 100644 --- a/scipost_django/forums/templates/forums/forum_list.html +++ b/scipost_django/forums/templates/forums/forum_list.html @@ -45,7 +45,13 @@ {% endif %} <span class="d-flex flex-wrap justify-content-between"> <a href="{{ forum.get_absolute_url }}">{{ forum|truncatechars:30 }}</a> - <span class="badge bg-primary rounded-pill">{% with nr_posts=forum.nr_posts %}{{ nr_posts }} post{{ nr_posts|pluralize }}{% endwith %}</span> + {% with nr_posts=forum.nr_posts %} + {% if nr_posts %} + <span class="badge bg-primary rounded-pill"> + {{ nr_posts }} post{{ nr_posts|pluralize }} + {% endif %} + {% endwith %} + </span> </span> </div> <div class="card-body"> @@ -54,7 +60,7 @@ <hr/> <p>Descendants:</p> <ul class="list-unstyled forumList"> - {% for child in forum.child_forums.all %} + {% for child in forum.child_forums.all reversed %} {% include 'forums/forum_as_li.html' with forum=child %} {% endfor %} </ul> @@ -83,12 +89,16 @@ </thead> <tbody> {% for forum in object_list %} - <tr> - <td><a href="{{ forum.get_absolute_url }}">{{ forum }}</a></td> - <td>{{ forum.latest_post }}</td> - <td>{{ forum.latest_post.posted_on|date:"Y-m-d" }}</td> - <td><span class="badge bg-primary rounded-pill">{{ forum.nr_posts }}</span></td> - </tr> + {% with formul.latest_post as latest_post %} + {% if latest_post %} + <tr> + <td><a href="{{ forum.get_absolute_url }}">{{ forum }}</a></td> + <td>{{ forum.latest_post }}</td> + <td>{{ forum.latest_post.posted_on|date:"Y-m-d" }}</td> + <td><span class="badge bg-primary rounded-pill">{{ forum.nr_posts }}</span></td> + </tr> + {% endif %} + {% endwith %} {% empty %} <tr> <td>No visible Posts found.</td> diff --git a/scipost_django/forums/views.py b/scipost_django/forums/views.py index 8dd189e6df3466641bbcad068c12ea26f1ff27aa..a5c0f4ff2839e7029d7f92b5cd0a2852732e45c1 100644 --- a/scipost_django/forums/views.py +++ b/scipost_django/forums/views.py @@ -176,7 +176,10 @@ class ForumListView(LoginRequiredMixin, ListView): def get_queryset(self): queryset = get_objects_for_user( self.request.user, "forums.can_view_forum" - ).anchors() + ).anchors().select_related("meeting").prefetch_related( + "posts" + "__followup_posts" * 3, + "child_forums__posts" + "__followup_posts" * 7, + ) return queryset