Esempio n. 1
0
def updated_threads():
	viewable = get_viewable_forum_ids()

	threads = fetch_threads_and_threadread_query().\
			filter(Thread.forum_id.in_(viewable)).\
			limit(50)

	if not g.user:
		threads = add_null_entities(threads)

	return render_template('thread_list.html',
		mode='updated_threads',
		threads=threads)
Esempio n. 2
0
def view_forum(slug):
	forum = Forum.query.filter_by(slug=slug).first()
	if not forum:
		abort(404)
	if not forum.can_be_viewed_by(g.user):
		abort(403)


	base_query = fetch_threads_and_threadread_query().\
		filter(Thread.forum == forum)
	query = base_query.filter(Thread.is_stickied==False)
	pagenum = int(request.args.get('page', 1))

	pagination = query.paginate(pagenum, THREADS_PER_PAGE, error_out=False)

	stickies = base_query.filter(Thread.is_stickied==True).all()

	if not g.user:
		pagination.items = add_null_entities(pagination.items)
		stickies = add_null_entities(stickies)

	return render_template('thread_list.html',
		mode='forum', forum=forum, stickies=stickies,
		threads=pagination.items, pagination=pagination)
Esempio n. 3
0
def forum_index():
	c_query = db.session.query(Category).order_by('position')

	if g.user:
		on_clause = db.and_(
			Thread.id == ThreadRead.thread_id,
			ThreadRead.user_id == g.user.id)

		condition = db.case(
			whens=((ThreadRead.time == None, true()),),
			else_=Thread.last_updated_at > ThreadRead.time)

		subquery = db.session.query(db.func.count(Thread.id)).\
			outerjoin(ThreadRead, on_clause).\
			correlate(Forum).\
			filter(Thread.forum_id == Forum.id, condition).\
			as_scalar()

		entities = (Forum, subquery)
	else:
		entities = (Forum,)

	f_query = db.Query(entities, session=db.session()).\
		order_by(Forum.position).\
		options(joinedload('last_thread'), joinedload('last_thread.last_poster'))

	categories = []
	forum_lists = {}
	for category in c_query:
		list = []
		forum_lists[category.id] = list
		categories.append((category, list))

	if g.user:
		forums = f_query
	else:
		forums = add_null_entities(f_query, 0)

	for forum, unread_count in forums:
		forum_lists[forum.category_id].append((forum, unread_count))

	return render_template('forum_index.html', categories=categories)