re-add rss feeds

This commit is contained in:
2026-06-10 22:30:53 +03:00
parent 50c61da8b6
commit bf3028e7d6
9 changed files with 113 additions and 12 deletions

View File

@@ -1,8 +1,10 @@
from flask import Blueprint, redirect, url_for, render_template, request, abort
from flask import Blueprint, redirect, url_for, render_template, request, abort, current_app
from functools import wraps
from app import cache
from ..auth import login_required, get_active_user, is_logged_in
from ..db import db
from ..models import Threads, Posts, Topics, Users, Reactions, Subscriptions
from ..lib.render_atom import render_atom_template
from ..util import get_form_checkbox, time_now
import math
@@ -70,9 +72,23 @@ def thread(thread_id, slug):
posts=posts, page=page,
page_count=page_count, topic=topic,
started_by=started_by, topics=Topics.get_list(),
Reactions=Reactions, last_post=last_post
Reactions=Reactions, last_post=last_post,
__feedlink=url_for('.feed', thread_id=thread_id, _external=True),
__feedtitle=f'replies to {thread.title}',
)
@bp.get('/<int:thread_id>/feed.atom/')
@cache.cached(timeout=5 * 60, unless=lambda: current_app.config['DEBUG'])
def feed(thread_id):
thread = Threads.find({'id': thread_id})
if not thread:
abort(404)
topic = Topics.find({'id': thread.topic_id})
posts = thread.get_posts_rss()
return render_atom_template('threads/thread.atom', thread=thread, topic=topic, posts=posts)
@bp.post('/<int:thread_id>/')
@login_required
def reply(thread_id):
@@ -195,10 +211,6 @@ def mark_read():
return redirect(url_for('users.inbox', username=user.username))
@bp.get('/<int:thread_id>/feed.atom/')
def feed(thread_id):
return 'stub'
@bp.get('/new/')
@login_required
def new():

View File

@@ -1,5 +1,6 @@
from flask import Blueprint, redirect, url_for, render_template, request, session, abort
from flask import Blueprint, redirect, url_for, render_template, request, session, abort, current_app
from app import cache
from ..lib.render_atom import render_atom_template
from ..models import Topics, Threads, Subscriptions
from ..auth import get_active_user
import math
@@ -42,8 +43,20 @@ def topic(topic_id, slug):
subscription = Subscriptions.find({'user_id': user.id, 'thread_id': thread['id']})
if subscription:
subscriptions[thread['id']] = subscription.get_unread_count()
return render_template('topics/topic.html', topic=topic, threads=threads, sort_by=sort_by, page=page, page_count=page_count, subscriptions=subscriptions)
return render_template(
'topics/topic.html', topic=topic,
threads=threads, sort_by=sort_by,
page=page, page_count=page_count, subscriptions=subscriptions,
__feedlink=url_for('.feed', topic_id=topic_id, _external=True),
__feedtitle=f'latest threads in {topic.name}',
)
@bp.get('/<int:topic_id>/feed.atom/')
@cache.cached(timeout=5 * 60, unless=lambda: current_app.config['DEBUG'])
def feed(topic_id):
return 'stub'
topic = Topics.find({'id': topic_id})
if not topic:
abort(404)
threads_list = topic.get_threads_with_op_rss()
return render_atom_template('topics/topic.atom', topic=topic, threads_list=threads_list)