draw the rest of the owl
This commit is contained in:
@@ -1,31 +1,35 @@
|
||||
from flask import (
|
||||
Blueprint, render_template, request, redirect, url_for, flash,
|
||||
abort,
|
||||
abort, current_app,
|
||||
)
|
||||
from .users import login_required, mod_only, get_active_user, is_logged_in
|
||||
from ..db import db
|
||||
from ..models import Threads, Topics, Posts, Subscriptions, Reactions
|
||||
from ..constants import InfoboxKind
|
||||
from ..lib.render_atom import render_atom_template
|
||||
from .posts import create_post
|
||||
from slugify import slugify
|
||||
from app import cache
|
||||
import math
|
||||
import time
|
||||
|
||||
bp = Blueprint("threads", __name__, url_prefix = "/threads/")
|
||||
|
||||
|
||||
def get_post_url(post_id, _anchor=False):
|
||||
def get_post_url(post_id, _anchor=False, external=False):
|
||||
post = Posts.find({'id': post_id})
|
||||
if not post:
|
||||
return ""
|
||||
|
||||
thread = Threads.find({'id': post.thread_id})
|
||||
|
||||
res = url_for('threads.thread', slug=thread.slug, after=post_id)
|
||||
if not _anchor:
|
||||
return res
|
||||
anchor = None if not _anchor else f'post-{post_id}'
|
||||
|
||||
return f"{res}#post-{post_id}"
|
||||
return url_for('threads.thread', slug=thread.slug, after=post_id, _external=external, _anchor=anchor)
|
||||
# if not _anchor:
|
||||
# return res
|
||||
|
||||
# return f"{res}#post-{post_id}"
|
||||
|
||||
|
||||
@bp.get("/<slug>")
|
||||
@@ -80,9 +84,25 @@ def thread(slug):
|
||||
is_subscribed = is_subscribed,
|
||||
Reactions = Reactions,
|
||||
unread_count = unread_count,
|
||||
__feedlink = url_for('.thread_atom', slug=slug, _external=True),
|
||||
__feedtitle = f'replies to {thread.title}',
|
||||
)
|
||||
|
||||
|
||||
@bp.get("/<slug>/feed.atom")
|
||||
@cache.cached(timeout=5 * 60, unless=lambda: current_app.config.get('DEBUG', False))
|
||||
def thread_atom(slug):
|
||||
thread = Threads.find({"slug": slug})
|
||||
if not thread:
|
||||
abort(404) # TODO throw an atom friendly 404
|
||||
return
|
||||
|
||||
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, get_post_url=get_post_url)
|
||||
|
||||
|
||||
@bp.post("/<slug>")
|
||||
@login_required
|
||||
def reply(slug):
|
||||
|
||||
Reference in New Issue
Block a user