add edit thread routes
This commit is contained in:
@@ -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('/<int:thread_id>/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('/<int:thread_id>/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()
|
||||
|
||||
|
||||
11
app/templates/threads/edit.html
Normal file
11
app/templates/threads/edit.html
Normal file
@@ -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.')}}
|
||||
<form class="plank primary-bg full-width" method="POST">
|
||||
<label for="title">New title</label>
|
||||
<input type="text" id="title" name="title" required value="{{thread.title}}">
|
||||
<input type="submit" value="Save">
|
||||
</form>
|
||||
{%- endblock -%}
|
||||
@@ -22,7 +22,7 @@
|
||||
<legend>Actions</legend>
|
||||
{%- if is_logged_in() -%}
|
||||
{%- if thread.user_id == get_active_user().id -%}
|
||||
<a class="linkbutton" href="{{url_for('threads.edit', thread_id=thread.id)}}">Edit</a>
|
||||
<a class="linkbutton" href="{{url_for('threads.edit', thread_id=thread.id)}}">Rename</a>
|
||||
{%- endif -%}
|
||||
<form action="{{url_for('threads.subscribe' if not get_active_user().is_subscribed(thread.id) else 'threads.unsubscribe', thread_id=thread.id)}}" method="POST">
|
||||
<input type="hidden" name="last_post_timestamp" value="{{last_post.created_at}}">
|
||||
@@ -37,7 +37,7 @@
|
||||
<fieldset class="plank even no-shadow minimal thread-actions">
|
||||
<legend>Moderation actions</legend>
|
||||
{%- if thread.user_id != get_active_user().id -%}
|
||||
<a class="linkbutton warn" href="{{url_for('threads.edit', thread_id=thread.id)}}">Edit</a>
|
||||
<a class="linkbutton warn" href="{{url_for('threads.edit', thread_id=thread.id)}}">Rename</a>
|
||||
{%- endif -%}
|
||||
<form method="POST">
|
||||
<input type="hidden" name="lock" value="{{(not thread.locked()) | int}}">
|
||||
|
||||
Reference in New Issue
Block a user