Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Don't translate the trophy model info

Roland Geider99352beaf47b
diff --git a/wger/core/management/commands/extract-i18n.py b/wger/core/management/commands/extract-i18n.py
index 968c83eda..c73abb3f7 100644
--- a/wger/core/management/commands/extract-i18n.py
+++ b/wger/core/management/commands/extract-i18n.py
@@ -25,6 +25,7 @@ from wger.exercises.models import (
ExerciseCategory,
Muscle,
)
+from wger.trophies.models import Trophy
class Command(BaseCommand):
@@ -58,6 +59,11 @@ class Command(BaseCommand):
+ [i for i in WeightUnit.objects.all()]
)
+ # Trophy data is only translated in the django repo
+ trophy_data = [i.name for i in Trophy.objects.all()] + [
+ i.description for i in Trophy.objects.all()
+ ]
+
# Make entries unique and sort alphabetically
data = sorted(set([i.__str__() for i in data]))
@@ -67,6 +73,8 @@ class Command(BaseCommand):
out = '{% load i18n %}\n'
for i in data:
out += f'{{% translate "{i}" %}}\n'
+ for i in trophy_data:
+ out += f'{{% translate "{i}" %}}\n'
f.write(out)
self.stdout.write(self.style.SUCCESS('Wrote content to wger/i18n.tpl'))
diff --git a/wger/trophies/api/serializers.py b/wger/trophies/api/serializers.py
index bab681a46..120947fa3 100644
--- a/wger/trophies/api/serializers.py
+++ b/wger/trophies/api/serializers.py
@@ -19,6 +19,7 @@ import logging
# Django
from django.templatetags.static import static
+from django.utils.translation import gettext as _
# Third Party
from rest_framework import serializers
@@ -30,6 +31,7 @@ from wger.trophies.models import (
UserTrophy,
)
+
logger = logging.getLogger(__name__)
@@ -41,6 +43,8 @@ class TrophySerializer(serializers.ModelSerializer):
"""
image = serializers.SerializerMethodField()
+ name = serializers.SerializerMethodField()
+ description = serializers.SerializerMethodField()
class Meta:
model = Trophy
@@ -57,6 +61,14 @@ class TrophySerializer(serializers.ModelSerializer):
)
read_only_fields = fields
+ def get_name(self, obj: Trophy):
+ """Translate the trophy name"""
+ return _(obj.name)
+
+ def get_description(self, obj: Trophy):
+ """Translate the trophy description"""
+ return _(obj.description)
+
def get_image(self, obj: Trophy):
"""Build absolute URL to trophy image, if possible."""
diff --git a/wger/trophies/models/trophy.py b/wger/trophies/models/trophy.py
index d19acc901..8882b8850 100644
--- a/wger/trophies/models/trophy.py
+++ b/wger/trophies/models/trophy.py
@@ -19,7 +19,6 @@ import uuid
# Django
from django.db import models
-from django.utils.translation import gettext_lazy as _
class Trophy(models.Model):
@@ -36,13 +35,13 @@ class Trophy(models.Model):
TYPE_OTHER = 'other'
TROPHY_TYPES = (
- (TYPE_TIME, _('Time-based')),
- (TYPE_VOLUME, _('Volume-based')),
- (TYPE_COUNT, _('Count-based')),
- (TYPE_SEQUENCE, _('Sequence-based')),
- (TYPE_DATE, _('Date-based')),
- (TYPE_PR, _('Personal Record')),
- (TYPE_OTHER, _('Other')),
+ (TYPE_TIME, 'Time-based'),
+ (TYPE_VOLUME, 'Volume-based'),
+ (TYPE_COUNT, 'Count-based'),
+ (TYPE_SEQUENCE, 'Sequence-based'),
+ (TYPE_DATE, 'Date-based'),
+ (TYPE_PR, 'Personal Record'),
+ (TYPE_OTHER, 'Other'),
)
uuid = models.UUIDField(
@@ -54,14 +53,14 @@ class Trophy(models.Model):
name = models.CharField(
max_length=100,
- verbose_name=_('Name'),
- help_text=_('The name of the trophy'),
+ verbose_name='Name',
+ help_text='The name of the trophy',
)
"""The user-facing name of the trophy"""
description = models.TextField(
- verbose_name=_('Description'),
- help_text=_('A description of how to earn this trophy'),
+ verbose_name='Description',
+ help_text='A description of how to earn this trophy',
blank=True,
default='',
)
@@ -71,58 +70,58 @@ class Trophy(models.Model):
max_length=20,
choices=TROPHY_TYPES,
default=TYPE_OTHER,
- verbose_name=_('Trophy type'),
- help_text=_('The type of criteria used to evaluate this trophy'),
+ verbose_name='Trophy type',
+ help_text='The type of criteria used to evaluate this trophy',
)
"""The type of trophy (time, volume, count, sequence, date, other)"""
checker_class = models.CharField(
max_length=255,
- verbose_name=_('Checker class'),
- help_text=_('The Python class path used to check if this trophy is earned'),
+ verbose_name='Checker class',
+ help_text='The Python class path used to check if this trophy is earned',
)
"""Python path to the checker class (e.g., 'wger.trophies.checkers.CountBasedChecker')"""
checker_params = models.JSONField(
default=dict,
blank=True,
- verbose_name=_('Checker parameters'),
- help_text=_('JSON parameters passed to the checker class'),
+ verbose_name='Checker parameters',
+ help_text='JSON parameters passed to the checker class',
)
"""Parameters for the checker class (e.g., {'count': 1} for workout count)"""
is_hidden = models.BooleanField(
default=False,
- verbose_name=_('Hidden'),
- help_text=_('If true, this trophy is hidden until earned'),
+ verbose_name='Hidden',
+ help_text='If true, this trophy is hidden until earned',
)
"""Whether the trophy is hidden until earned"""
is_progressive = models.BooleanField(
default=False,
- verbose_name=_('Progressive'),
- help_text=_('If true, this trophy shows progress towards completion'),
+ verbose_name='Progressive',
+ help_text='If true, this trophy shows progress towards completion',
)
"""Whether to show progress towards earning the trophy"""
is_active = models.BooleanField(
default=True,
- verbose_name=_('Active'),
- help_text=_('If false, this trophy cannot be earned'),
+ verbose_name='Active',
+ help_text='If false, this trophy cannot be earned',
)
"""Whether the trophy is active and can be earned"""
is_repeatable = models.BooleanField(
default=False,
- verbose_name=_('Repeatable'),
- help_text=_('If true, this trophy can be earned multiple times'),
+ verbose_name='Repeatable',
+ help_text='If true, this trophy can be earned multiple times',
)
"""Whether the trophy can be earned multiple times"""
order = models.PositiveIntegerField(
default=0,
- verbose_name=_('Order'),
- help_text=_('Display order of the trophy'),
+ verbose_name='Order',
+ help_text='Display order of the trophy',
)
"""Display order for the trophy"""
@@ -140,8 +139,8 @@ class Trophy(models.Model):
class Meta:
ordering = ['order', 'name']
- verbose_name = _('Trophy')
- verbose_name_plural = _('Trophies')
+ verbose_name = 'Trophy'
+ verbose_name_plural = 'Trophies'
def __str__(self):
return self.name
diff --git a/wger/trophies/models/user_statistics.py b/wger/trophies/models/user_statistics.py
index 21a8afb31..9c9c59689 100644
--- a/wger/trophies/models/user_statistics.py
+++ b/wger/trophies/models/user_statistics.py
@@ -17,7 +17,6 @@
# Django
from django.contrib.auth.models import User
from django.db import models
-from django.utils.translation import gettext_lazy as _
class UserStatistics(models.Model):
@@ -31,7 +30,7 @@ class UserStatistics(models.Model):
User,
on_delete=models.CASCADE,
related_name='trophy_statistics',
- verbose_name=_('User'),
+ verbose_name='User',
)
"""The user these statistics belong to"""
@@ -39,95 +38,95 @@ class UserStatistics(models.Model):
max_digits=12,
decimal_places=2,
default=0,
- verbose_name=_('Total weight lifted'),
- help_text=_('Cumulative weight lifted in kg'),
+ verbose_name='Total weight lifted',
+ help_text='Cumulative weight lifted in kg',
)
"""Total cumulative weight lifted in kg"""
total_workouts = models.PositiveIntegerField(
default=0,
- verbose_name=_('Total workouts'),
- help_text=_('Total number of workout sessions completed'),
+ verbose_name='Total workouts',
+ help_text='Total number of workout sessions completed',
)
"""Total number of workout sessions completed"""
current_streak = models.PositiveIntegerField(
default=0,
- verbose_name=_('Current streak'),
- help_text=_('Current consecutive days with workouts'),
+ verbose_name='Current streak',
+ help_text='Current consecutive days with workouts',
)
"""Current consecutive workout streak in days"""
longest_streak = models.PositiveIntegerField(
default=0,
- verbose_name=_('Longest streak'),
- help_text=_('Longest consecutive days with workouts'),
+ verbose_name='Longest streak',
+ help_text='Longest consecutive days with workouts',
)
"""Longest consecutive workout streak ever achieved"""
last_workout_date = models.DateField(
null=True,
blank=True,
- verbose_name=_('Last workout date'),
- help_text=_('Date of the most recent workout'),
+ verbose_name='Last workout date',
+ help_text='Date of the most recent workout',
)
"""Date of the most recent workout"""
earliest_workout_time = models.TimeField(
null=True,
blank=True,
- verbose_name=_('Earliest workout time'),
- help_text=_('Earliest time a workout was started'),
+ verbose_name='Earliest workout time',
+ help_text='Earliest time a workout was started',
)
"""Earliest time a workout was ever started"""
latest_workout_time = models.TimeField(
null=True,
blank=True,
- verbose_name=_('Latest workout time'),
- help_text=_('Latest time a workout was started'),
+ verbose_name='Latest workout time',
+ help_text='Latest time a workout was started',
)
"""Latest time a workout was ever started"""
weekend_workout_streak = models.PositiveIntegerField(
default=0,
- verbose_name=_('Weekend workout streak'),
- help_text=_('Consecutive weekends with workouts on both Saturday and Sunday'),
+ verbose_name='Weekend workout streak',
+ help_text='Consecutive weekends with workouts on both Saturday and Sunday',
)
"""Consecutive weekends with workouts on both Saturday and Sunday"""
last_complete_weekend_date = models.DateField(
null=True,
blank=True,
- verbose_name=_('Last complete weekend date'),
- help_text=_('Date of the last Saturday where both Sat and Sun had workouts'),
+ verbose_name='Last complete weekend date',
+ help_text='Date of the last Saturday where both Sat and Sun had workouts',
)
"""Used for tracking consecutive weekend workouts"""
last_inactive_date = models.DateField(
null=True,
blank=True,
- verbose_name=_('Last inactive date'),
- help_text=_('Last date before the current activity period began'),
+ verbose_name='Last inactive date',
+ help_text='Last date before the current activity period began',
)
"""Used for Phoenix trophy - tracks when user was last inactive"""
worked_out_jan_1 = models.BooleanField(
default=False,
- verbose_name=_('Worked out on January 1st'),
- help_text=_('Whether user has ever worked out on January 1st'),
+ verbose_name='Worked out on January 1st',
+ help_text='Whether user has ever worked out on January 1st',
)
"""Flag for New Year, New Me trophy"""
last_updated = models.DateTimeField(
auto_now=True,
- verbose_name=_('Last updated'),
+ verbose_name='Last updated',
)
"""When these statistics were last updated"""
class Meta:
- verbose_name = _('User statistics')
- verbose_name_plural = _('User statistics')
+ verbose_name = 'User statistics'
+ verbose_name_plural = 'User statistics'
def __str__(self):
return f'Statistics for {self.user.username}'
diff --git a/wger/trophies/models/user_trophy.py b/wger/trophies/models/user_trophy.py
index f6687e577..5131707fa 100644
--- a/wger/trophies/models/user_trophy.py
+++ b/wger/trophies/models/user_trophy.py
@@ -24,7 +24,6 @@ from django.db import (
IntegrityError,
models,
)
-from django.utils.translation import gettext_lazy as _
# Local
from .trophy import Trophy
@@ -39,7 +38,7 @@ class UserTrophy(models.Model):
User,
on_delete=models.CASCADE,
related_name='earned_trophies',
- verbose_name=_('User'),
+ verbose_name='User',
)
"""The user who earned the trophy"""
@@ -47,29 +46,29 @@ class UserTrophy(models.Model):
Trophy,
on_delete=models.CASCADE,
related_name='user_trophies',
- verbose_name=_('Trophy'),
+ verbose_name='Trophy',
)
"""The trophy that was earned"""
earned_at = models.DateTimeField(
auto_now_add=True,
- verbose_name=_('Earned at'),
- help_text=_('When the trophy was earned'),
+ verbose_name='Earned at',
+ help_text='When the trophy was earned',
)
"""When the trophy was earned"""
progress = models.FloatField(
default=0.0,
validators=[MinValueValidator(0.0), MaxValueValidator(100.0)],
- verbose_name=_('Progress'),
- help_text=_('Progress towards earning the trophy (0-100)'),
+ verbose_name='Progress',
+ help_text='Progress towards earning the trophy (0-100)',
)
"""Progress towards earning the trophy (0-100%)"""
is_notified = models.BooleanField(
default=False,
- verbose_name=_('Notified'),
- help_text=_('Whether the user has been notified about earning this trophy'),
+ verbose_name='Notified',
+ help_text='Whether the user has been notified about earning this trophy',
)
"""Whether the user has been notified about this trophy (for future notification system)"""
@@ -77,15 +76,15 @@ class UserTrophy(models.Model):
blank=True,
null=True,
default=None,
- verbose_name=_('Context data'),
- help_text=_('Additional information concerning this trophy'),
+ verbose_name='Context data',
+ help_text='Additional information concerning this trophy',
)
"""Additional information concerning this trophy (useful for repeatable trophies)"""
class Meta:
ordering = ['-earned_at']
- verbose_name = _('User trophy')
- verbose_name_plural = _('User trophies')
+ verbose_name = 'User trophy'
+ verbose_name_plural = 'User trophies'
def __str__(self):
return f'{self.user.username} - {self.trophy.name}'
diff --git a/wger/trophies/services/statistics.py b/wger/trophies/services/statistics.py
index 91c881f5f..2128953c7 100644
--- a/wger/trophies/services/statistics.py
+++ b/wger/trophies/services/statistics.py
@@ -22,7 +22,6 @@ from typing import Optional
# Django
from django.contrib.auth.models import User
-from django.db.models import Sum
# wger
from wger.manager.consts import WEIGHT_UNIT_LB