From a3c07db3a063444d531e1b54f47766b81756637d Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 6 Mar 2024 05:42:31 +0200 Subject: [PATCH] code in 10 and 100 badges --- files/classes/art_submissions.py | 12 +++++++++++- files/routes/art_submissions.py | 9 ++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/files/classes/art_submissions.py b/files/classes/art_submissions.py index 8e67f4e54..1153b3cd1 100644 --- a/files/classes/art_submissions.py +++ b/files/classes/art_submissions.py @@ -26,9 +26,19 @@ class ArtSubmission(Base): @property @lazy - def badge_id(self): + def badge_id_1(self): return 99 if self.kind == "sidebar" else 101 + @property + @lazy + def badge_id_10(self): + return 331 if self.kind == "sidebar" else 333 + + @property + @lazy + def badge_id_100(self): + return 332 if self.kind == "sidebar" else 334 + @property @lazy def resize(self): diff --git a/files/routes/art_submissions.py b/files/routes/art_submissions.py index 9b172d202..ebd45f379 100644 --- a/files/routes/art_submissions.py +++ b/files/routes/art_submissions.py @@ -107,7 +107,6 @@ def approve_art(v, id): author = get_user(author) entry.author_id = author.id g.db.add(entry) - badge_grant(author, entry.badge_id) entry_url = f"{SITE_FULL_IMAGES}/i/{SITE_NAME}/{entry.location_kind}/{entry.id}.webp" @@ -142,6 +141,14 @@ def approve_art(v, id): entry.approved = True + all_by_author = g.db.query(ArtSubmission).filter_by(kind=entry.kind, author_id=author.id, approved=True).count() + if all_by_author >= 99: + badge_grant(badge_id=entry.badge_id_100, user=author) + elif all_by_author >= 9: + badge_grant(badge_id=entry.badge_id_10, user=author) + else: + badge_grant(badge_id=entry.badge_id_1, user=author) + return {"message": f"{entry.msg_kind} approved!"} @app.post("/remove/art/")