Compare commits

...

2 Commits

Author SHA1 Message Date
Darks 98878bda7d
Meilleur gestion des avatars (#42) 2019-12-22 14:58:19 +01:00
Darks 1e618fafd1
Ajout des permaliens sur les commentaires de topic 2019-12-17 13:16:06 +01:00
4 changed files with 69 additions and 9 deletions

View File

@ -1,6 +1,7 @@
from datetime import date
from flask import flash
from flask_login import UserMixin
from sqlalchemy import func as SQLfunc
from os.path import isfile
from PIL import Image
from app import app, db
@ -77,10 +78,10 @@ class Member(User):
xp = db.Column(db.Integer)
register_date = db.Column(db.Date, default=date.today)
# Avatars # TODO: rendre ça un peu plus propre
avatar_id = db.Column(db.Integer, default=0)
@property
def avatar(self):
return str(self.id) + '.png'
return f'{self.id}_{self.avatar_id}.png'
@property
def level(self):
@ -200,6 +201,11 @@ class Member(User):
size = 128, 128
im = Image.open(avatar)
im.thumbnail(size, Image.ANTIALIAS)
# TODO: verify concurrency behavior
current_id = db.session.query(SQLfunc.max(Member.avatar_id)).first()[0]
self.avatar_id = current_id + 1
db.session.merge(self)
db.session.commit()
im.save(V5Config.AVATARS_FOLDER + self.avatar, 'PNG')
def get_public_data(self):

View File

@ -0,0 +1,21 @@
{% extends "base/base.html" %}
{% import "widgets/editor.html" as widget_editor %}
{% import "widgets/member.html" as widget_member %}
{% import "widgets/pagination.html" as widget_pagination with context %}
{% block title %}
<a href='/forum'>Forum de Planète Casio</a> » <a href="{{ url_for('forum_page', f=t.forum) }}">{{ t.forum.name }}</a> » <h1>{{ t.title }}</h1>
{% endblock %}
{% block content %}
<section>
<h1>Édition du topic {{ t.title }}</h1>
<div class=form>
<h3>Commenter le sujet</h3>
<form action="" method="post" enctype="multipart/form-data">
Un formulaire
</form>
</div>
</section>
{% endblock %}

View File

@ -19,16 +19,20 @@
<table class="thread">
{% for c in comments.items %}
<tr>
<tr id="{{ c.id }}">
{% if c != t.thread.top_comment %}
<td class="member">{{ widget_member.profile(c.author ) }}</td>
<td>
{% if c.date_created != c.date_modified %}
Le {{ c.date_created|date }} (Modifié le {{ c.date_modified|date }})
{% elif c.date_created == c.date_modified %}
Le {{ c.date_created|date }}
<div>{% if c.date_created != c.date_modified %}
Posté le {{ c.date_created|date }} (Modifié le {{ c.date_modified|date }})
{% else %}
Posté le {{ c.date_created|date }}
{% endif %}
<hr>
| <a href="{{ url_for('forum_topic', f=t.forum, t=t, page=comments.page, _anchor=c.id) }}">#</a>
| <a href="#">Modifier</a>
| <a href="#">Supprimer</a>
</div>
<!--<hr>-->
<p>{{ c.text }}</p>
{% elif loop.index0 != 0 %}
<div>Ce message est le top comment</div>
@ -39,7 +43,7 @@
</table>
{{ widget_pagination.paginate(comments, 'forum_topic', {'f': t.forum, 't':t}) }}
<div class=form>
<h3>Commenter le sujet</h3>
<form action="" method="post" enctype="multipart/form-data">

View File

@ -0,0 +1,29 @@
"""Ajout d'un ID d'avatar (#42)
Revision ID: c40b1f0ed821
Revises: c665488fc26e
Create Date: 2019-12-22 14:46:40.598673
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'c40b1f0ed821'
down_revision = 'c665488fc26e'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('member', sa.Column('avatar_id', sa.Integer(),
nullable=False, server_default='0'))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('member', 'avatar_id')
# ### end Alembic commands ###