From e3357976299f57804a959026e22cdec64d72e6f1 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 8 Jun 2024 12:27:05 +0100 Subject: [PATCH] Fix UserRank not being translatable --- app/blueprints/todo/user.py | 2 +- app/blueprints/users/settings.py | 2 +- app/models/__init__.py | 5 +++-- app/models/packages.py | 5 +++-- app/models/users.py | 26 +++++++++++++++++++++++--- app/templates/macros/audit_log.html | 2 +- app/templates/macros/threads.html | 2 +- app/templates/users/list.html | 2 +- app/templates/users/profile.html | 2 +- 9 files changed, 35 insertions(+), 13 deletions(-) diff --git a/app/blueprints/todo/user.py b/app/blueprints/todo/user.py index 044a4d41..78d02a61 100644 --- a/app/blueprints/todo/user.py +++ b/app/blueprints/todo/user.py @@ -113,7 +113,7 @@ def apply_all_updates(username): PackageRelease.commit_hash == package.update_config.last_commit)).count() > 0: continue - title = package.update_config.get_title() + title = package.update_config.title ref = package.update_config.get_ref() rel = PackageRelease() diff --git a/app/blueprints/users/settings.py b/app/blueprints/users/settings.py index 2ce2fd01..471e4213 100644 --- a/app/blueprints/users/settings.py +++ b/app/blueprints/users/settings.py @@ -374,7 +374,7 @@ def modtools(username): if current_user.rank.at_least(new_rank): if new_rank != user.rank: user.rank = form["rank"].data - msg = "Set rank of {} to {}".format(user.display_name, user.rank.get_title()) + msg = "Set rank of {} to {}".format(user.display_name, user.rank.title) add_audit_log(AuditSeverity.MODERATION, current_user, msg, url_for("users.profile", username=username)) else: diff --git a/app/models/__init__.py b/app/models/__init__.py index 7ea23ecc..44c13838 100644 --- a/app/models/__init__.py +++ b/app/models/__init__.py @@ -71,12 +71,13 @@ class AuditSeverity(enum.Enum): def __str__(self): return self.name - def get_title(self): + @property + def title(self): return self.name.replace("_", " ").title() @classmethod def choices(cls): - return [(choice, choice.get_title()) for choice in cls] + return [(choice, choice.title) for choice in cls] @classmethod def coerce(cls, item): diff --git a/app/models/packages.py b/app/models/packages.py index 0294a209..fbb0c9be 100644 --- a/app/models/packages.py +++ b/app/models/packages.py @@ -1358,14 +1358,15 @@ class PackageUpdateConfig(db.Model): else: return lazy_gettext("New tag %(tag_name)s found on the Git repo.", tag_name=self.last_tag) - def get_title(self): + @property + def title(self): return self.last_tag or self.outdated_at.strftime("%Y-%m-%d") def get_ref(self): return self.last_tag or self.last_commit def get_create_release_url(self): - return self.package.get_url("packages.create_release", title=self.get_title(), ref=self.get_ref()) + return self.package.get_url("packages.create_release", title=self.title, ref=self.get_ref()) class PackageAlias(db.Model): diff --git a/app/models/users.py b/app/models/users.py index 37646283..928234d4 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -39,8 +39,28 @@ class UserRank(enum.Enum): def at_least(self, min): return self.value >= min.value - def get_title(self): - return self.name.replace("_", " ").title() + @property + def title(self): + if self == UserRank.BANNED: + return lazy_gettext("Banned") + elif self == UserRank.NOT_JOINED: + return lazy_gettext("Not Joined") + elif self == UserRank.NEW_MEMBER: + return lazy_gettext("New Member") + elif self == UserRank.MEMBER: + return lazy_gettext("Member") + elif self == UserRank.TRUSTED_MEMBER: + return lazy_gettext("Trusted Member") + elif self == UserRank.APPROVER: + return lazy_gettext("Approver") + elif self == UserRank.EDITOR: + return lazy_gettext("Editor") + elif self == UserRank.BOT: + return lazy_gettext("Bot") + elif self == UserRank.MODERATOR: + return lazy_gettext("Moderator") + elif self == UserRank.ADMIN: + return lazy_gettext("Admin") def to_name(self): return self.name.lower() @@ -50,7 +70,7 @@ class UserRank(enum.Enum): @classmethod def choices(cls): - return [(choice, choice.get_title()) for choice in cls] + return [(choice, choice.title) for choice in cls] @classmethod def coerce(cls, item): diff --git a/app/templates/macros/audit_log.html b/app/templates/macros/audit_log.html index 079cb900..a30afce9 100644 --- a/app/templates/macros/audit_log.html +++ b/app/templates/macros/audit_log.html @@ -10,7 +10,7 @@
+ title="{{ _('Severity: %(sev)s.', sev=entry.severity.title) }}"> {% if entry.severity == entry.severity.MODERATION %} {% elif entry.severity == entry.severity.EDITOR %} diff --git a/app/templates/macros/threads.html b/app/templates/macros/threads.html index 0a17679a..a38cdd66 100644 --- a/app/templates/macros/threads.html +++ b/app/templates/macros/threads.html @@ -29,7 +29,7 @@ {% endif %} {% if r.author.rank == r.author.rank.BOT %} - {{ r.author.rank.get_title() }} + {{ r.author.rank.title }} {% endif %} diff --git a/app/templates/users/list.html b/app/templates/users/list.html index 049634bd..8092a703 100644 --- a/app/templates/users/list.html +++ b/app/templates/users/list.html @@ -46,7 +46,7 @@ {% endif %} - {{ user.rank.get_title() }} + {{ user.rank.title }}
diff --git a/app/templates/users/profile.html b/app/templates/users/profile.html index 48365eda..9ee61f8e 100644 --- a/app/templates/users/profile.html +++ b/app/templates/users/profile.html @@ -66,7 +66,7 @@ - {{ user.rank.get_title() }} + {{ user.rank.title }}