forum: allow users to move topics to wherever they can write
This commit is contained in:
parent
be644a6e18
commit
3551103c88
|
@ -1,5 +1,5 @@
|
|||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, SubmitField, TextAreaField, MultipleFileField
|
||||
from wtforms import StringField, SubmitField, TextAreaField, MultipleFileField, SelectField
|
||||
from wtforms.validators import InputRequired, Length
|
||||
import app.utils.validators as vd
|
||||
from app.utils.antibot_field import AntibotField
|
||||
|
@ -66,4 +66,9 @@ class TopicEditForm(CommentEditForm):
|
|||
'Nom du sujet',
|
||||
validators=[InputRequired(), Length(min=3, max=128)])
|
||||
|
||||
# List of forums is generated at runtime
|
||||
forum = SelectField(
|
||||
'Forum',
|
||||
validators=[InputRequired()])
|
||||
|
||||
submit = SubmitField('Modifier le sujet')
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
from app import app, db
|
||||
from app.models.user import Member
|
||||
from app.models.post import Post
|
||||
from app.models.comment import Comment
|
||||
from app.models.attachment import Attachment
|
||||
from app.models.topic import Topic
|
||||
from app.models.comment import Comment
|
||||
from app.models.forum import Forum
|
||||
from app.models.post import Post
|
||||
from app.models.program import Program
|
||||
from app.models.topic import Topic
|
||||
from app.models.user import Member
|
||||
from app.utils.render import render
|
||||
from app.utils.check_csrf import check_csrf
|
||||
from app.forms.forum import CommentEditForm, AnonymousCommentEditForm, TopicEditForm
|
||||
|
@ -43,6 +44,11 @@ def edit_post(postid):
|
|||
{ f'a{a.id}': a for a in comment.attachments })
|
||||
form = TheForm()
|
||||
|
||||
if isinstance(p, Topic):
|
||||
forums = sorted(Forum.query.all(), key=lambda f: f.url)
|
||||
forums = [f for f in forums if current_user.can_post_in_forum(f)]
|
||||
form.forum.choices = [(f.url, f"{f.url}: {f.name}") for f in forums]
|
||||
|
||||
if form.validate_on_submit():
|
||||
comment.text = form.message.data
|
||||
|
||||
|
@ -63,7 +69,10 @@ def edit_post(postid):
|
|||
|
||||
if isinstance(p, Topic):
|
||||
p.title = form.title.data
|
||||
db.session.add(p)
|
||||
f = Forum.query.filter_by(url=form.forum.data).first_or_404()
|
||||
if current_user.can_post_in_forum(f):
|
||||
p.forum = f
|
||||
db.session.merge(p)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
@ -79,6 +88,7 @@ def edit_post(postid):
|
|||
elif isinstance(p, Topic):
|
||||
form.message.data = p.thread.top_comment.text
|
||||
form.title.data = p.title
|
||||
form.forum.data = p.forum.url
|
||||
return render('forum/edit_topic.html', t=p, form=form)
|
||||
|
||||
@app.route('/post/supprimer/<int:postid>', methods=['GET','POST'])
|
||||
|
|
|
@ -30,6 +30,14 @@
|
|||
<form action="" method="post" enctype="multipart/form-data">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
<div>
|
||||
{{ form.forum.label }}
|
||||
{{ form.forum }}
|
||||
{% for error in form.forum.errors %}
|
||||
<span class="msgerror">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{ form.title.label }}
|
||||
{{ form.title }}
|
||||
|
|
Loading…
Reference in New Issue