Add topic searching and topic discarding
This commit is contained in:
@@ -19,7 +19,7 @@ from flask import *
|
||||
from flask_user import *
|
||||
from app import app
|
||||
from app.models import *
|
||||
from app.utils import is_package_page
|
||||
from app.utils import is_package_page, rank_required
|
||||
from .packages import QueryBuilder
|
||||
|
||||
@app.route("/api/packages/")
|
||||
@@ -43,3 +43,18 @@ def api_topics_page():
|
||||
.order_by(db.asc(ForumTopic.wip), db.asc(ForumTopic.name), db.asc(ForumTopic.title))
|
||||
pkgs = [t.getAsDictionary() for t in query.all()]
|
||||
return jsonify(pkgs)
|
||||
|
||||
|
||||
@app.route("/api/topic_discard/", methods=["POST"])
|
||||
@rank_required(UserRank.EDITOR)
|
||||
def topic_set_discard():
|
||||
tid = request.args.get("tid")
|
||||
discard = request.args.get("discard")
|
||||
if tid is None or discard is None:
|
||||
abort(400)
|
||||
|
||||
topic = ForumTopic.query.get(tid)
|
||||
topic.discarded = discard == "true"
|
||||
db.session.commit()
|
||||
|
||||
return jsonify(topic.getAsDictionary())
|
||||
|
||||
@@ -54,11 +54,16 @@ def todo_page():
|
||||
@app.route("/todo/topics/")
|
||||
@login_required
|
||||
def todo_topics_page():
|
||||
total = ForumTopic.query.count()
|
||||
query = ForumTopic.query
|
||||
|
||||
query = ForumTopic.query \
|
||||
.filter(~ db.exists().where(Package.forums==ForumTopic.topic_id)) \
|
||||
.order_by(db.asc(ForumTopic.wip), db.asc(ForumTopic.name), db.asc(ForumTopic.title))
|
||||
show_discarded = request.args.get("show_discarded") == "True"
|
||||
if not show_discarded:
|
||||
query = query.filter_by(discarded=False)
|
||||
|
||||
total = query.count()
|
||||
|
||||
query = query.filter(~ db.exists().where(Package.forums==ForumTopic.topic_id)) \
|
||||
.order_by(db.asc(ForumTopic.wip), db.asc(ForumTopic.name), db.asc(ForumTopic.title))
|
||||
|
||||
topic_count = query.count()
|
||||
|
||||
@@ -75,5 +80,5 @@ def todo_topics_page():
|
||||
if query.has_prev else None
|
||||
|
||||
return render_template("todo/topics.html", topics=query.items, total=total, \
|
||||
topic_count=topic_count, query=search, \
|
||||
topic_count=topic_count, query=search, show_discarded=show_discarded, \
|
||||
next_url=next_url, prev_url=prev_url, page=page, page_max=query.pages)
|
||||
|
||||
Reference in New Issue
Block a user