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

This commit is contained in:
Darks 2020-07-23 18:17:20 +02:00
commit 20f7dc268e
Signed by: Darks
GPG Key ID: F61F10FA138E797C
7 changed files with 41 additions and 3 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
__pycache__/
app/__pycache__/
app/static/avatars/
app/static/images/trophies/
## Devlopement files

View File

@ -5,6 +5,7 @@ from flask_login import LoginManager
from flask_mail import Mail
from config import Config
import time
import slugify
app = Flask(__name__)
app.config.from_object(Config)
@ -49,3 +50,8 @@ from app.routes.forum import index, topic
from app.utils import pluralize # To use pluralize into the templates
from app.utils import date
from app.utils import is_title
# Add slugify into the available functions in every template
app.jinja_env.globals.update(
slugify=slugify.slugify
)

BIN
app/data/trophies.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

@ -2,6 +2,7 @@
# name Trophy name as displayed on the site.
# is_title If True, the trophy can be worn as a title next to the avatar.
# description Detailed description to be shown on profile page.
# hidden Not shown unless awarded (for unique titles).
# Manually awarded
-
@ -185,3 +186,8 @@
is_title: True
description: Foudroyer les cœurs à 5 reprises!
hidden: False
-
name: Survivant de la v42
is_title: False
description: A connu la v42 de Planète Casio.
hidden: True

View File

@ -61,7 +61,7 @@
border-radius: 2px;
}
.trophy img {
height: 50px; margin-right: 5px;
height: 48px; margin-right: 8px;
}
.trophy div > * {
display: block;

View File

@ -46,7 +46,7 @@
<div class="trophies">
{% for t in trophies if t in member.trophies or t.hidden == False %}
<div class="trophy {{ '' if t in member.trophies else 'disabled' }}">
<img src="{{ url_for('static', filename='images/fa_124.png') }}">
<img src="{{ url_for('static', filename='images/trophies/'+slugify(t.name))+'.png' }}">
<div>
<em>{{ t.name }}</em>
<span>{{ t.description }}</span>

View File

@ -10,6 +10,8 @@ import os
import sys
import yaml
import readline
import slugify
from PIL import Image
help_msg = """
This is the Planète Casio master shell. Type 'exit' or C-D to leave.
@ -37,7 +39,7 @@ the database.
Type 'add-group <member> #<group-id>' to add a new member to a group.
Type 'create-trophies' to reset trophies and titles.
Type 'create-trophies' to reset trophies and titles and their icons.
Type 'create-forums' to reset the forum tree.
"""
@ -183,6 +185,29 @@ def create_trophies():
print(f"Created {len(tr)} trophies.")
# Create their icons in /app/static/images/trophies
names = [ slugify.slugify(t["name"]) for t in tr ]
src = os.path.join(app.root_path, "data", "trophies.png")
dst = os.path.join(app.root_path, "static", "images", "trophies")
try:
os.mkdir(dst)
except FileExistsError:
pass
img = Image.open(src)
def trophy_iterator(img):
for y in range(img.height // 26):
for x in range(img.width // 26):
icon = img.crop((26*x+1, 26*y+1, 26*x+25, 26*y+25))
# Skip blank squares in the source image
if len(icon.getcolors()) > 1:
yield icon.resize((48,48))
for (name, icon) in zip(names, trophy_iterator(img)):
icon.save(os.path.join(dst, f"{name}.png"))
def create_forums():
# Clean up forums
forums("clear")