add unread count to thread title in topic view
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from flask import Blueprint, redirect, url_for, render_template, request, session, abort
|
||||
|
||||
from ..models import Topics, Threads
|
||||
from ..models import Topics, Threads, Subscriptions
|
||||
from ..auth import get_active_user
|
||||
import math
|
||||
|
||||
bp = Blueprint('topics', __name__, url_prefix = '/topics/')
|
||||
@@ -33,7 +34,15 @@ def topic(topic_id, slug):
|
||||
page = max(1, min(int(request.args.get('page', default=1)), page_count))
|
||||
except ValueError:
|
||||
abort(404)
|
||||
return render_template('topics/topic.html', topic=topic, threads=topic.get_threads(PER_PAGE, page, sort_by), sort_by=sort_by, page=page, page_count=page_count)
|
||||
threads = topic.get_threads(PER_PAGE, page, sort_by)
|
||||
subscriptions = {}
|
||||
user = get_active_user()
|
||||
if user:
|
||||
for thread in threads:
|
||||
subscription = Subscriptions.find({'user_id': user.id, 'thread_id': thread['id']})
|
||||
if subscription:
|
||||
subscriptions[thread['id']] = subscription.get_unread_count()
|
||||
return render_template('topics/topic.html', topic=topic, threads=threads, sort_by=sort_by, page=page, page_count=page_count, subscriptions=subscriptions)
|
||||
|
||||
@bp.get('/<int:topic_id>/feed.atom/')
|
||||
def feed(topic_id):
|
||||
|
||||
Reference in New Issue
Block a user