From ff21d89c2312aac2c828fc5483c05107c1529bf5 Mon Sep 17 00:00:00 2001 From: Darks Date: Fri, 9 Aug 2019 23:20:53 +0200 Subject: [PATCH] Small modifications --- Pipfile | 2 +- app/models/users.py | 17 ++++++++++------- app/routes/account/account.py | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Pipfile b/Pipfile index 9bee1b5..50b3487 100644 --- a/Pipfile +++ b/Pipfile @@ -7,7 +7,7 @@ name = "pypi" flask = ">=1.0" flask-wtf = ">=0.14" flask-login = ">=0.4" -flask-migrate = ">=2.3 " +flask-migrate = ">=2.3" flask-sqlalchemy = ">=2.3" flask-script = ">=2.0" uwsgi = ">=2.0" diff --git a/app/models/users.py b/app/models/users.py index aa2964c..7ba0248 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -206,22 +206,24 @@ class Member(User, db.Model): def add_trophy(self, t): """ - Add a trophy to the current user. heck whether the request sender has the right - to do this! + Add a trophy to the current user. Check whether the request sender has + the right to do this! """ + if type(t) == int: + t = Trophy.get(t) if type(t) == str: - t = Trophy.query.filter_by(name=name).first() + t = Trophy.query.filter_by(name=t).first() if t not in self.trophies: self.trophies.append(t) db.session.merge(self) db.session.commit() # TODO: implement the notification system - # self.notify(f"Vous venez de débloquer le trophée '{name}'") + # self.notify(f"Vous venez de débloquer le trophée '{t.name}'") def del_trophy(self, t): """ - Add a trophy to the current user. heck whether the request sender has the right - to do this! + Add a trophy to the current user. Check whether the request sender has + the right to do this! """ if type(t) == str: t = Trophy.query.filter_by(name=name).first() @@ -271,7 +273,8 @@ class Member(User, db.Model): if age.days > 365.25 * 5: self.add_trophy("Papy Casio") if context == "on-profile-update" or context is None: - pass + # TODO: add a better condition (this is for test) + self.add_trophy("Artiste") def __repr__(self): return f'' diff --git a/app/routes/account/account.py b/app/routes/account/account.py index 601f5af..e24786d 100644 --- a/app/routes/account/account.py +++ b/app/routes/account/account.py @@ -25,6 +25,7 @@ def edit_account(): ) db.session.merge(current_user) db.session.commit() + current_user.update_trophies("on-profile-update") flash('Modifications effectuées', 'ok') else: flash('Erreur lors de la modification', 'error')