Browse Source

Merge branch 'dev' of gitea.planet-casio.com:devs/PCv5 into dev

preprod
Eragon 2 months ago
parent
commit
27ca00ffce
Signed by: Eragon <sam.vzh@netc.fr> GPG Key ID: 41F8C3FE5948FDAB
9 changed files with 74 additions and 30 deletions
  1. +3
    -7
      app/__init__.py
  2. +29
    -0
      app/processors/menu.py
  3. +9
    -0
      app/processors/utilities.py
  4. +1
    -2
      app/routes/forum/index.py
  5. +5
    -1
      app/routes/forum/topic.py
  6. +1
    -1
      app/static/css/global.css
  7. BIN
      app/static/images/default_avatar.png
  8. +11
    -12
      app/templates/base/navbar/forum.html
  9. +15
    -7
      app/utils/render.py

+ 3
- 7
app/__init__.py View File

@@ -15,7 +15,6 @@ login = LoginManager(app)
login.login_view = 'login'
login.login_message = "Veuillez vous authentifier avant de continuer."


from app.utils.converters import *
app.url_map.converters['topicslug'] = TopicSlugConverter
app.url_map.converters['forum'] = ForumConverter
@@ -26,12 +25,9 @@ def request_time():
g.request_start_time = time.time()
g.request_time = lambda: "%.5fs" % (time.time() - g.request_start_time)

@app.context_processor
def utilities_processor():
return dict(
len=len,
enumerate=enumerate
)

from app.processors.menu import menu_processor
from app.processors.utilities import utilities_processor

from app import models # IDK why this is here, but it works
from app.models.comment import Comment

+ 29
- 0
app/processors/menu.py View File

@@ -0,0 +1,29 @@
from app import app, db
from app.forms.login import LoginForm
from app.forms.search import SearchForm
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 Member

@app.context_processor
def menu_processor():
""" All items used to render main menu. Includes search form """

login_form = LoginForm(prefix="menu_")
search_form = SearchForm()
main_forum = Forum.query.filter_by(parent=None).first()

# Constructing last forum comments [(member, topic)]
raw = db.session.execute( """SELECT member.id, topic.id FROM comment
RIGHT JOIN post ON comment.id = post.id
INNER JOIN topic ON comment.thread_id = topic.thread_id
INNER JOIN member ON post.author_id = member.id
ORDER BY post.date_created DESC
LIMIT 10""")
last_forum_comments = [(Member.query.get(m), Topic.query.get(t))
for m, t in raw]

return dict(login_form=login_form, search_form=search_form,
main_forum=main_forum, last_forum_comments=last_forum_comments)

+ 9
- 0
app/processors/utilities.py View File

@@ -0,0 +1,9 @@
from app import app

@app.context_processor
def utilities_processor():
""" Add some utilities to render context """
return dict(
len=len,
enumerate=enumerate
)

+ 1
- 2
app/routes/forum/index.py View File

@@ -11,8 +11,7 @@ from app import app, db

@app.route('/forum/')
def forum_index():
main_forum = Forum.query.filter_by(parent=None).first()
return render('/forum/index.html', main_forum=main_forum)
return render('/forum/index.html')

@app.route('/forum/<forum:f>/', methods=['GET', 'POST'])
def forum_page(f):

+ 5
- 1
app/routes/forum/topic.py View File

@@ -1,5 +1,5 @@
from flask_login import current_user
from flask import request, redirect, url_for, flash
from flask import request, redirect, url_for, flash, abort

from app.utils.render import render
from app.forms.forum import CommentForm
@@ -12,6 +12,10 @@ from app import app, db

@app.route('/forum/<forum:f>/<topicslug:t>', methods=['GET', 'POST'])
def forum_topic(f, t):
# Quick n' dirty workaround to converters
if f != t.forum:
abort(404)

form = CommentForm()

if form.validate_on_submit():

+ 1
- 1
app/static/css/global.css View File

@@ -16,7 +16,7 @@

body {
margin: 0;
background: #ffffff;
background: #ffffff; color: #000000;
font-family: Twemoji, 'DejaVu Sans', sans-serif;
}


BIN
app/static/images/default_avatar.png View File

Before After
Width: 512  |  Height: 512  |  Size: 19KB

+ 11
- 12
app/templates/base/navbar/forum.html View File

@@ -5,25 +5,24 @@
</svg>
Forum
</h2>
<a href='/forum'>Index du forum</a>
<a href='{{ url_for('forum_index') }}'>Index du forum</a>

<hr>

<a href="/forum/news/">Vie communautaire</a>
<a href="/forum/projects/">Projets de programmation</a>
<a href="/forum/help/">Questions et problèmes</a>
<a href="/forum/discussion/">Discussions</a>
<a href="/forum/">Administration</a>
<a href="/forum/">CreativeCalc</a>
{% for f in main_forum.sub_forums %}
<a href="{{ url_for('forum_page', f=f) }}">{{ f.name }}</a>
{% endfor %}

<hr>

<h3>Derniers commentaires</h3>
<ul>
<li><a href="#">Legolas</a> sur <a href="#">Bugs de la v5</a></li>
<li><a href="#">Dark Storm</a> sur <a href="#">fxSDK support</a></li>
<li><a href="#">Gollum</a> sur <a href="#">Le nom de topic qui fout le bordel car il est trop long…</a></li>
<li><a href="#">Lephenixnoir</a> sur <a href="#">fxSDK support</a></li>
<li><a href="#">Kristaba</a> sur <a href="#">FiXos, le retour</a></li>
{% for m, t in last_forum_comments %}
<li>
<a href="{{ url_for('user', username=m.name) }}">{{ m.name }}</a>
sur
<a href="{{ url_for('forum_topic', f=t.forum, t=t)}}">{{ t.title }}</a>
</li>
{% endfor %}
</ul>
</div>

+ 15
- 7
app/utils/render.py View File

@@ -1,16 +1,16 @@
from flask import render_template
from app.forms.login import LoginForm
from app.forms.search import SearchForm
from app.models.forum import Forum


def render(*args, styles=[], **kwargs):
def render(*args, styles=[], scripts=[], **kwargs):
# TODO: debugguer cette merde : au logout, ça foire
# if current_user.is_authenticated:
# login_form = LoginForm()
# return render_template(*args, **kwargs, login_form=login_form)
# return render_template(*args, **kwargs)

# Pour jouer sur les feuilles de style :
# Pour jouer sur les feuilles de style ou les scripts :
# render('page.html', styles=['-css/form.css', '+css/admin/forms.css'])

styles_ = [
@@ -24,6 +24,10 @@ def render(*args, styles=[], **kwargs):
'css/responsive.css',
'css/table.css'
]
scripts_ = [

]

for s in styles:
print(s[1:])
if s[0] == '-':
@@ -31,7 +35,11 @@ def render(*args, styles=[], **kwargs):
if s[0] == '+':
styles_.append(s[1:])

login_form = LoginForm(prefix="menu_")
search_form = SearchForm()
return render_template(*args, **kwargs,
login_form=login_form, search_form=search_form, styles=styles_)
for s in scripts:
print(s[1:])
if s[0] == '-':
scripts_.remove(s[1:])
if s[0] == '+':
scripts_.append(s[1:])

return render_template(*args, **kwargs, styles=styles_, scripts=scripts_)

Loading…
Cancel
Save