From d74dd6c5f3a0bcf68175817112c4e99e761aaafa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Wed, 29 Apr 2026 21:42:22 +0300 Subject: [PATCH] add edit thread routes --- app/routes/threads.py | 26 ++++++++++++++++++-------- app/templates/threads/edit.html | 11 +++++++++++ app/templates/threads/thread.html | 4 ++-- 3 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 app/templates/threads/edit.html diff --git a/app/routes/threads.py b/app/routes/threads.py index 1c9a330..255d4b5 100644 --- a/app/routes/threads.py +++ b/app/routes/threads.py @@ -90,13 +90,26 @@ def reply(thread_id): @login_required @ownership_or_mod_required def edit(thread_id): - return 'stub' + thread = Threads.find({'id': thread_id}) + if not thread: + abort(404) + return render_template('threads/edit.html', thread=thread) @bp.post('//edit/') @login_required @ownership_or_mod_required def edit_post(thread_id): - return 'stub' + thread = Threads.find({'id': thread_id}) + if not thread: + abort(404) + new_title = request.form.get('title', '').strip() + if not new_title: + abort(400) + + if new_title != thread.title: + thread.update({'title': new_title}) + + return redirect(url_for('.thread_by_id', thread_id=thread_id)) @bp.post('//subscribe/') @login_required @@ -168,14 +181,11 @@ def new_post(): user = get_active_user() if not user.can_post_to_thread_or_topic(topic): - abort(404) + abort(403) - title = request.form.get('title') + title = request.form.get('title', '').strip() if not title: - abort(404) - - if not title.strip(): - abort(404) + abort(400) title = title.strip() diff --git a/app/templates/threads/edit.html b/app/templates/threads/edit.html new file mode 100644 index 0000000..b337846 --- /dev/null +++ b/app/templates/threads/edit.html @@ -0,0 +1,11 @@ +{%- from 'common/macros.html' import subheader, babycode_editor_component -%} +{%- extends 'base.html' -%} +{%- block title -%}editing thread "{{thread.title}}"{%- endblock -%} +{%- block content -%} +{{subheader('Rename thread "%s"' % thread.title, 'You can change the thread title here. To edit the OP of this thread, press the Edit button on the post instead.')}} +
+ + + +
+{%- endblock -%} diff --git a/app/templates/threads/thread.html b/app/templates/threads/thread.html index 63c9b44..abd9144 100644 --- a/app/templates/threads/thread.html +++ b/app/templates/threads/thread.html @@ -22,7 +22,7 @@ Actions {%- if is_logged_in() -%} {%- if thread.user_id == get_active_user().id -%} - Edit + Rename {%- endif -%}
@@ -37,7 +37,7 @@
Moderation actions {%- if thread.user_id != get_active_user().id -%} - Edit + Rename {%- endif -%}