finish that a tag in topics view
This commit is contained in:
@ -3,6 +3,7 @@ from dotenv import load_dotenv
|
|||||||
from .models import Avatars, Users
|
from .models import Avatars, Users
|
||||||
from .auth import digest
|
from .auth import digest
|
||||||
from .routes.users import is_logged_in, get_active_user
|
from .routes.users import is_logged_in, get_active_user
|
||||||
|
from .routes.threads import get_post_url
|
||||||
from .constants import (
|
from .constants import (
|
||||||
PermissionLevel, permission_level_string,
|
PermissionLevel, permission_level_string,
|
||||||
InfoboxKind, InfoboxIcons, InfoboxHTMLClass,
|
InfoboxKind, InfoboxIcons, InfoboxHTMLClass,
|
||||||
@ -116,6 +117,12 @@ def create_app():
|
|||||||
def inject_auth():
|
def inject_auth():
|
||||||
return {"is_logged_in": is_logged_in, "get_active_user": get_active_user, "active_user": get_active_user()}
|
return {"is_logged_in": is_logged_in, "get_active_user": get_active_user, "active_user": get_active_user()}
|
||||||
|
|
||||||
|
@app.context_processor
|
||||||
|
def inject_funcs():
|
||||||
|
return {
|
||||||
|
'get_post_url': get_post_url,
|
||||||
|
}
|
||||||
|
|
||||||
@app.template_filter("ts_datetime")
|
@app.template_filter("ts_datetime")
|
||||||
def ts_datetime(ts, format):
|
def ts_datetime(ts, format):
|
||||||
return datetime.utcfromtimestamp(ts or int(time.time())).strftime(format)
|
return datetime.utcfromtimestamp(ts or int(time.time())).strftime(format)
|
||||||
|
@ -13,6 +13,20 @@ import time
|
|||||||
bp = Blueprint("threads", __name__, url_prefix = "/threads/")
|
bp = Blueprint("threads", __name__, url_prefix = "/threads/")
|
||||||
|
|
||||||
|
|
||||||
|
def get_post_url(post_id, _anchor=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
|
||||||
|
|
||||||
|
return f"{res}#post-{post_id}"
|
||||||
|
|
||||||
|
|
||||||
@bp.get("/<slug>")
|
@bp.get("/<slug>")
|
||||||
def thread(slug):
|
def thread(slug):
|
||||||
POSTS_PER_PAGE = 10
|
POSTS_PER_PAGE = 10
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
{% if topic['id'] in active_threads %}
|
{% if topic['id'] in active_threads %}
|
||||||
{% with thread=active_threads[topic['id']] %}
|
{% with thread=active_threads[topic['id']] %}
|
||||||
<span>
|
<span>
|
||||||
Latest post in: <a href="{{ url_for("threads.thread", slug=thread['thread_slug'])}}">{{ thread['thread_title'] }}</a> by <a href="{{ url_for("users.page", username=thread['username'])}}">{{ thread['username'] }}</a> at <a href="">{{ timestamp(thread['post_created_at']) }}</a>
|
Latest post in: <a href="{{ url_for("threads.thread", slug=thread['thread_slug'])}}">{{ thread['thread_title'] }}</a> by <a href="{{ url_for("users.page", username=thread['username'])}}">{{ thread['username'] }}</a> at <a href="{{ get_post_url(thread.post_id, _anchor=true) }}">{{ timestamp(thread['post_created_at']) }}</a>
|
||||||
</span>
|
</span>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Reference in New Issue
Block a user