', methods=['GET', 'POST'])
+def forum_topic(f, t):
+ form = CommentForm()
+
+ if form.validate_on_submit():
+ c = Comment(current_user, form.message.data, t.thread)
+ db.session.add(c)
+ db.session.commit()
+ flash('Message envoyé', 'ok')
+ # Redirect to empty the form
+ return redirect(url_for('forum_topic', f=f, t=t))
+
+ # Update views
+ t.views += 1
+ db.session.merge(t)
+ db.session.commit()
+
+ return render('/forum/topic.html', t=t, form=form)
diff --git a/app/static/css/table.css b/app/static/css/table.css
index c70652c..4445169 100644
--- a/app/static/css/table.css
+++ b/app/static/css/table.css
@@ -42,13 +42,22 @@ table.forumlist tr:nth-child(4n+3) {
background: rgba(0, 0, 0, .05);
}
+
/* Topic table */
table.topiclist {
- width: 90%;
+ width: 100%;
margin: auto;
}
table.topiclist tr > *:nth-child(n+2) {
/* This matches all children except the first column */
text-align: center;
}
+
+
+table.forumlist th > td:last-child,
+table.forumlist tr > td:last-child,
+table.topiclist th > td:last-child,
+table.topiclist tr > td:last-child {
+ width: 20%; text-align: center;
+}
diff --git a/app/templates/forum/forum.html b/app/templates/forum/forum.html
index 974e89a..45efe52 100644
--- a/app/templates/forum/forum.html
+++ b/app/templates/forum/forum.html
@@ -10,25 +10,40 @@
{{ f.descr }}
{% if f.topics %}
+ Sujets
Sujet | Auteur | Date de création |
Commentaires | Vues |
{% for t in f.topics %}
- {{ t.title }} |
- {{ t.author.name }} |
- {{ t.date_created | date }} |
- {{ t.comments | length }} |
- {{ t.views }} |
+ {{ t.title }} |
+ {{ t.author.name }} |
+ {{ t.date_created | date }} |
+ {{ t.thread.comments | length }} |
+ {{ t.views }} |
{% endfor %}
- {% else %}
+ {% elif len(f.sub_forums) == 0 %}
Il n'y a aucun topic sur ce forum ! Animons-le vite !
{% endif %}
+
+ {% if len(f.sub_forums) > 0 %}
+ Forums
+
+ {{ f.name }} | Nombre de sujets |
+
+ {% for sf in f.sub_forums %}
+ {{ sf.name }} |
+ {{ sf.topics | length }} |
+ {{ sf.descr }} | |
+ {% endfor %}
+
+
+ {% endif %}
+
+ {% if len(f.sub_forums) == 0 or (current_user.is_authenticated and current_user.priv('access-admin-board')) %}
-
Créer un nouveau sujet
-
- {{ widget_editor.editor(form.message) }}
+ {{ widget_editor.text_editor(form.message) }}
{{ form.submit(class_='bg-green') }}
+ {% endif %}
{% endblock %}
diff --git a/app/templates/forum/topic.html b/app/templates/forum/topic.html
new file mode 100644
index 0000000..1afe3b4
--- /dev/null
+++ b/app/templates/forum/topic.html
@@ -0,0 +1,33 @@
+{% extends "base/base.html" %}
+{% import "widgets/editor.html" as widget_editor %}
+
+{% block title %}
+Forum de Planète Casio » {{ t.forum.name }}
+{% endblock %}
+
+{% block content %}
+
+ {{ t.title }}
+
+ {{ t.thread.top_comment.text }}
+
+ {% for i, c in enumerate(t.thread.comments) %}
+ {% if c != t.thread.top_comment %}
+ {{ c.text }}
+ {% elif i != 0 %}
+ Ce message est le top comment
+ {% endif %}
+ {% endfor %}
+
+
+
+{% endblock %}
diff --git a/app/templates/widgets/editor.html b/app/templates/widgets/editor.html
index 2d4d911..087865a 100644
--- a/app/templates/widgets/editor.html
+++ b/app/templates/widgets/editor.html
@@ -1,9 +1,9 @@
-{% macro editor(form) %}
+{% macro text_editor(field, label=True) %}
- {{ form.hidden_tag() }}
- {{ form.label }}
- {{ form.contents() }}
- {% for error in form.contents.errors %}
+ {{ field.label if label }}
+
Widgets. Lots of widgets :3
+ {{ field() }}
+ {% for error in field.errors %}
{{ error }}
{% endfor %}
diff --git a/app/utils/converters.py b/app/utils/converters.py
index 001d2b4..eb5bf3a 100644
--- a/app/utils/converters.py
+++ b/app/utils/converters.py
@@ -18,6 +18,7 @@ For more information, see the Werkzeug documentation:
from werkzeug.routing import BaseConverter, ValidationError
from app.models.forum import Forum
+from app.models.topic import Topic
import re
import sys
@@ -48,10 +49,10 @@ class TopicSlugConverter(BaseConverter):
if m is None:
raise Exception(f"TopicSlugConverter: conversation failed")
- return int(m[1], 10)
+ return Topic.query.get_or_404(int(m[1], 10))
- def to_url(self, topic_id):
- return str(topic_id)
+ def to_url(self, topic):
+ return str(topic.id)
# Export only the converter classes
__all__ = "ForumConverter TopicSlugConverter".split()