SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit e64e691e authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add quick links to anchor, latest followup posts in forums

parent 9e4c483c
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,13 @@ class ForumQuerySet(models.QuerySet):
class PostQuerySet(models.QuerySet):
def anchors(self):
"""Return only the Posts which do not have a Post as a parent."""
from django.contrib.contenttypes.models import ContentType
type_forum = ContentType.objects.get_by_natural_key('forums', 'forum')
type_meeting = ContentType.objects.get_by_natural_key('forums', 'meeting')
return self.filter(parent_content_type__in=[type_forum, type_meeting])
def motions_excluded(self):
"""Filter all Motions out of the Post queryset."""
return self.filter(motion__isnull=True)
......@@ -217,12 +217,21 @@ class Post(models.Model):
nr += self.followup_posts.all().count()
return nr
@property
def latest_followup(self):
return self.followup_posts.last()
def posts_hierarchy_id_list(self):
id_list = [self.id]
for post in self.followup_posts.all():
id_list += post.posts_hierarchy_id_list()
return id_list
@property
def latest_followup_in_hierarchy(self):
id_list = self.posts_hierarchy_id_list()
return Post.objects.filter(pk__in=id_list).exclude(pk=self.id).last()
def get_anchor_forum_or_meeting(self):
"""
Climb back the hierarchy up to the original Forum.
......
......@@ -118,7 +118,7 @@
<div class="card">
<div class="card-header">
<button class="btn btn-primary btn-small" data-bs-toggle="collapse" data-bs-target="#recentPostsLinks">
Quick links: posts and motions (click to toggle)
Quick links: all posts and motions (click to toggle)
</button>
</div>
<div class="card-body collapse" id="recentPostsLinks">
......@@ -128,7 +128,7 @@
<li>
<a href="{{ post.get_absolute_url }}">{{ post.subject }}</a> posted by {{ post.posted_by.first_name }} {{ post.posted_by.last_name }} on {{ post.posted_on|date:"Y-m-d H:m" }}
{% if post.parent and not post.motion %}
- regarding <a href="{{ post.parent.get_absolute_url }}">{{ post.parent }}</a>
- regarding <a href="{{ post.parent.get_absolute_url }}">{{ post.parent }}</a>
{% endif %}
</li>
{% endfor %}
......@@ -138,6 +138,41 @@
</div>
</div>
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">
<button class="btn btn-primary btn-small" data-bs-toggle="collapse" data-bs-target="#anchorPostsLinks">
Quick links: anchor posts, latest followup (click to toggle)
</button>
</div>
<div class="card-body collapse" id="anchorPostsLinks">
<ul>
{% for post in forum.posts_all.anchors %}
<li>
<a href="{{ post.get_absolute_url }}">{{ post.subject }}</a> posted by {{ post.posted_by.first_name }} {{ post.posted_by.last_name }} on {{ post.posted_on|date:"Y-m-d H:m" }}
<p>
{% with post.nr_followups as nr_followups %}
{{ nr_followups }} followup{{ nr_followups|pluralize }}
{% endwith %}
{% with post.latest_followup_in_hierarchy as latest_followup %}
{% if latest_followup %}
,&emsp;latest: <a href="{{ latest_followup.get_absolute_url }}">
{{ latest_followup.subject }}</a>
posted by {{ latest_followup.posted_by.first_name }}
{{ latest_followup.posted_by.last_name }}
on {{ latest_followup.posted_on|date:"Y-m-d H:m" }}
{% endif %}
{% endwith %}
</p>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<h2 class="highlight" id="Description">Description</h2>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment