frontend for bookmark menu
This commit is contained in:
47
app/routes/hyperapi.py
Normal file
47
app/routes/hyperapi.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from flask import Blueprint, render_template, request, url_for
|
||||
from ..auth import get_active_user, is_logged_in, hard_login_required
|
||||
from ..models import BookmarkCollections
|
||||
from functools import wraps
|
||||
|
||||
bp = Blueprint('hyperapi', __name__, url_prefix='/hyperapi/')
|
||||
|
||||
def user_required(view_func):
|
||||
@wraps(view_func)
|
||||
def wrapper(*args, **kwargs):
|
||||
if get_active_user().is_guest():
|
||||
return '<span>Your account must be approved by a moderator before you may perform this action.</span>', 403
|
||||
return view_func(*args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
@bp.get('/bookmarks/dropdown/')
|
||||
@hard_login_required
|
||||
@user_required
|
||||
def get_bookmark_dropdown():
|
||||
user = get_active_user()
|
||||
concept_kind = request.args.get('concept_kind', 'thread')
|
||||
try:
|
||||
concept_id = int(request.args.get('concept_id', 0))
|
||||
except ValueError:
|
||||
return 'error', 400
|
||||
is_thread = concept_kind == 'thread'
|
||||
collections = BookmarkCollections.findall({'user_id': user.id})
|
||||
in_collection = None
|
||||
for collection in collections:
|
||||
callable = collection.has_thread if is_thread else collection.has_post
|
||||
if callable(concept_id):
|
||||
in_collection = collection.id
|
||||
break
|
||||
submit_url = url_for('.bookmark_thread' if is_thread else '.bookmark_post')
|
||||
return render_template('hyper/bookmark_dropdown.html', collections=collections, in_collection=in_collection, is_thread=is_thread, concept_id=concept_id, submit_url=submit_url)
|
||||
|
||||
@bp.post('/bookmarks/thread/')
|
||||
@hard_login_required
|
||||
@user_required
|
||||
def bookmark_thread():
|
||||
return '', 204
|
||||
|
||||
@bp.post('/bookmarks/post/')
|
||||
@hard_login_required
|
||||
@user_required
|
||||
def bookmark_post():
|
||||
return '', 204
|
||||
Reference in New Issue
Block a user