feat(forum): ajout du post invité sur les topics (#36)
- Encore une fois, penser à faire ces ACL… (#40)
This commit is contained in:
parent
e6c1545031
commit
34bc74b8e5
|
@ -4,11 +4,12 @@ from flask import request, redirect, url_for, abort, flash
|
|||
from app import app, db
|
||||
from config import V5Config
|
||||
from app.utils.render import render
|
||||
from app.forms.forum import TopicCreationForm
|
||||
from app.forms.forum import TopicCreationForm, AnonymousTopicCreationForm
|
||||
from app.models.forum import Forum
|
||||
from app.models.topic import Topic
|
||||
from app.models.thread import Thread
|
||||
from app.models.comment import Comment
|
||||
from app.models.users import Guest
|
||||
|
||||
|
||||
@app.route('/forum/')
|
||||
|
@ -17,7 +18,10 @@ def forum_index():
|
|||
|
||||
@app.route('/forum/<forum:f>/', methods=['GET', 'POST'])
|
||||
def forum_page(f):
|
||||
form = TopicCreationForm()
|
||||
if current_user.is_authenticated:
|
||||
form = TopicCreationForm()
|
||||
else:
|
||||
form = AnonymousTopicCreationForm()
|
||||
|
||||
# TODO: do not hardcode name of news forums
|
||||
if form.validate_on_submit() and (
|
||||
|
@ -27,28 +31,37 @@ def forum_page(f):
|
|||
or ("/actus" in f.url and current_user.is_authenticated
|
||||
and current_user.priv('write-news'))
|
||||
# Forum is not news and is a leaf:
|
||||
or ("/actus" not in f.url and not f.sub_forums)):
|
||||
or ("/actus" not in f.url and not f.sub_forums)) and (
|
||||
V5Config.ENABLE_GUEST_POST or current_user.is_authenticated):
|
||||
|
||||
print("User can post topic")
|
||||
|
||||
# First create the thread, then the comment, then the topic
|
||||
th = Thread()
|
||||
db.session.add(th)
|
||||
db.session.commit()
|
||||
|
||||
c = Comment(current_user, form.message.data, th)
|
||||
if current_user.is_authenticated:
|
||||
author = current_user
|
||||
else:
|
||||
author = Guest(form.pseudo.data)
|
||||
db.session.add(author)
|
||||
|
||||
c = Comment(author, form.message.data, th)
|
||||
db.session.add(c)
|
||||
db.session.commit()
|
||||
|
||||
th.set_top_comment(c)
|
||||
db.session.merge(th)
|
||||
|
||||
t = Topic(f, current_user, form.title.data, th)
|
||||
t = Topic(f, author, form.title.data, th)
|
||||
db.session.add(t)
|
||||
db.session.commit()
|
||||
|
||||
# Update member's xp and trophies
|
||||
current_user.add_xp(V5Config.XP_POINTS['topic'])
|
||||
current_user.update_trophies('new-post')
|
||||
|
||||
if current_user.is_authenticated:
|
||||
current_user.add_xp(V5Config.XP_POINTS['topic'])
|
||||
current_user.update_trophies('new-post')
|
||||
|
||||
flash('Le sujet a bien été créé', 'ok')
|
||||
return redirect(url_for('forum_topic', f=f, page=(t,1)))
|
||||
|
|
|
@ -43,11 +43,21 @@
|
|||
|
||||
{% if (current_user.is_authenticated and current_user.priv('write-anywhere'))
|
||||
or ("/actus" in f.url and current_user.is_authenticated and current_user.priv('write-news'))
|
||||
or ("/actus" not in f.url and not f.sub_forums) %}
|
||||
or ("/actus" not in f.url and not f.sub_forums)
|
||||
and (current_user.is_authenticated or V5Config.ENABLE_GUEST_POST) %}
|
||||
<div class=form>
|
||||
<h2>Créer un nouveau sujet</h2>
|
||||
<form action="" method="post" enctype="multipart/form-data">
|
||||
{{ form.hidden_tag() }}
|
||||
{% if form.pseudo %}
|
||||
<div>
|
||||
{{ form.pseudo.label }}
|
||||
{{ form.pseudo() }}
|
||||
{% for error in form.pseudo.errors %}
|
||||
<span class="msgerror">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div>
|
||||
{{ form.title.label }}
|
||||
|
|
|
@ -11,7 +11,11 @@
|
|||
<section>
|
||||
<h1>{{ t.title }}</h1>
|
||||
<table class="thread"><tr>
|
||||
<td class="member">{{ widget_member.profile(t.author ) }}</td>
|
||||
{% if t.author.type == "member" %}
|
||||
<td class="member">{{ widget_member.profile(t.author ) }}</td>
|
||||
{% else %}
|
||||
<td class="guest"><em>Invité</em>{{ t.author.name }}</td>
|
||||
{% endif %}
|
||||
<td>{{ t.thread.top_comment.text }}</td>
|
||||
</tr></table>
|
||||
|
||||
|
|
Loading…
Reference in New Issue