From c4bfef476560678b9fcf2ac3403ff6d5bcc3b81c Mon Sep 17 00:00:00 2001 From: Lephe Date: Sun, 19 Jul 2020 22:27:00 +0200 Subject: [PATCH] trophies: add descriptions DATABASE UPDATE: run [flask db upgrade], then use the [create-trophies] command of the master script to recreate trophies. --- app/data/trophies.yaml | 38 ++++++++++++++++++- app/models/trophies.py | 8 +++- app/models/users.py | 2 +- app/templates/account/user.html | 2 +- master.py | 6 ++- ...9d4c2a5d1_add_a_description_to_trophies.py | 30 +++++++++++++++ 6 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 migrations/versions/b659d4c2a5d1_add_a_description_to_trophies.py diff --git a/app/data/trophies.yaml b/app/data/trophies.yaml index 6097e21..9723454 100644 --- a/app/data/trophies.yaml +++ b/app/data/trophies.yaml @@ -1,120 +1,154 @@ # This is a list of trophies. For each trophies, the following keys may be set: -# name Trophy name as displayed on the site. -# is_title If True, the trophy can be worn as a title next to the avatar. +# 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. # Manually awarded - name: Membre de CreativeCalc is_title: True + description: Membre de l'association qui gère Planète Casio ! - name: Membre d'honneur is_title: True + description: Gloire, honneur et déférence sont dûs. - name: Grand Manitou is_title: True + description: Le seul. L'unique. Le GRAND MANITOU. - name: Gourou is_title: True + description: Possède des trophées obscurs. - name: Grand Maître des traits d'esprit is_title: True + description: Inégalé pour l'heure. # Number of posts of any kind - name: Premiers mots is_title: False + description: Écrire 20 messages. - name: Beau parleur is_title: False + description: Écrire 500 messages. - name: Plume infaillible is_title: False + description: Écrire 1500 messages. - name: Romancier émérite is_title: True + description: Écrire 5000 messages ! # Number of posted tutorials - name: Pédagogue is_title: False + description: Élaborer 5 tutoriels. - name: Encyclopédie vivante is_title: False + description: Élaborer 10 tutoriels. - name: Guerrier du savoir is_title: True + description: Élaborer 25 tutoriels ! # Account age (awarded on login only) - name: Initié is_title: False + description: Être membre pendant 1 mois. - name: Aficionado is_title: False + description: Être membre pendant 1 an. - name: Veni, vidi, casii is_title: False + description: Être membre pendant 2 ans. - name: Papy Casio is_title: True + description: Être membre pendant 5 ans. - name: Vétéran mythique is_title: True + description: Être membre pendant 10 ans ! # Number of "good" programs - name: Programmeur du dimanche is_title: False + description: Publier 5 prorammes. - name: Codeur invétéré is_title: False + description: Publier 10 programmes. - name: Je code donc je suis is_title: True + description: Publier 20 programmes ! # Number of posted tests - name: Testeur is_title: False + description: Partager 5 tests. - name: Grand joueur is_title: False + description: Partager 25 tests. - name: Hard tester is_title: True + description: Partager 100 tests ! # Number of event participations - name: Participant is_title: False + description: Participer à un événement du site. - name: Concourant encore is_title: False + description: Participer à 5 événements du site. - name: Concurrent de l'extrême is_title: True + description: Participer à 15 événements du site ! # Number of posted art - name: Dessinateur en herbe is_title: False + description: Publier 5 assets graphiques. - name: Open pixel is_title: False + description: Publier 30 assets graphiques. - name: Roi du pixel is_title: True + description: Publier 100 assets graphiques ! # Miscellaneous automatically awarded - name: Actif is_title: False + description: Être présent 30 jours de suite. - name: Artiste is_title: False + description: Modifier son avatar. - name: Maître du code is_title: True + description: Être décoré 5 fois du label de qualité ! - name: Bourreau des cœurs is_title: True + description: Foudroyer les cœurs à 5 reprises ! diff --git a/app/models/trophies.py b/app/models/trophies.py index a884e6a..6f2a169 100644 --- a/app/models/trophies.py +++ b/app/models/trophies.py @@ -15,12 +15,15 @@ class Trophy(db.Model): # Trophy name (in French) name = db.Column(db.Unicode(64), index=True) + # Description + description = db.Column(db.UnicodeText, index=True) owners = db.relationship('Member', secondary=lambda: TrophyMember, back_populates='trophies') - def __init__(self, name): + def __init__(self, name, description): self.name = name + self.description = description def __repr__(self): return f'' @@ -33,8 +36,9 @@ class Title(Trophy): id = db.Column(db.Integer, db.ForeignKey('trophy.id'), primary_key=True) css = db.Column(db.UnicodeText) - def __init__(self, name, css=""): + def __init__(self, name, description, css=""): self.name = name + self.description = description self.css = css def __repr__(self): diff --git a/app/models/users.py b/app/models/users.py index e69a830..38af1e5 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -340,7 +340,7 @@ class Member(User): if context in ["new-post", "new-program", "new-tutorial", "new-test", None]: - # Cannot use ORM tools because it adds circular import issues + # FIXME: Use ORM tools with careful, non-circular imports post_count = db.session.execute(f"""SELECT COUNT(*) FROM post INNER JOIN member ON member.id = post.author_id WHERE member.id = {self.id}""").first()[0] diff --git a/app/templates/account/user.html b/app/templates/account/user.html index d9a0d1c..96ab15b 100644 --- a/app/templates/account/user.html +++ b/app/templates/account/user.html @@ -55,7 +55,7 @@
{{ t.name }} - Avoir posté 50 messages sur le forum + {{ t.description }}
{% endfor %} diff --git a/master.py b/master.py index 98db175..22bddc8 100755 --- a/master.py +++ b/master.py @@ -171,10 +171,12 @@ def create_trophies(): tr = yaml.safe_load(fp.read()) for t in tr: + description = t.get("description", "") + if t["is_title"]: - trophy = Title(t["name"], t.get("css", "")) + trophy = Title(t["name"], description, t.get("css", "")) else: - trophy = Trophy(t["name"]) + trophy = Trophy(t["name"], description) db.session.add(trophy) db.session.commit() diff --git a/migrations/versions/b659d4c2a5d1_add_a_description_to_trophies.py b/migrations/versions/b659d4c2a5d1_add_a_description_to_trophies.py new file mode 100644 index 0000000..710893b --- /dev/null +++ b/migrations/versions/b659d4c2a5d1_add_a_description_to_trophies.py @@ -0,0 +1,30 @@ +"""add a description to trophies + +Revision ID: b659d4c2a5d1 +Revises: d1b465f88d3b +Create Date: 2020-07-19 22:06:55.789405 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'b659d4c2a5d1' +down_revision = 'd1b465f88d3b' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('trophy', sa.Column('description', sa.UnicodeText(), nullable=True)) + op.create_index(op.f('ix_trophy_description'), 'trophy', ['description'], unique=False) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_trophy_description'), table_name='trophy') + op.drop_column('trophy', 'description') + # ### end Alembic commands ###