add new thread route
This commit is contained in:
@@ -16,7 +16,7 @@ def thread(slug):
|
||||
posts_count = Posts.count({'thread_id': thread.id})
|
||||
page_count = max(1, math.ceil(posts_count / PER_PAGE))
|
||||
page = 1
|
||||
after = request.args.get('after', default=None)
|
||||
after = request.args.get('after')
|
||||
if after is not None:
|
||||
try:
|
||||
after_id = int(after)
|
||||
@@ -56,7 +56,37 @@ def feed(slug):
|
||||
def new():
|
||||
topics = Topics.select()
|
||||
try:
|
||||
selected_topic = int(request.args.get('topic_id', default=None))
|
||||
selected_topic = int(request.args.get('topic_id'))
|
||||
except ValueError, TypeError:
|
||||
selected_topic = None
|
||||
return render_template('threads/new_thread.html', topics=topics, selected_topic=selected_topic)
|
||||
|
||||
@bp.post('/new')
|
||||
@login_required
|
||||
def new_post():
|
||||
try:
|
||||
topic_id = int(request.form.get('topic_id'))
|
||||
except ValueError, TypeError:
|
||||
abort(404)
|
||||
topic_id = int(topic_id)
|
||||
topic = Topics.find({'id': topic_id})
|
||||
if not topic:
|
||||
abort(404)
|
||||
|
||||
user = get_active_user()
|
||||
if not user.can_post_to_topic(topic):
|
||||
abort(404)
|
||||
|
||||
title = request.form.get('title')
|
||||
if not title:
|
||||
abort(404)
|
||||
|
||||
if not title.strip():
|
||||
abort(404)
|
||||
|
||||
title = title.strip()
|
||||
|
||||
content = request.form.get('babycode_content')
|
||||
|
||||
thread = Threads.new(user.id, topic.id, title, content)
|
||||
return redirect(url_for('.thread', slug=thread.slug))
|
||||
|
||||
Reference in New Issue
Block a user