Meilleur gestion des avatars (#42)

pull/47/head
Darks 3 years ago
parent 1e618fafd1
commit 98878bda7d
Signed by: Darks
GPG Key ID: F61F10FA138E797C
  1. 10
      app/models/users.py
  2. 21
      app/templates/forum/edit_topic.html
  3. 29
      migrations/versions/c40b1f0ed821_ajout_d_un_id_d_avatar_42.py

@ -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):

@ -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 %}

@ -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 ###
Loading…
Cancel
Save