Skip to content

Commit

Permalink
use proper badge descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
catgirlinspace committed Jun 21, 2024
1 parent 81b6b33 commit 7882263
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion groups/templates/groups/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h2 class="font-splatoon1 text-xl">Owner</h2>

{% if group.members.count > 0 %}
<h2 class="font-splatoon1 text-xl">Members</h2>
<div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3">
<div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
{% for member in group.members.all %}
{% include "users/includes/user-link.html" with user=member show_splashtag=True %}
{% endfor %}
Expand Down
8 changes: 6 additions & 2 deletions splatnet_assets/badge_descriptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import re
import typing

from splatnet_assets.models import NameplateBadge, LocalizationString
from splatnet_assets.models import LocalizationString

if typing.TYPE_CHECKING:
from splatnet_assets.models import NameplateBadge

level_regex = re.compile(r"_Lv\d{2}")
group_regex = re.compile(r"\[group=0004.+]")
Expand All @@ -25,7 +29,7 @@ def has_prefix(s, prefixes):
return any(s.startswith(prefix) for prefix in prefixes)


def get_proper_badge_localization(badge: NameplateBadge, locale: str = None) -> str:
def get_proper_badge_localization(badge: "NameplateBadge", locale: str = None) -> str:
localization_string = badge.description.get_string(locale)
if has_prefix(badge.internal_id, bad_badge_prefixes):
# find replacement string and replace
Expand Down
7 changes: 7 additions & 0 deletions splatnet_assets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def url(self):

django_locale_to_splatnet_locale = {
'ja': 'ja-JP',
'es': 'es-ES',
'ru': 'ru-RU',
}


Expand Down Expand Up @@ -149,6 +151,11 @@ class NameplateBadge(models.Model):
image = models.OneToOneField('Image', on_delete=models.PROTECT, related_name='+')
description = models.ForeignKey('LocalizationString', on_delete=models.PROTECT)

@property
def translated_description(self):
from splatnet_assets.badge_descriptions import get_proper_badge_localization
return get_proper_badge_localization(self)


class Stage(models.Model):
internal_id = models.CharField(max_length=100)
Expand Down
4 changes: 2 additions & 2 deletions templates/includes/splashtag.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<div class="absolute bottom-0 right-0 flex flex-row gap-2">
{% for badge in splashtag.badges %}
{% if badge is not None %}
<img src="{{ badge.image.url }}" class="h-8 w-8" alt="{{ badge.description.string }}"
title="{{ badge.description.string }}">
<img src="{{ badge.image.url }}" class="h-8 w-8" alt="{{ badge.translated_description }}"
title="{{ badge.translated_description }}">
{% else %}
<span class="h-8 w-8"></span>
{% endif %}
Expand Down

0 comments on commit 7882263

Please sign in to comment.