add user bookmarks view

This commit is contained in:
2025-11-20 03:49:44 +03:00
parent b86e049263
commit 95decd9a56
4 changed files with 60 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ from flask import (
from functools import wraps
from ..db import db
from ..lib.babycode import babycode_to_html, BABYCODE_VERSION
from ..models import Users, Sessions, Subscriptions, Avatars, PasswordResetLinks, InviteKeys
from ..models import Users, Sessions, Subscriptions, Avatars, PasswordResetLinks, InviteKeys, BookmarkCollections
from ..constants import InfoboxKind, PermissionLevel
from ..auth import digest, verify
from wand.image import Image
@@ -260,6 +260,8 @@ def sign_up_post():
"permission": PermissionLevel.GUEST.value,
})
BookmarkCollections.create_default(new_user.id)
if current_app.config['DISABLE_SIGNUP']:
invite_key = InviteKeys.find({'key': key})
new_user.update({
@@ -688,3 +690,14 @@ def revoke_invite_link(username):
invite.delete()
return redirect(url_for('.invite_links', username=target_user.username))
@bp.get('/<username>/bookmarks')
@login_required
def bookmarks(username):
target_user = Users.find({'username': username})
if not target_user or target_user.username != get_active_user().username:
return redirect(url_for('.bookmarks', username=get_active_user().username))
collections = target_user.get_bookmark_collections()
return render_template('users/bookmarks.html', collections=collections)

View File

@@ -91,7 +91,7 @@
</form>
{% endmacro %}
{% macro full_post(post, render_sig = True, is_latest = False, editing = False, active_user = None, no_reply = false, Reactions = none) %}
{% macro full_post(post, render_sig = True, is_latest = False, editing = False, active_user = None, no_reply = false, Reactions = none, show_thread_title = false) %}
{% set postclass = "post" %}
{% if editing %}
{% set postclass = postclass + " editing" %}
@@ -112,6 +112,11 @@
<div class="post-content-container" {{ "id=latest-post" if is_latest else "" }}>
<div class="post-info">
<span>
{% if show_thread_title %}
<a href="{{ url_for('threads.thread', slug=post.thread_slug) }}">Thread: {{ post.thread_title }}</a>
&bullet;
{% endif %}
<a href="{{ post_permalink }}" title="Permalink"><i>
{% if (post['edited_at'] | int) > (post['created_at'] | int) %}
Edited on {{ timestamp(post['edited_at']) }}
@@ -119,6 +124,7 @@
Posted on {{ timestamp(post['edited_at']) }}
{% endif %}
</i></a>
</span>
<span>
{% set show_edit = false %}
{% if active_user %}

View File

@@ -20,6 +20,10 @@
&bullet;
<a href="{{ url_for('users.invite_links', username=user.username )}}">Invite to {{ config.SITE_NAME }}</a>
{% endif %}
{% if not user.is_guest() %}
&bullet;
<a href="{{ url_for('users.bookmarks', username=user.username) }}">Bookmarks</a>
{% endif %}
{% if user.is_mod() %}
&bullet;
<a href="{{ url_for("mod.user_list") }}">User list</a>

View File

@@ -0,0 +1,35 @@
{% from "common/macros.html" import accordion, full_post %}
{% extends "base.html" %}
{% block title %}bookmarks{% endblock %}
{% block content %}
<div class="darkbg inbox-container">
{% for collection in collections %}
{% call(section) accordion(disabled=collection.is_empty()) %}
{% if section == 'header' %}
<h1 class="thread-title">{{ collection.name }}</h1>{{" (no bookmarks)" if collection.is_empty() else ""}}
{% else %}
{% call(inner_section) accordion(disabled=not collection.has_threads()) %}
{% if inner_section == 'header' %}
Threads{{" (no bookmarks)" if not collection.has_threads() else ""}}
{% else %}
<ul>
{% for thread in collection.get_threads()|sort(attribute='created_at', reverse=true) %}
<li><a href="{{ url_for('threads.thread', slug=thread.slug) }}">{{ thread.title }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endcall %}
{% call(inner_section) accordion(disabled=not collection.has_posts()) %}
{% if inner_section == 'header' %}
Posts{{" (no bookmarks)" if not collection.has_posts() else ""}}
{% else %}
{% for post in collection.get_posts()|sort(attribute='created_at', reverse=true) %}
{{ full_post(post.get_full_post_view(), no_reply=false, render_sig=false, show_thread_title=true) }}
{% endfor %}
{% endif %}
{% endcall %}
{% endif %}
{% endcall %}
{% endfor %}
</div>
{% endblock %}