mirror of
https://github.com/ae-utbm/sith.git
synced 2026-11-20 16:09:54 +00:00
Make ClubRole.name translatable
This commit is contained in:
1 parent
aab5cc178e
commit
884940af30
8 files changed
+167
-23
No files matched your search
+15
-2
@@ -302,12 +302,22 @@ class ClubRoleForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = ClubRole
|
||||
fields = ["name", "description", "is_presidency", "is_board", "is_active"]
|
||||
fields = [
|
||||
"name",
|
||||
"name_en",
|
||||
"description",
|
||||
"is_presidency",
|
||||
"is_board",
|
||||
"is_active",
|
||||
]
|
||||
widgets = {
|
||||
"is_presidency": forms.HiddenInput(),
|
||||
"is_board": forms.HiddenInput(),
|
||||
"is_active": forms.CheckboxInput(attrs={"class": "switch"}),
|
||||
}
|
||||
help_texts = {
|
||||
"name_en": _("Provide an english name for non-french speaking users.")
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
@@ -354,7 +364,10 @@ class ClubRoleCreateForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = ClubRole
|
||||
fields = ["name", "description"]
|
||||
fields = ["name", "name_en", "description"]
|
||||
help_texts = {
|
||||
"name_en": _("Provide an english name for non-french speaking users.")
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self, *args, club: Club, is_presidency: bool, is_board: bool, **kwargs
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# Generated by Django 5.2.18 on 2026-11-14 11:44
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from django.db import migrations, models
|
||||
from django.db.models import F
|
||||
from django.db.models.expressions import Case, Value, When
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.db.migrations.state import StateApps
|
||||
|
||||
|
||||
def copy_name(apps: StateApps, schema_editor):
|
||||
"""Automatically populate French names and the most common English ones"""
|
||||
ClubRole = apps.get_model("club", "ClubRole")
|
||||
ClubRole.objects.update(
|
||||
name_fr=F("name"),
|
||||
name_en=Case(
|
||||
When(name="Président⸱e", then=Value("President")),
|
||||
When(name="Vice-Président⸱e", then=Value("Vice-president")),
|
||||
When(name="Trésorier⸱e", then=Value("Treasurer")),
|
||||
When(name="Responsable communication", then=Value("Communication manager")),
|
||||
When(name="Secrétaire", then=Value("Secretary")),
|
||||
When(name="Responsable info", then=Value("IT manager")),
|
||||
When(name="Membre du bureau", then=Value("Board member")),
|
||||
When(name="Membre actif⸱ve", then=Value("Active member")),
|
||||
When(name="Curieux⸱euse", then=Value("Curious")),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("club", "0019_remove_mailingsubscription_mailing_and_more")]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="clubrole",
|
||||
name="name_en",
|
||||
field=models.CharField(max_length=50, null=True, verbose_name="name"),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="clubrole",
|
||||
name="name_fr",
|
||||
field=models.CharField(max_length=50, null=True, verbose_name="name"),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="clubrole",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("club", "name"),
|
||||
name="clubrole_club_name_unique",
|
||||
violation_error_message="There is already a role with that name",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="clubrole",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("club", "name_fr"),
|
||||
name="clubrole_club_name_unique-fr",
|
||||
violation_error_message="There is already a role with that name",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="clubrole",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("club", "name_en"),
|
||||
name="clubrole_club_name_unique-en",
|
||||
violation_error_message="There is already a role with that name",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(
|
||||
copy_name, reverse_code=migrations.RunPython.noop, elidable=True
|
||||
),
|
||||
]
|
||||
+6
-1
@@ -307,7 +307,12 @@ class ClubRole(OrderedModel):
|
||||
violation_error_message=_(
|
||||
"A role cannot be in the presidency while not being in the board"
|
||||
),
|
||||
)
|
||||
),
|
||||
models.UniqueConstraint(
|
||||
fields=("club", "name"),
|
||||
name="clubrole_club_name_unique",
|
||||
violation_error_message=_("There is already a role with that name"),
|
||||
),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@@ -37,6 +37,9 @@
|
||||
<div class="form-group">
|
||||
{{ subform.name.as_field_group() }}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ subform.name_en.as_field_group() }}
|
||||
</div>
|
||||
<div class="form-group">
|
||||
{{ subform.description.as_field_group() }}
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,7 @@ import pytest
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import translation
|
||||
from django.utils.timezone import now
|
||||
from model_bakery import baker, seq
|
||||
from model_bakery.recipe import Recipe
|
||||
@@ -281,3 +282,14 @@ class TestClubRoleUpdate(TestCase):
|
||||
# the second membership is finished, so its user shouldn't get the role
|
||||
assert members[0].user.groups.contains(self.club.board_group)
|
||||
assert not members[1].user.groups.contains(self.club.board_group)
|
||||
|
||||
def test_name_translation(self):
|
||||
"""Test that setting the english name works."""
|
||||
name_en = "something something"
|
||||
self.payload["roles-0-name_en"] = name_en
|
||||
formset = ClubRoleFormSet(data=self.payload, instance=self.club)
|
||||
assert formset.is_valid()
|
||||
formset.save()
|
||||
self.roles[0].refresh_from_db()
|
||||
with translation.override("en"):
|
||||
assert self.roles[0].name == name_en
|
||||
@@ -0,0 +1,8 @@
|
||||
from modeltranslation.translator import TranslationOptions, register
|
||||
|
||||
from club.models import ClubRole
|
||||
|
||||
|
||||
@register(ClubRole)
|
||||
class ClubRoleTranslationOptions(TranslationOptions):
|
||||
fields = ("name",)
|
||||
@@ -252,7 +252,6 @@ class Command(BaseCommand):
|
||||
date_of_birth="1942-06-12",
|
||||
password="plop",
|
||||
)
|
||||
User.objects.all().update(cgu_approved_at=now())
|
||||
User.groups.through.objects.bulk_create(
|
||||
[
|
||||
User.groups.through(group=groups.counter_admin, user=counter),
|
||||
@@ -277,6 +276,10 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
self._create_pages(groups)
|
||||
# the "approve cgu" button is shown if the cgu were approved
|
||||
# before the last version of the CGU page.
|
||||
# Hence, it's better for this update to be after page creation.
|
||||
User.objects.all().update(cgu_approved_at=now())
|
||||
|
||||
self._create_subscription(root)
|
||||
self._create_subscription(skia)
|
||||
@@ -779,28 +782,47 @@ class Command(BaseCommand):
|
||||
name="Carte AE", address="Jamais imprimée", parent=ae
|
||||
)
|
||||
roles = []
|
||||
presidency_roles = ["Président⸱e", "Vice-Président⸱e"]
|
||||
presidency_roles = [
|
||||
("Président⸱e", "President"),
|
||||
("Vice-Président⸱e", "Vice-president"),
|
||||
]
|
||||
board_roles = [
|
||||
"Trésorier⸱e",
|
||||
"Secrétaire",
|
||||
"Respo Info",
|
||||
"Respo Com",
|
||||
"Membre du bureau",
|
||||
("Trésorier⸱e", "Treasurer"),
|
||||
("Secrétaire", "Secretary"),
|
||||
("Respo Info", "IT manager"),
|
||||
("Respo Com", "Communication manager"),
|
||||
("Membre du bureau", "Board member"),
|
||||
]
|
||||
simple_roles = [
|
||||
("Membre actif⸱ve", "Active member"),
|
||||
("Curieux⸱euse", "Curious"),
|
||||
]
|
||||
simple_roles = ["Membre actif⸱ve", "Curieux⸱euse"]
|
||||
for club in ae, pdf, troll, refound:
|
||||
for i, role in enumerate(presidency_roles):
|
||||
for i, (role_fr, role_en) in enumerate(presidency_roles):
|
||||
roles.append(
|
||||
ClubRole(
|
||||
club=club, order=i, name=role, is_presidency=True, is_board=True
|
||||
club=club,
|
||||
order=i,
|
||||
name=role_fr,
|
||||
name_en=role_en,
|
||||
is_presidency=True,
|
||||
is_board=True,
|
||||
)
|
||||
)
|
||||
for i, role in enumerate(board_roles, start=len(presidency_roles)):
|
||||
roles.append(ClubRole(club=club, order=i, name=role, is_board=True))
|
||||
for i, role in enumerate(
|
||||
for i, (role_fr, role_en) in enumerate(
|
||||
board_roles, start=len(presidency_roles)
|
||||
):
|
||||
roles.append(
|
||||
ClubRole(
|
||||
club=club, order=i, name=role_fr, name_en=role_en, is_board=True
|
||||
)
|
||||
)
|
||||
for i, (role_fr, role_en) in enumerate(
|
||||
simple_roles, start=len(presidency_roles) + len(board_roles)
|
||||
):
|
||||
roles.append(ClubRole(club=club, order=i, name=role))
|
||||
roles.append(
|
||||
ClubRole(club=club, order=i, name=role_fr, name_en=role_en)
|
||||
)
|
||||
ClubRole.objects.bulk_create(roles)
|
||||
insta, fb, discord, _ = LinkType.objects.bulk_create(
|
||||
[
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-11-12 15:32+0100\n"
|
||||
"POT-Creation-Date: 2026-11-14 13:59+0100\n"
|
||||
"PO-Revision-Date: 2016-07-18\n"
|
||||
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
|
||||
"Language-Team: AE info <ae.info@utbm.fr>\n"
|
||||
@@ -251,6 +251,10 @@ msgstr "Inactif"
|
||||
msgid "All clubs"
|
||||
msgstr "Tous les clubs"
|
||||
|
||||
#: club/forms.py
|
||||
msgid "Provide an english name for non-french speaking users."
|
||||
msgstr "Fournissez un nom anglais pour les utilisateurs non-francophones."
|
||||
|
||||
#: club/models.py
|
||||
msgid "slug name"
|
||||
msgstr "nom slug"
|
||||
@@ -340,6 +344,10 @@ msgid "A role cannot be in the presidency while not being in the board"
|
||||
msgstr ""
|
||||
"Un rôle ne peut pas appartenir à la présidence sans être dans le bureau"
|
||||
|
||||
#: club/models.py
|
||||
msgid "There is already a role with that name"
|
||||
msgstr "Il existe déjà un rôle avec ce nom"
|
||||
|
||||
#: club/models.py
|
||||
#, python-format
|
||||
msgid "Role %(role)s cannot be placed below a member role"
|
||||
@@ -4344,7 +4352,8 @@ msgid ""
|
||||
"A minor is barman on this on this device, so you cannot currently sell "
|
||||
"alcohol."
|
||||
msgstr ""
|
||||
"Un mineur est barman sur cet appareil, vous ne pouvez donc pas vendre d'alcool actuellement."
|
||||
"Un mineur est barman sur cet appareil, vous ne pouvez donc pas vendre "
|
||||
"d'alcool actuellement."
|
||||
|
||||
#: counter/views/eticket.py
|
||||
msgid "people(s)"
|
||||
@@ -5499,14 +5508,14 @@ msgstr "Photos de %(user_name)s"
|
||||
msgid "Download all my pictures"
|
||||
msgstr "Télécharger toutes mes photos"
|
||||
|
||||
#: sith/settings.py
|
||||
msgid "English"
|
||||
msgstr "Anglais"
|
||||
|
||||
#: sith/settings.py
|
||||
msgid "French"
|
||||
msgstr "Français"
|
||||
|
||||
#: sith/settings.py
|
||||
msgid "English"
|
||||
msgstr "Anglais"
|
||||
|
||||
#: sith/settings.py
|
||||
msgid "TC"
|
||||
msgstr "TC"
|
||||
|
||||
Reference in new issue
Block a user