Browse Source

Show a group's scheduled topics in its sidebar

This adds a list of a group's recurring scheduled topics to its sidebar,
linking to the newest topic for each one.
merge-requests/85/head
Deimos 5 years ago
parent
commit
7c2d95709a
  1. 11
      tildes/tildes/templates/topic_listing.jinja2
  2. 27
      tildes/tildes/views/topic.py

11
tildes/tildes/templates/topic_listing.jinja2

@ -231,6 +231,17 @@
</ul> </ul>
{% endif %} {% endif %}
{% if most_recent_scheduled_topics %}
<ul class="nav">
<li>Recurring scheduled topics</li>
<ul class="nav">
{% for scheduled_topic in most_recent_scheduled_topics %}
<li class="nav-item"><a href="{{ scheduled_topic.permalink }}">{{ scheduled_topic.title }}</a></li>
{% endfor %}
</ul>
</ul>
{% endif %}
{% if wiki_pages or wiki_has_index %} {% if wiki_pages or wiki_has_index %}
<ul class="nav"> <ul class="nav">
<li>Group wiki pages</li> <li>Group wiki pages</li>

27
tildes/tildes/views/topic.py

@ -15,7 +15,7 @@ from pyramid.request import Request
from pyramid.response import Response from pyramid.response import Response
from pyramid.view import view_config from pyramid.view import view_config
from sqlalchemy import cast from sqlalchemy import cast
from sqlalchemy.sql.expression import any_, desc
from sqlalchemy.sql.expression import any_, desc, text
from sqlalchemy_utils import Ltree from sqlalchemy_utils import Ltree
from webargs.pyramidparser import use_kwargs from webargs.pyramidparser import use_kwargs
from zope.sqlalchemy import mark_changed from zope.sqlalchemy import mark_changed
@ -32,7 +32,7 @@ from tildes.lib.datetime import SimpleHoursPeriod
from tildes.models.comment import Comment, CommentNotification, CommentTree from tildes.models.comment import Comment, CommentNotification, CommentTree
from tildes.models.group import Group, GroupWikiPage from tildes.models.group import Group, GroupWikiPage
from tildes.models.log import LogComment, LogTopic from tildes.models.log import LogComment, LogTopic
from tildes.models.topic import Topic, TopicVisit
from tildes.models.topic import Topic, TopicSchedule, TopicVisit
from tildes.models.user import UserGroupSettings from tildes.models.user import UserGroupSettings
from tildes.schemas.comment import CommentSchema from tildes.schemas.comment import CommentSchema
from tildes.schemas.fields import Enum, ShortTimePeriod from tildes.schemas.fields import Enum, ShortTimePeriod
@ -240,6 +240,28 @@ def get_group_topics(
wiki_pages = None wiki_pages = None
wiki_has_index = False wiki_has_index = False
if isinstance(request.context, Group):
# Get the most recent topic from each scheduled topic in this group
# I'm not even going to attempt to write this query in pure SQLAlchemy
topic_id_subquery = """
SELECT topic_id FROM (SELECT topic_id, schedule_id, row_number() OVER
(PARTITION BY schedule_id ORDER BY created_time DESC) AS rownum FROM topics)
AS t WHERE schedule_id IS NOT NULL AND rownum = 1
"""
most_recent_scheduled_topics = (
request.query(Topic)
.join(TopicSchedule)
.filter(
Topic.topic_id.in_(text(topic_id_subquery)), # type: ignore
TopicSchedule.group == request.context,
TopicSchedule.next_post_time != None, # noqa
)
.order_by(TopicSchedule.next_post_time)
.all()
)
else:
most_recent_scheduled_topics = None
return { return {
"group": request.context, "group": request.context,
"groups": groups, "groups": groups,
@ -258,6 +280,7 @@ def get_group_topics(
"wiki_pages": wiki_pages, "wiki_pages": wiki_pages,
"wiki_has_index": wiki_has_index, "wiki_has_index": wiki_has_index,
"subgroups": subgroups, "subgroups": subgroups,
"most_recent_scheduled_topics": most_recent_scheduled_topics,
} }

Loading…
Cancel
Save