mirror of
https://github.com/wger-project/wger.git
synced 2026-11-29 09:41:02 +01:00
Merge pull request #2582 from LukeSekai/fix/plural-count-messages
Use plural forms in counted backend messages
This commit is contained in:
@@ -28,7 +28,7 @@ schema reset) without asking.
|
||||
|
||||
## Layout
|
||||
|
||||
```
|
||||
```text
|
||||
wger/<app>/
|
||||
├── models/ one file per model (or group), re-exported from models/__init__.py
|
||||
├── api/ DRF serializers, viewsets, filtersets
|
||||
|
||||
@@ -22,6 +22,8 @@ Progression requirements can now reference the top of the prescribed range via t
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* Counted messages for token expiry, confirmation links, inactive-member reminders,
|
||||
and workout-session limits now use locale-aware plural forms.
|
||||
* Deleting a routine, day, slot, or slot entry now preserves completed workout
|
||||
sessions and logs, including performed and target values. Only the references
|
||||
to deleted routine structure are cleared. Explicit session deletion and account
|
||||
|
||||
@@ -107,7 +107,10 @@
|
||||
</a>
|
||||
</div>
|
||||
<p class="note">
|
||||
{% blocktranslate with time=expire_date|time:"TIME_FORMAT" date=expire_date|date:"DATE_FORMAT" trimmed %}
|
||||
{% blocktranslate with time=expire_date|time:"TIME_FORMAT" date=expire_date|date:"DATE_FORMAT" count expire_hours=expire_hours trimmed %}
|
||||
The link is valid for {{ expire_hours }} hour (until {{ date }}, {{ time }}).
|
||||
You can request a new one from your profile settings.
|
||||
{% plural %}
|
||||
The link is valid for {{ expire_hours }} hours (until {{ date }}, {{ time }}).
|
||||
You can request a new one from your profile settings.
|
||||
{% endblocktranslate %}
|
||||
|
||||
@@ -14,8 +14,12 @@ Your email verification code is listed below. Please enter it in your open brows
|
||||
{% blocktranslate trimmed %}
|
||||
To confirm this is correct, go to {{ activate_url }}
|
||||
{% endblocktranslate %}
|
||||
{% blocktranslate with time=expire_date|time:"TIME_FORMAT" date=expire_date|date:"DATE_FORMAT" trimmed %}
|
||||
The link is valid for {{ expire_hours }} hours (until {{ date }}, {{ time }}). You can request a new one from your profile settings.
|
||||
{% blocktranslate with time=expire_date|time:"TIME_FORMAT" date=expire_date|date:"DATE_FORMAT" count expire_hours=expire_hours trimmed %}
|
||||
The link is valid for {{ expire_hours }} hour (until {{ date }}, {{ time }}).
|
||||
You can request a new one from your profile settings.
|
||||
{% plural %}
|
||||
The link is valid for {{ expire_hours }} hours (until {{ date }}, {{ time }}).
|
||||
You can request a new one from your profile settings.
|
||||
{% endblocktranslate %}
|
||||
{% endif %}
|
||||
{% endautoescape %}{% endblock content %}
|
||||
|
||||
@@ -53,7 +53,10 @@
|
||||
|
||||
{% if long_lived_sessions %}
|
||||
<p>
|
||||
{% blocktranslate trimmed with days=refresh_token_lifetime_days %}
|
||||
{% blocktranslate trimmed count days=refresh_token_lifetime_days %}
|
||||
Refresh tokens expire {{ days }} day after they were
|
||||
generated, unless you revoke them sooner.
|
||||
{% plural %}
|
||||
Refresh tokens expire {{ days }} days after they were
|
||||
generated, unless you revoke them sooner.
|
||||
{% endblocktranslate %}
|
||||
|
||||
@@ -26,6 +26,7 @@ from django.test import override_settings
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_datetime
|
||||
from django.utils.translation import override
|
||||
|
||||
# Third Party
|
||||
from rest_framework.authtoken.models import Token
|
||||
@@ -56,6 +57,21 @@ class ApiKeyTestCase(WgerTestCase):
|
||||
Tests the API key page
|
||||
"""
|
||||
|
||||
def test_refresh_token_lifetime_pluralization(self):
|
||||
self.user_login('test')
|
||||
user = User.objects.get(username='test')
|
||||
mint_long_lived_refresh_token(user, lifetime_seconds=120 * 86400)
|
||||
|
||||
for days in (1, 2, 21):
|
||||
with (
|
||||
self.subTest(days=days),
|
||||
override('en'),
|
||||
override_settings(HEADLESS_JWT_REFRESH_TOKEN_EXPIRES_IN=days * 86400),
|
||||
):
|
||||
response = self.client.get(reverse('core:user:api-key'))
|
||||
unit = 'day' if days == 1 else 'days'
|
||||
self.assertContains(response, f'Refresh tokens expire {days} {unit} after')
|
||||
|
||||
def test_api_key_page(self):
|
||||
"""
|
||||
Tests the API key generation page
|
||||
|
||||
44
wger/core/tests/test_plural_messages.py
Normal file
44
wger/core/tests/test_plural_messages.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# This file is part of wger Workout Manager, licensed under AGPL-3.0-or-later.
|
||||
|
||||
# Standard Library
|
||||
from datetime import timedelta
|
||||
|
||||
# Django
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.template.loader import render_to_string
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils import timezone
|
||||
from django.utils.html import strip_tags
|
||||
from django.utils.translation import override
|
||||
|
||||
|
||||
class CountedTemplateMessagesTestCase(SimpleTestCase):
|
||||
"""Counted messages in pages and emails select the appropriate plural form."""
|
||||
|
||||
def render_message(self, template: str, context: dict) -> str:
|
||||
with override('en'):
|
||||
rendered = render_to_string(template, {'user': AnonymousUser(), **context})
|
||||
return ' '.join(strip_tags(rendered).split())
|
||||
|
||||
def test_confirmation_link_lifetime(self):
|
||||
for hours in (1, 2, 24):
|
||||
for extension in ('html', 'txt'):
|
||||
with self.subTest(hours=hours, extension=extension):
|
||||
text = self.render_message(
|
||||
f'account/email/email_confirmation_message.{extension}',
|
||||
{
|
||||
'expire_hours': hours,
|
||||
'expire_date': timezone.now() + timedelta(hours=hours),
|
||||
},
|
||||
)
|
||||
unit = 'hour' if hours == 1 else 'hours'
|
||||
self.assertIn(f'The link is valid for {hours} {unit} (until', text)
|
||||
|
||||
def test_inactive_member_reminder(self):
|
||||
for weeks in (1, 2, 21):
|
||||
with self.subTest(weeks=weeks):
|
||||
text = self.render_message('gym/email_inactive_members.html', {'weeks': weeks})
|
||||
unit = 'week' if weeks == 1 else 'weeks'
|
||||
self.assertIn(f'in the last {weeks} {unit}', text)
|
||||
if weeks == 1:
|
||||
self.assertNotIn('in the last 1 weeks', text)
|
||||
@@ -1,5 +1,9 @@
|
||||
{% load i18n wger_extras %}
|
||||
{% blocktranslate %}The following users have not visited the gym in the last {{ weeks }} weeks{% endblocktranslate %}
|
||||
{% blocktranslate trimmed count weeks=weeks %}
|
||||
The following users have not visited the gym in the last {{ weeks }} week
|
||||
{% plural %}
|
||||
The following users have not visited the gym in the last {{ weeks }} weeks
|
||||
{% endblocktranslate %}
|
||||
|
||||
{% translate "User"|ljust:"25" %} {% translate "Last activity" %}
|
||||
---------------------------------------------------------
|
||||
|
||||
@@ -23,7 +23,7 @@ from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_lazy as _, ngettext
|
||||
|
||||
# wger
|
||||
from wger.utils.uuid import uuid7
|
||||
@@ -190,7 +190,11 @@ class WorkoutSession(models.Model):
|
||||
|
||||
if self.datetime_end - self.datetime_start > self.max_duration():
|
||||
raise ValidationError(
|
||||
_('A session cannot be longer than %(hours)s hours.')
|
||||
ngettext(
|
||||
'A session cannot be longer than %(hours)s hour.',
|
||||
'A session cannot be longer than %(hours)s hours.',
|
||||
settings.WGER_MAX_SESSION_LENGTH_HOURS,
|
||||
)
|
||||
% {'hours': settings.WGER_MAX_SESSION_LENGTH_HOURS}
|
||||
)
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import zoneinfo
|
||||
|
||||
# Django
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import (
|
||||
IntegrityError,
|
||||
transaction,
|
||||
@@ -25,6 +26,7 @@ from django.db import (
|
||||
from django.test import override_settings
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import override
|
||||
|
||||
# Third Party
|
||||
from rest_framework import status
|
||||
@@ -60,6 +62,24 @@ class WorkoutSessionDurationTestCase(WgerTestCase):
|
||||
SESSION = 'bbbbbbbb-bbbb-bbbb-bbbb-000000000005'
|
||||
ROUTINE = 3
|
||||
|
||||
def test_limit_message_uses_the_configured_count(self):
|
||||
start = timezone.now()
|
||||
for hours in (1, 2, 21):
|
||||
with (
|
||||
self.subTest(hours=hours),
|
||||
override('en'),
|
||||
override_settings(WGER_MAX_SESSION_LENGTH_HOURS=hours),
|
||||
):
|
||||
session = WorkoutSession(
|
||||
datetime_start=start,
|
||||
datetime_end=start + datetime.timedelta(hours=hours + 1),
|
||||
)
|
||||
unit = 'hour' if hours == 1 else 'hours'
|
||||
with self.assertRaisesMessage(
|
||||
ValidationError, f'A session cannot be longer than {hours} {unit}.'
|
||||
):
|
||||
session.clean()
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.user_login('test')
|
||||
|
||||
Reference in New Issue
Block a user