Fix UserRank not being translatable

This commit is contained in:
rubenwardy 2024-06-08 12:27:05 +01:00
parent 7cf1f40ff6
commit e335797629
9 changed files with 35 additions and 13 deletions

@ -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()

@ -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:

@ -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):

@ -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):

@ -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):

@ -10,7 +10,7 @@
<div class="row {% if entry.severity == entry.severity.NORMAL %}text-muted{% endif %}">
<div class="col-sm-auto text-center" style="width: 50px;"
title="{{ _('Severity: %(sev)s.', sev=entry.severity.get_title()) }}">
title="{{ _('Severity: %(sev)s.', sev=entry.severity.title) }}">
{% if entry.severity == entry.severity.MODERATION %}
<i class="fas fa-exclamation-triangle" style="color: yellow;"></i>
{% elif entry.severity == entry.severity.EDITOR %}

@ -29,7 +29,7 @@
{% endif %}
{% if r.author.rank == r.author.rank.BOT %}
<span class="badge bg-dark">
{{ r.author.rank.get_title() }}
{{ r.author.rank.title }}
</span>
{% endif %}

@ -46,7 +46,7 @@
<i class="fas fa-user me-2"></i>
{% endif %}
{{ user.rank.get_title() }}
{{ user.rank.title }}
</div>
<span class="col-sm {{ user.rank }}">

@ -66,7 +66,7 @@
<span class="btn">
<i class="fas fa-user"></i>
<span class="count">
{{ user.rank.get_title() }}
{{ user.rank.title }}
</span>
</span>