replace stub returns with redirects
This commit is contained in:
parent
13c89cbde2
commit
7ab1c8745f
@ -18,7 +18,7 @@ def thread(slug):
|
|||||||
POSTS_PER_PAGE = 10
|
POSTS_PER_PAGE = 10
|
||||||
thread = Threads.find({"slug": slug})
|
thread = Threads.find({"slug": slug})
|
||||||
if not thread:
|
if not thread:
|
||||||
return "no"
|
return redirect(url_for('topics.all_topics'))
|
||||||
|
|
||||||
post_count = Posts.count({"thread_id": thread.id})
|
post_count = Posts.count({"thread_id": thread.id})
|
||||||
page_count = max(math.ceil(post_count / POSTS_PER_PAGE), 1)
|
page_count = max(math.ceil(post_count / POSTS_PER_PAGE), 1)
|
||||||
@ -69,12 +69,12 @@ def thread(slug):
|
|||||||
def reply(slug):
|
def reply(slug):
|
||||||
thread = Threads.find({"slug": slug})
|
thread = Threads.find({"slug": slug})
|
||||||
if not thread:
|
if not thread:
|
||||||
return "no"
|
return redirect(url_for('topics.all_topics'))
|
||||||
user = get_active_user()
|
user = get_active_user()
|
||||||
if user.is_guest():
|
if user.is_guest():
|
||||||
return "no"
|
return redirect(url_for('.thread', slug=slug))
|
||||||
if thread.locked() and not user.is_mod():
|
if thread.locked() and not user.is_mod():
|
||||||
return "no"
|
return redirect(url_for('.thread', slug=slug))
|
||||||
|
|
||||||
post_content = request.form['post_content']
|
post_content = request.form['post_content']
|
||||||
post = create_post(thread.id, user.id, post_content)
|
post = create_post(thread.id, user.id, post_content)
|
||||||
@ -102,10 +102,12 @@ def create_form():
|
|||||||
topic = Topics.find({"id": request.form['topic_id']})
|
topic = Topics.find({"id": request.form['topic_id']})
|
||||||
user = get_active_user()
|
user = get_active_user()
|
||||||
if not topic:
|
if not topic:
|
||||||
return "no"
|
flash('Invalid topic', InfoboxKind.ERROR)
|
||||||
|
return redirect(url_for('.create'))
|
||||||
|
|
||||||
if topic.is_locked and not get_active_user().is_mod():
|
if topic.is_locked and not get_active_user().is_mod():
|
||||||
return "no"
|
flash(f'Topic "{topic.name}" is locked', InfoboxKind.ERROR)
|
||||||
|
return redirect(url_for('.create'))
|
||||||
|
|
||||||
title = request.form['title'].strip()
|
title = request.form['title'].strip()
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
@ -128,8 +130,10 @@ def create_form():
|
|||||||
def lock(slug):
|
def lock(slug):
|
||||||
user = get_active_user()
|
user = get_active_user()
|
||||||
thread = Threads.find({'slug': slug})
|
thread = Threads.find({'slug': slug})
|
||||||
|
if not thread:
|
||||||
|
return redirect(url_for('topics.all_topics'))
|
||||||
if not ((thread.user_id == user.id) or user.is_mod()):
|
if not ((thread.user_id == user.id) or user.is_mod()):
|
||||||
return 'no'
|
return redirect(url_for('.thread', slug=slug))
|
||||||
target_op = request.form.get('target_op')
|
target_op = request.form.get('target_op')
|
||||||
thread.update({
|
thread.update({
|
||||||
'is_locked': target_op
|
'is_locked': target_op
|
||||||
@ -143,8 +147,10 @@ def lock(slug):
|
|||||||
def sticky(slug):
|
def sticky(slug):
|
||||||
user = get_active_user()
|
user = get_active_user()
|
||||||
thread = Threads.find({'slug': slug})
|
thread = Threads.find({'slug': slug})
|
||||||
|
if not thread:
|
||||||
|
return redirect(url_for('topics.all_topics'))
|
||||||
if not ((thread.user_id == user.id) or user.is_mod()):
|
if not ((thread.user_id == user.id) or user.is_mod()):
|
||||||
return 'no'
|
return redirect(url_for('.thread', slug=slug))
|
||||||
target_op = request.form.get('target_op')
|
target_op = request.form.get('target_op')
|
||||||
thread.update({
|
thread.update({
|
||||||
'is_stickied': target_op
|
'is_stickied': target_op
|
||||||
@ -167,12 +173,12 @@ def move(slug):
|
|||||||
'id': new_topic_id
|
'id': new_topic_id
|
||||||
})
|
})
|
||||||
if not new_topic:
|
if not new_topic:
|
||||||
return 'no'
|
return redirect(url_for('topics.all_topics'))
|
||||||
thread = Threads.find({
|
thread = Threads.find({
|
||||||
'slug': slug
|
'slug': slug
|
||||||
})
|
})
|
||||||
if not thread:
|
if not thread:
|
||||||
return 'no'
|
return redirect(url_for('topics.all_topics'))
|
||||||
if new_topic.id == thread.topic_id:
|
if new_topic.id == thread.topic_id:
|
||||||
flash('Thread is already in this topic.', InfoboxKind.ERROR)
|
flash('Thread is already in this topic.', InfoboxKind.ERROR)
|
||||||
return redirect(url_for('.thread', slug=slug))
|
return redirect(url_for('.thread', slug=slug))
|
||||||
@ -189,7 +195,7 @@ def subscribe(slug):
|
|||||||
user = get_active_user()
|
user = get_active_user()
|
||||||
thread = Threads.find({'slug': slug})
|
thread = Threads.find({'slug': slug})
|
||||||
if not thread:
|
if not thread:
|
||||||
return 'no'
|
return redirect(url_for('topics.all_topics'))
|
||||||
subscription = Subscriptions.find({
|
subscription = Subscriptions.find({
|
||||||
'user_id': user.id,
|
'user_id': user.id,
|
||||||
'thread_id': thread.id,
|
'thread_id': thread.id,
|
||||||
@ -204,11 +210,11 @@ def subscribe(slug):
|
|||||||
})
|
})
|
||||||
elif request.form['subscribe'] == 'unsubscribe':
|
elif request.form['subscribe'] == 'unsubscribe':
|
||||||
if not subscription:
|
if not subscription:
|
||||||
return 'no'
|
return redirect(url_for('.thread', slug=slug))
|
||||||
subscription.delete()
|
subscription.delete()
|
||||||
elif request.form['subscribe'] == 'read':
|
elif request.form['subscribe'] == 'read':
|
||||||
if not subscription:
|
if not subscription:
|
||||||
return 'no'
|
return redirect(url_for('.thread', slug=slug))
|
||||||
subscription.update({
|
subscription.update({
|
||||||
'last_seen': int(time.time())
|
'last_seen': int(time.time())
|
||||||
})
|
})
|
||||||
|
@ -51,7 +51,7 @@ def topic(slug):
|
|||||||
"slug": slug
|
"slug": slug
|
||||||
})
|
})
|
||||||
if not target_topic:
|
if not target_topic:
|
||||||
return "no"
|
return redirect(url_for('.all_topics'))
|
||||||
|
|
||||||
threads_count = Threads.count({
|
threads_count = Threads.count({
|
||||||
"topic_id": target_topic.id
|
"topic_id": target_topic.id
|
||||||
@ -77,7 +77,7 @@ def topic(slug):
|
|||||||
def edit(slug):
|
def edit(slug):
|
||||||
topic = Topics.find({"slug": slug})
|
topic = Topics.find({"slug": slug})
|
||||||
if not topic:
|
if not topic:
|
||||||
return "no"
|
return redirect(url_for('.all_topics'))
|
||||||
return render_template("topics/edit.html", topic=topic)
|
return render_template("topics/edit.html", topic=topic)
|
||||||
|
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ def edit(slug):
|
|||||||
def edit_post(slug):
|
def edit_post(slug):
|
||||||
topic = Topics.find({"slug": slug})
|
topic = Topics.find({"slug": slug})
|
||||||
if not topic:
|
if not topic:
|
||||||
return "no"
|
return redirect(url_for('.all_topics'))
|
||||||
|
|
||||||
topic.update({
|
topic.update({
|
||||||
"name": request.form.get('name', default = topic.name).strip(),
|
"name": request.form.get('name', default = topic.name).strip(),
|
||||||
@ -104,7 +104,7 @@ def edit_post(slug):
|
|||||||
def delete(slug):
|
def delete(slug):
|
||||||
topic = Topics.find({"slug": slug})
|
topic = Topics.find({"slug": slug})
|
||||||
if not topic:
|
if not topic:
|
||||||
return "no"
|
return redirect(url_for('.all_topics'))
|
||||||
|
|
||||||
topic.delete()
|
topic.delete()
|
||||||
|
|
||||||
|
@ -269,14 +269,17 @@ def settings_form(username):
|
|||||||
def set_avatar(username):
|
def set_avatar(username):
|
||||||
user = get_active_user()
|
user = get_active_user()
|
||||||
if user.is_guest():
|
if user.is_guest():
|
||||||
return 'no'
|
flash('You must be logged in to perform this action.', InfoboxKind.ERROR)
|
||||||
|
return redirect(url_for('.settings', user.username))
|
||||||
if 'avatar' not in request.files:
|
if 'avatar' not in request.files:
|
||||||
return 'no!...'
|
flash('Avatar missing.', InfoboxKind.ERROR)
|
||||||
|
return redirect(url_for('.settings', user.username))
|
||||||
|
|
||||||
file = request.files['avatar']
|
file = request.files['avatar']
|
||||||
|
|
||||||
if file.filename == '':
|
if file.filename == '':
|
||||||
return 'no..?'
|
flash('Avatar missing.', InfoboxKind.ERROR)
|
||||||
|
return redirect(url_for('.settings', user.username))
|
||||||
|
|
||||||
file_bytes = file.read()
|
file_bytes = file.read()
|
||||||
|
|
||||||
@ -300,7 +303,8 @@ def set_avatar(username):
|
|||||||
old_avatar.delete()
|
old_avatar.delete()
|
||||||
return redirect(url_for('.settings', username=user.username))
|
return redirect(url_for('.settings', username=user.username))
|
||||||
else:
|
else:
|
||||||
return 'uhhhh no'
|
flash('Something went wrong. Please try again later.', InfoboxKind.WARN)
|
||||||
|
return redirect(url_for('.settings', user.username))
|
||||||
|
|
||||||
|
|
||||||
@bp.post('/<username>/clear_avatar')
|
@bp.post('/<username>/clear_avatar')
|
||||||
@ -308,7 +312,7 @@ def set_avatar(username):
|
|||||||
def clear_avatar(username):
|
def clear_avatar(username):
|
||||||
user = get_active_user()
|
user = get_active_user()
|
||||||
if user.is_default_avatar():
|
if user.is_default_avatar():
|
||||||
return 'no'
|
return redirect(url_for('.settings', user.username))
|
||||||
|
|
||||||
old_avatar = Avatars.find({'id': user.avatar_id})
|
old_avatar = Avatars.find({'id': user.avatar_id})
|
||||||
user.update({'avatar_id': 1})
|
user.update({'avatar_id': 1})
|
||||||
@ -336,9 +340,9 @@ def log_out():
|
|||||||
def confirm_user(user_id):
|
def confirm_user(user_id):
|
||||||
target_user = Users.find({"id": user_id})
|
target_user = Users.find({"id": user_id})
|
||||||
if not target_user:
|
if not target_user:
|
||||||
return "no"
|
return redirect(url_for('.all_topics'))
|
||||||
if int(target_user.permission) > PermissionLevel.GUEST.value:
|
if int(target_user.permission) > PermissionLevel.GUEST.value:
|
||||||
return "no"
|
return redirect(url_for('.page', username=target_user.username))
|
||||||
|
|
||||||
target_user.update({
|
target_user.update({
|
||||||
"permission": PermissionLevel.USER.value,
|
"permission": PermissionLevel.USER.value,
|
||||||
@ -353,9 +357,9 @@ def confirm_user(user_id):
|
|||||||
def mod_user(user_id):
|
def mod_user(user_id):
|
||||||
target_user = Users.find({"id": user_id})
|
target_user = Users.find({"id": user_id})
|
||||||
if not target_user:
|
if not target_user:
|
||||||
return "no"
|
return redirect(url_for('.all_topics'))
|
||||||
if target_user.is_mod():
|
if target_user.is_mod():
|
||||||
return "no"
|
return redirect(url_for('.page', username=target_user.username))
|
||||||
|
|
||||||
target_user.update({
|
target_user.update({
|
||||||
"permission": PermissionLevel.MODERATOR.value,
|
"permission": PermissionLevel.MODERATOR.value,
|
||||||
@ -369,9 +373,9 @@ def mod_user(user_id):
|
|||||||
def demod_user(user_id):
|
def demod_user(user_id):
|
||||||
target_user = Users.find({"id": user_id})
|
target_user = Users.find({"id": user_id})
|
||||||
if not target_user:
|
if not target_user:
|
||||||
return "no"
|
return redirect(url_for('.all_topics'))
|
||||||
if not target_user.is_mod():
|
if not target_user.is_mod():
|
||||||
return "no"
|
return redirect(url_for('.page', username=target_user.username))
|
||||||
|
|
||||||
target_user.update({
|
target_user.update({
|
||||||
"permission": PermissionLevel.USER.value,
|
"permission": PermissionLevel.USER.value,
|
||||||
@ -385,9 +389,9 @@ def demod_user(user_id):
|
|||||||
def guest_user(user_id):
|
def guest_user(user_id):
|
||||||
target_user = Users.find({"id": user_id})
|
target_user = Users.find({"id": user_id})
|
||||||
if not target_user:
|
if not target_user:
|
||||||
return "no"
|
return redirect(url_for('.all_topics'))
|
||||||
if target_user.is_mod():
|
if target_user.is_mod():
|
||||||
return "no"
|
return redirect(url_for('.page', username=target_user.username))
|
||||||
|
|
||||||
target_user.update({
|
target_user.update({
|
||||||
"permission": PermissionLevel.GUEST.value,
|
"permission": PermissionLevel.GUEST.value,
|
||||||
|
Loading…
Reference in New Issue
Block a user