Compare commits

...
12 Commits
Author SHA1 Message Date
thomas girod 4c1a94e83d Merge pull request #1553 from ae-utbm/fix-formula-product-init
fix: 500 when editing products being part of a formula
2026-11-19 13:08:56 +01:00
thomas girod cacc243562 Merge pull request #1552 from ae-utbm/model-translate
Model translate
2026-11-19 13:08:42 +01:00
imperosol 3065783492 fix: 500 when editing products being part of a formula 2026-11-18 16:11:17 +01:00
thomas girod 6805ef4912 Merge pull request #1548 from ae-utbm/edt-link
add timetable link to UserTabsMixin
2026-11-17 12:13:14 +01:00
imperosol 884940af30 Make ClubRole.name translatable 2026-11-14 14:10:13 +01:00
imperosol aab5cc178e add django-modeltranslation to dependencies
La lib permet d'activer les traductions sur certaines colonnes de la db. Sous le capot, ça se fait en ayant une colonne `<field>_fr` et une autre `<field>_en`.

On ne va pas faire ça pour tout, mais dans certains cas c'est quand même mieux pour les utilisateurs étrangers.
2026-11-14 12:41:36 +01:00
imperosol fa14bcb608 add timetable link to UserTabsMixin 2026-11-12 23:56:41 +01:00
thomas girod cda00e88df Merge pull request #1547 from ae-utbm/barman-age
Check birthdate and bans when adding users to counter sellers
2026-11-12 16:22:50 +01:00
imperosol a31062a271 doc: CounterClick 2026-11-12 15:49:31 +01:00
imperosol 01112a89aa forbid minors from selling alcohol 2026-11-12 15:49:31 +01:00
imperosol e45b4eb9e0 end barmanship on ban 2026-11-10 20:21:50 +01:00
imperosol 079ec8a8e5 forbid users with a ban or no birthdate to be barmen 2026-11-10 13:27:06 +01:00
26 changed files with 478 additions and 42 deletions

No files matched your search

+15 -2
View File
@@ -302,12 +302,22 @@ class ClubRoleForm(forms.ModelForm):
class Meta: class Meta:
model = ClubRole model = ClubRole
fields = ["name", "description", "is_presidency", "is_board", "is_active"] fields = [
"name",
"name_en",
"description",
"is_presidency",
"is_board",
"is_active",
]
widgets = { widgets = {
"is_presidency": forms.HiddenInput(), "is_presidency": forms.HiddenInput(),
"is_board": forms.HiddenInput(), "is_board": forms.HiddenInput(),
"is_active": forms.CheckboxInput(attrs={"class": "switch"}), "is_active": forms.CheckboxInput(attrs={"class": "switch"}),
} }
help_texts = {
"name_en": _("Provide an english name for non-french speaking users.")
}
def clean(self): def clean(self):
cleaned_data = super().clean() cleaned_data = super().clean()
@@ -354,7 +364,10 @@ class ClubRoleCreateForm(forms.ModelForm):
class Meta: class Meta:
model = ClubRole 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__( def __init__(
self, *args, club: Club, is_presidency: bool, is_board: bool, **kwargs 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
View File
@@ -307,7 +307,12 @@ class ClubRole(OrderedModel):
violation_error_message=_( violation_error_message=_(
"A role cannot be in the presidency while not being in the board" "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): def __str__(self):
+3
View File
@@ -37,6 +37,9 @@
<div class="form-group"> <div class="form-group">
{{ subform.name.as_field_group() }} {{ subform.name.as_field_group() }}
</div> </div>
<div class="form-group">
{{ subform.name_en.as_field_group() }}
</div>
<div class="form-group"> <div class="form-group">
{{ subform.description.as_field_group() }} {{ subform.description.as_field_group() }}
</div> </div>
+12
View File
@@ -4,6 +4,7 @@ import pytest
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.test import Client, TestCase from django.test import Client, TestCase
from django.urls import reverse from django.urls import reverse
from django.utils import translation
from django.utils.timezone import now from django.utils.timezone import now
from model_bakery import baker, seq from model_bakery import baker, seq
from model_bakery.recipe import Recipe 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 # the second membership is finished, so its user shouldn't get the role
assert members[0].user.groups.contains(self.club.board_group) assert members[0].user.groups.contains(self.club.board_group)
assert not members[1].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
+8
View File
@@ -0,0 +1,8 @@
from modeltranslation.translator import TranslationOptions, register
from club.models import ClubRole
@register(ClubRole)
class ClubRoleTranslationOptions(TranslationOptions):
fields = ("name",)
+36 -14
View File
@@ -252,7 +252,6 @@ class Command(BaseCommand):
date_of_birth="1942-06-12", date_of_birth="1942-06-12",
password="plop", password="plop",
) )
User.objects.all().update(cgu_approved_at=now())
User.groups.through.objects.bulk_create( User.groups.through.objects.bulk_create(
[ [
User.groups.through(group=groups.counter_admin, user=counter), User.groups.through(group=groups.counter_admin, user=counter),
@@ -277,6 +276,10 @@ class Command(BaseCommand):
) )
self._create_pages(groups) 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(root)
self._create_subscription(skia) self._create_subscription(skia)
@@ -779,28 +782,47 @@ class Command(BaseCommand):
name="Carte AE", address="Jamais imprimée", parent=ae name="Carte AE", address="Jamais imprimée", parent=ae
) )
roles = [] roles = []
presidency_roles = ["Président⸱e", "Vice-Président⸱e"] presidency_roles = [
("Président⸱e", "President"),
("Vice-Président⸱e", "Vice-president"),
]
board_roles = [ board_roles = [
"Trésorier⸱e", ("Trésorier⸱e", "Treasurer"),
"Secrétaire", ("Secrétaire", "Secretary"),
"Respo Info", ("Respo Info", "IT manager"),
"Respo Com", ("Respo Com", "Communication manager"),
"Membre du bureau", ("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 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( roles.append(
ClubRole( 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)): for i, (role_fr, role_en) in enumerate(
roles.append(ClubRole(club=club, order=i, name=role, is_board=True)) board_roles, start=len(presidency_roles)
for i, role in enumerate( ):
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) 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) ClubRole.objects.bulk_create(roles)
insta, fb, discord, _ = LinkType.objects.bulk_create( insta, fb, discord, _ = LinkType.objects.bulk_create(
[ [
+8
View File
@@ -769,6 +769,14 @@ class UserBan(models.Model):
def __str__(self): def __str__(self):
return f"Ban of user {self.user.id}" return f"Ban of user {self.user.id}"
def save(self, *args, **kwargs):
if self.ban_group_id in [
settings.SITH_GROUP_BANNED_COUNTER_ID,
settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
]:
self.user.counters.clear()
return super().save(*args, **kwargs)
class GlobalPermissionRights(models.Model): class GlobalPermissionRights(models.Model):
"""Little hack to have permissions not linked to a specific db table.""" """Little hack to have permissions not linked to a specific db table."""
+3
View File
@@ -321,6 +321,7 @@ class UserTabTestView(UserTabsMixin, DetailView): ...
"edit", "edit",
"prefs", "prefs",
"clubs", "clubs",
"timetable",
"stats", "stats",
"account", "account",
], ],
@@ -337,6 +338,7 @@ class UserTabTestView(UserTabsMixin, DetailView): ...
"edit", "edit",
"prefs", "prefs",
"clubs", "clubs",
"timetable",
"groups", "groups",
], ],
), ),
@@ -370,6 +372,7 @@ def test_displayed_user_self_tabs(user_factory, expected_tabs: list[str]):
"edit", "edit",
"prefs", "prefs",
"clubs", "clubs",
"timetable",
"groups", "groups",
"stats", "stats",
"account", "account",
+21
View File
@@ -275,6 +275,27 @@ class UserTabsMixin(TabedViewMixin):
"name": _("Clubs"), "name": _("Clubs"),
} }
) )
if user == self.request.user and not user.timetables.exists():
tab_list.append(
{
"url": reverse("timetable:generator"),
"slug": "timetable",
"name": _("Timetable"),
}
)
elif user == self.request.user or (
self.request.user.has_perm("timetable.view_timetable")
and user.preferences.show_my_timetable
):
tab_list.append(
{
"url": reverse(
"core:user_timetable", kwargs={"user_id": user.id}
),
"slug": "timetable",
"name": _("Timetable"),
}
)
if self.request.user.is_owner(user): if self.request.user.is_owner(user):
tab_list.append( tab_list.append(
{ {
+37 -4
View File
@@ -3,7 +3,7 @@ import math
import uuid import uuid
from collections import defaultdict from collections import defaultdict
from datetime import date, datetime, timezone from datetime import date, datetime, timezone
from typing import TYPE_CHECKING, ClassVar from typing import TYPE_CHECKING, ClassVar, LiteralString
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from django import forms from django import forms
@@ -19,7 +19,7 @@ from phonenumber_field.widgets import RegionalPhoneNumberWidget
from club.models import Club from club.models import Club
from club.widgets.ajax_select import AutoCompleteSelectClub from club.widgets.ajax_select import AutoCompleteSelectClub
from core.models import User, UserQuerySet from core.models import User, UserBan, UserQuerySet
from core.views import LoginForm from core.views import LoginForm
from core.views.forms import ( from core.views.forms import (
FutureDateTimeField, FutureDateTimeField,
@@ -257,6 +257,41 @@ class CounterEditForm(forms.ModelForm):
countersellers__is_regular=False countersellers__is_regular=False
).all() ).all()
def clean_sellers(self, field: LiteralString):
sellers = self.cleaned_data[field]
bans = [
settings.SITH_GROUP_BANNED_COUNTER_ID,
settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
]
invalid_sellers = sellers.annotate(
is_banned=Exists(
UserBan.objects.filter(user=OuterRef("pk"), ban_group__in=bans)
)
).filter(Q(is_banned=True) | Q(date_of_birth=None))
for seller in invalid_sellers:
if seller.is_banned:
self.add_error(
field,
ValidationError(
_("%(user)s is banned.") % {"user": seller.get_full_name()}
),
)
if not seller.date_of_birth:
self.add_error(
field,
ValidationError(
_("%(user)s has not filled its birthdate.")
% {"user": seller.get_full_name()}
),
)
return sellers
def clean_sellers_regular(self):
return self.clean_sellers("sellers_regular")
def clean_sellers_temporary(self):
return self.clean_sellers("sellers_temporary")
def clean(self): def clean(self):
regular: UserQuerySet = self.cleaned_data["sellers_regular"] regular: UserQuerySet = self.cleaned_data["sellers_regular"]
temporary: UserQuerySet = self.cleaned_data["sellers_temporary"] temporary: UserQuerySet = self.cleaned_data["sellers_temporary"]
@@ -472,8 +507,6 @@ class ProductForm(forms.ModelForm):
self.fields["name"].widget.attrs["autofocus"] = "autofocus" self.fields["name"].widget.attrs["autofocus"] = "autofocus"
if self.instance.id: if self.instance.id:
self.fields["counters"].initial = self.instance.counters.all() self.fields["counters"].initial = self.instance.counters.all()
if hasattr(self.instance, "formula"):
self.formula_init(self.instance.formula)
self.price_formset = ProductPriceFormSet( self.price_formset = ProductPriceFormSet(
*args, instance=self.instance, prefix="price", **kwargs *args, instance=self.instance, prefix="price", **kwargs
) )
+26 -1
View File
@@ -405,7 +405,7 @@ class TestCounterClick(TestFullClickBase):
self.assertRedirects(res, self.counter.get_absolute_url()) self.assertRedirects(res, self.counter.get_absolute_url())
assert self.updated_amount(self.customer) == Decimal(8) assert self.updated_amount(self.customer) == Decimal(8)
def test_click_alcool_unauthorized(self): def test_click_alcohol_unauthorized(self):
self.login_in_bar() self.login_in_bar()
for user in [self.underage_customer, self.banned_alcohol_customer]: for user in [self.underage_customer, self.banned_alcohol_customer]:
@@ -423,6 +423,31 @@ class TestCounterClick(TestFullClickBase):
assert self.updated_amount(user) == Decimal(7) assert self.updated_amount(user) == Decimal(7)
def test_click_no_alcohol_if_minor_barman(self):
"""Test that no age restricted product can be sold if the barman is minor."""
set_age(self.barmen, 17)
self.login_in_bar(self.barmen)
res = self.client.get(
reverse(
"counter:click",
kwargs={"counter_id": self.counter.id, "user_id": self.customer.id},
)
)
assert res.status_code == 200
messages = list(get_messages(res.wsgi_request))
assert len(messages) == 1
assert messages[0].level == DEFAULT_LEVELS["WARNING"]
assert messages[0].message == (
"Un mineur est barman sur cet appareil, "
"vous ne pouvez donc pas vendre d'alcool actuellement."
)
assert res.context_data["prices"] == [
self.gift,
self.snack,
self.cons,
self.dcons,
]
def test_click_unauthorized_customer(self): def test_click_unauthorized_customer(self):
self.login_in_bar() self.login_in_bar()
+57 -2
View File
@@ -1,3 +1,6 @@
from datetime import timedelta
from dateutil.utils import today
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.test import TestCase from django.test import TestCase
@@ -6,7 +9,7 @@ from model_bakery import baker
from club.models import Membership from club.models import Membership
from core.baker_recipes import subscriber_user from core.baker_recipes import subscriber_user
from core.models import Group, User from core.models import Group, User, UserBan
from counter.baker_recipes import product_recipe from counter.baker_recipes import product_recipe
from counter.forms import CounterEditForm from counter.forms import CounterEditForm
from counter.models import Counter, CounterSellers from counter.models import Counter, CounterSellers
@@ -18,7 +21,11 @@ class TestEditCounterSellers(TestCase):
cls.counter = baker.make(Counter, type="BAR") cls.counter = baker.make(Counter, type="BAR")
cls.products = product_recipe.make(_quantity=2, _bulk_create=True) cls.products = product_recipe.make(_quantity=2, _bulk_create=True)
cls.counter.products.add(*cls.products) cls.counter.products.add(*cls.products)
users = subscriber_user.make(_quantity=6, _bulk_create=True) users = subscriber_user.make(
date_of_birth=today() - timedelta(days=365 * 20),
_quantity=6,
_bulk_create=True,
)
cls.regular_barmen = users[:2] cls.regular_barmen = users[:2]
cls.tmp_barmen = users[2:4] cls.tmp_barmen = users[2:4]
cls.not_barmen = users[4:] cls.not_barmen = users[4:]
@@ -128,6 +135,54 @@ class TestEditCounterSellers(TestCase):
self.counter.sellers.filter(countersellers__is_regular=False) self.counter.sellers.filter(countersellers__is_regular=False)
) == set(self.tmp_barmen) ) == set(self.tmp_barmen)
def test_barman_without_birthdate(self):
"""Test that users without a birthdate cannot be sellers."""
user = subscriber_user.make()
form = CounterEditForm(
data={
"sellers_regular": [*self.regular_barmen, user],
"sellers_temporary": self.tmp_barmen,
"products": self.products,
},
instance=self.counter,
user=self.operator,
)
assert not form.is_valid()
assert form.errors == {
"sellers_regular": [
f"{user.get_full_name()} n'a pas renseigné sa date de naissance."
]
}
def test_banned_barman_forbidden(self):
"""Test that users with a counter ban cannot be sellers."""
UserBan.objects.create(
user=self.not_barmen[0],
ban_group_id=settings.SITH_GROUP_BANNED_COUNTER_ID,
reason="ban comptoir",
)
UserBan.objects.create(
user=self.not_barmen[1],
ban_group_id=settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
reason="ban comptoir",
)
form = CounterEditForm(
data={
"sellers_regular": [*self.regular_barmen, *self.not_barmen[0:2]],
"sellers_temporary": self.tmp_barmen,
"products": self.products,
},
instance=self.counter,
user=self.operator,
)
assert not form.is_valid()
assert form.errors == {
"sellers_regular": [
f"{self.not_barmen[0].get_full_name()} est banni.",
f"{self.not_barmen[1].get_full_name()} est banni.",
]
}
class TestEditCounterProducts(TestCase): class TestEditCounterProducts(TestCase):
@classmethod @classmethod
+1 -1
View File
@@ -145,7 +145,7 @@ class TestStudentCard(TestCase):
self.login_in_counter() self.login_in_counter()
barman = subscriber_user.make() barman = subscriber_user.make()
self.counter.sellers.add(barman) self.counter.sellers.add(barman, through_defaults={"is_regular": True})
# We want to test sending requests from another counter while # We want to test sending requests from another counter while
# we are currently registered to another counter # we are currently registered to another counter
# so we connect to a counter and # so we connect to a counter and
+78 -4
View File
@@ -43,8 +43,8 @@ from counter.views.mixins import CounterTabsMixin
from counter.views.student_card import StudentCardFormFragment from counter.views.student_card import StudentCardFormFragment
if TYPE_CHECKING: if TYPE_CHECKING:
from django.http import HttpRequest
from django.utils.safestring import SafeString from django.utils.safestring import SafeString
from ninja.main import HttpRequest
from core.models import User from core.models import User
@@ -60,9 +60,70 @@ def get_operator(request: HttpRequest, counter: Counter, customer: Customer) ->
class CounterClick( class CounterClick(
CounterTabsMixin, UseFragmentsMixin, CanViewMixin, SingleObjectMixin, FormView CounterTabsMixin, UseFragmentsMixin, CanViewMixin, SingleObjectMixin, FormView
): ):
"""The click view """The click view.
This is a detail view not to have to worry about loading the counter
Everything is made by hand in the post method. This page is reached from the counter main page, after selecting
the user who is purchasing stuff.
# Counter access
Who can perform barman actions depends on the type of the counter :
- for eboutic counters, no barman access at all is granted ;
it's just a 404, as there should be only one eboutic,
accessible only at `/eboutic/`
- office counters are accessible to the board members of the
club owning the counter and to users that have been
explicitly added to the sellers of this counter.
- bar counters are accessible to users that have been added to
the counter sellers and that are currently logged as barmen
on the current device.
The bar case is really tricky,
as it doesn't use the usual django auth backend.
Barmen must not be logged in as regular users,
but as barmen, granting the session some special privileges,
even in the case where no regular user is logged in.
This is because of two reasons :
- we track the barmen connection, for logging,
statistics and dick contest purposes.
We want to know who was barman, where and when,
as barmen are accountable of what happens during their duty.
- multiple users must be able to log on the same device,
while keeping the session anonymous.
The bar PC must be a reliable way for any barman to click users,
but without requiring a user session.
Just imagine if someone who is superuser had to log in with
all its privileges on a device everyone can access.
# Available items
A counter can have multiple products.
A product can have multiple prices.
To select what the user can buy, we select
all the prices that can be applied to the current
customer, among the products of the counter.
The price selection logic is described in
[PriceQuerySet][counter.models.PriceQuerySet].
On top of that, some additional rules are applied,
because alcohol can be sold on counters :
- if the customer is minor (or has not filled its birthdate)
age restricted products are removed
([L.3342-1, Code de la santé publique](https://www.legifrance.gouv.fr/codes/article_lc/LEGIARTI000031927682))
- if any barman on the current device is minor,
age restricted products are also removed
([L.3336-4, Code de la santé publique](https://www.legifrance.gouv.fr/codes/article_lc/LEGIARTI000048654800))
The minor barman case is a little bit unclear, legally speaking,
as barmen are volunteers, but the law speaks only of employees and interns.
As such, we don't apply the law to its full extent.
It would be harsh for young students not to be able to
be barmen at the MDE, where no alcohol at all is sold during daytime.
However, we restrict items that can be sold as a token of good will.
""" """
model = Counter model = Counter
@@ -111,6 +172,19 @@ class CounterClick(
return redirect(obj) # Redirect to counter return redirect(obj) # Redirect to counter
self.prices = list(obj.get_prices_for(self.customer)) self.prices = list(obj.get_prices_for(self.customer))
if any(user.age < 18 for user in request.barmen):
# users without a birthdate cannot be sellers on counters,
# so the `user.age == 0` case shouldn't happen
filtered = [p for p in self.prices if p.product.limit_age < 18]
if len(filtered) != len(self.prices):
self.prices = filtered
messages.warning(
request,
_(
"A minor is barman on this on this device, "
"so you cannot currently sell alcohol."
),
)
return super().dispatch(request, *args, **kwargs) return super().dispatch(request, *args, **kwargs)
-1
View File
@@ -1 +0,0 @@
::: counter.views
+6
View File
@@ -0,0 +1,6 @@
::: counter.views.click
handler: python
options:
members:
- CounterClick
- RefillingCreateView
+1
View File
@@ -0,0 +1 @@
::: counter.views.home
+7
View File
@@ -0,0 +1,7 @@
::: counter.views.mixins
handler: python
options:
heading_level: 3
members:
- CounterTabsMixin
- CounterAdminTabsMixin
+5
View File
@@ -0,0 +1,5 @@
::: counter.views.admin
::: counter.views.cash
::: counter.views.eticket
::: counter.views.invoice
::: counter.views.student_card
+31 -5
View File
@@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-06 17:22+0100\n" "POT-Creation-Date: 2026-11-14 13:59+0100\n"
"PO-Revision-Date: 2016-07-18\n" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n" "Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@@ -251,6 +251,10 @@ msgstr "Inactif"
msgid "All clubs" msgid "All clubs"
msgstr "Tous les 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 #: club/models.py
msgid "slug name" msgid "slug name"
msgstr "nom slug" msgstr "nom slug"
@@ -340,6 +344,10 @@ msgid "A role cannot be in the presidency while not being in the board"
msgstr "" msgstr ""
"Un rôle ne peut pas appartenir à la présidence sans être dans le bureau" "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 #: club/models.py
#, python-format #, python-format
msgid "Role %(role)s cannot be placed below a member role" msgid "Role %(role)s cannot be placed below a member role"
@@ -3257,6 +3265,16 @@ msgstr ""
"Si vous souhaitez ajouter sur ce comptoir un produit qui n'appartient pas à " "Si vous souhaitez ajouter sur ce comptoir un produit qui n'appartient pas à "
"votre club, vous devriez demander à un admin." "votre club, vous devriez demander à un admin."
#: counter/forms.py
#, python-format
msgid "%(user)s is banned."
msgstr "%(user)s est banni."
#: counter/forms.py
#, python-format
msgid "%(user)s has not filled its birthdate."
msgstr "%(user)s n'a pas renseigné sa date de naissance."
#: counter/forms.py #: counter/forms.py
#, python-format #, python-format
msgid "" msgid ""
@@ -4329,6 +4347,14 @@ msgstr "Nombre de chèque"
msgid "You cannot click users on this counter" msgid "You cannot click users on this counter"
msgstr "Vous ne pouvez pas cliquer des gens sur ce comptoir" msgstr "Vous ne pouvez pas cliquer des gens sur ce comptoir"
#: counter/views/click.py
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."
#: counter/views/eticket.py #: counter/views/eticket.py
msgid "people(s)" msgid "people(s)"
msgstr "personne(s)" msgstr "personne(s)"
@@ -5482,14 +5508,14 @@ msgstr "Photos de %(user_name)s"
msgid "Download all my pictures" msgid "Download all my pictures"
msgstr "Télécharger toutes mes photos" msgstr "Télécharger toutes mes photos"
#: sith/settings.py
msgid "English"
msgstr "Anglais"
#: sith/settings.py #: sith/settings.py
msgid "French" msgid "French"
msgstr "Français" msgstr "Français"
#: sith/settings.py
msgid "English"
msgstr "Anglais"
#: sith/settings.py #: sith/settings.py
msgid "TC" msgid "TC"
msgstr "TC" msgstr "TC"
+5 -1
View File
@@ -113,7 +113,11 @@ nav:
- reference/core/auth.md - reference/core/auth.md
- counter: - counter:
- reference/counter/models.md - reference/counter/models.md
- reference/counter/views.md - Views:
- reference/counter/views/home.md
- reference/counter/views/click.md
- reference/counter/views/mixins.md
- reference/counter/views/others.md
- reference/counter/schemas.md - reference/counter/schemas.md
- eboutic: - eboutic:
- reference/eboutic/models.md - reference/eboutic/models.md
+1
View File
@@ -52,6 +52,7 @@ dependencies = [
"celery[redis]>=5.6.3,<7", "celery[redis]>=5.6.3,<7",
"django-celery-results>=2.6.0,<3", "django-celery-results>=2.6.0,<3",
"django-celery-beat>=2.9.0,<3", "django-celery-beat>=2.9.0,<3",
"django-modeltranslation>=0.20.6",
] ]
[project.urls] [project.urls]
+22 -5
View File
@@ -8,7 +8,10 @@ from django.utils.timezone import localtime
from model_bakery import baker from model_bakery import baker
from pytest_django.asserts import assertRedirects from pytest_django.asserts import assertRedirects
from core.baker_recipes import subscriber_user
from core.models import BanGroup, User, UserBan from core.models import BanGroup, User, UserBan
from counter.models import Counter
from sith import settings
if TYPE_CHECKING: if TYPE_CHECKING:
from django.test import Client from django.test import Client
@@ -33,11 +36,7 @@ def test_ban_user(client: Client, operator: User, expires_at: datetime):
client.force_login(operator) client.force_login(operator)
user = baker.make(User) user = baker.make(User)
ban_group = BanGroup.objects.first() ban_group = BanGroup.objects.first()
data = { data = {"user": user.id, "ban_group": ban_group.id, "reason": "Being naughty"}
"user": user.id,
"ban_group": ban_group.id,
"reason": "Being naughty",
}
if expires_at is not None: if expires_at is not None:
data["expires_at"] = expires_at.strftime("%Y-%m-%d %H:%M") data["expires_at"] = expires_at.strftime("%Y-%m-%d %H:%M")
response = client.post(reverse("rootplace:ban_create"), data) response = client.post(reverse("rootplace:ban_create"), data)
@@ -49,6 +48,24 @@ def test_ban_user(client: Client, operator: User, expires_at: datetime):
assert bans[0].ban_group == ban_group assert bans[0].ban_group == ban_group
@pytest.mark.django_db
def test_ban_counter_ends_barmanship():
user = subscriber_user.make()
counter = baker.make(Counter)
counter.sellers.add(user, through_defaults={"is_regular": True})
UserBan.objects.create(
user=user,
ban_group_id=settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
reason="ban comptoir",
)
# check that we did effectively delete the barmanship
# and not the bar itself (better safe than sorry)
assert Counter.objects.filter(id=counter.id).exists()
assert not user.counters.exists()
@pytest.mark.django_db @pytest.mark.django_db
def test_remove_ban(client: Client, operator: User): def test_remove_ban(client: Client, operator: User):
client.force_login(operator) client.force_login(operator)
+2 -1
View File
@@ -103,6 +103,7 @@ DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
SITE_ID = 4000 SITE_ID = 4000
INSTALLED_APPS = ( INSTALLED_APPS = (
"modeltranslation",
"django.contrib.admin", "django.contrib.admin",
"django.contrib.auth", "django.contrib.auth",
"django.contrib.contenttypes", "django.contrib.contenttypes",
@@ -285,7 +286,7 @@ LOGGING = {
LANGUAGE_CODE = "fr-FR" LANGUAGE_CODE = "fr-FR"
LANGUAGES = [("en", _("English")), ("fr", _("French"))] LANGUAGES = [("fr", _("French")), ("en", _("English"))]
TIME_ZONE = "Europe/Paris" TIME_ZONE = "Europe/Paris"
Generated
+15
View File
@@ -703,6 +703,19 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/f1/ae/63083bf0614a80857e264b9d3ae16af2e2eff7372da6e249abec7919cb0b/django_jinja-2.11.0-py3-none-any.whl", hash = "sha256:cc4c72246a6e346aa0574e0c56c3e534c1a20ef47b8476f05d7287781f69a0a9", size = 23748, upload-time = "2023-09-03T21:20:43.482Z" }, { url = "https://files.pythonhosted.org/packages/f1/ae/63083bf0614a80857e264b9d3ae16af2e2eff7372da6e249abec7919cb0b/django_jinja-2.11.0-py3-none-any.whl", hash = "sha256:cc4c72246a6e346aa0574e0c56c3e534c1a20ef47b8476f05d7287781f69a0a9", size = 23748, upload-time = "2023-09-03T21:20:43.482Z" },
] ]
[[package]]
name = "django-modeltranslation"
version = "0.20.6"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "django" },
{ name = "typing-extensions" },
]
sdist = { url = "https://files.pythonhosted.org/packages/a9/b7/049969e77ff4825836c78312b3b82bd58f94162ffe20bc46500f98391731/django_modeltranslation-0.20.6.tar.gz", hash = "sha256:29eb584f017206a0bea5e2a44ae5da514ad6ebf1e43536ff7fed7df67b795b0c", size = 82542, upload-time = "2026-09-07T12:03:24.651Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/ab/55/dfd72b735f50bb633409326311598d9a5bc861ee81ae3d137844ab903add/django_modeltranslation-0.20.6-py3-none-any.whl", hash = "sha256:913658af75510a4f71573441f267b5831a6034c524f917f337adc666a60fe724", size = 99206, upload-time = "2026-09-07T12:03:23.238Z" },
]
[[package]] [[package]]
name = "django-ninja" name = "django-ninja"
version = "1.7.3" version = "1.7.3"
@@ -2061,6 +2074,7 @@ dependencies = [
{ name = "django-haystack" }, { name = "django-haystack" },
{ name = "django-honeypot" }, { name = "django-honeypot" },
{ name = "django-jinja" }, { name = "django-jinja" },
{ name = "django-modeltranslation" },
{ name = "django-ninja" }, { name = "django-ninja" },
{ name = "django-ninja-extra" }, { name = "django-ninja-extra" },
{ name = "django-ordered-model" }, { name = "django-ordered-model" },
@@ -2129,6 +2143,7 @@ requires-dist = [
{ name = "django-haystack", specifier = ">=3.4.0,<4.0.0" }, { name = "django-haystack", specifier = ">=3.4.0,<4.0.0" },
{ name = "django-honeypot", specifier = ">=1.3.0,<2" }, { name = "django-honeypot", specifier = ">=1.3.0,<2" },
{ name = "django-jinja", specifier = ">=2.11.0,<3.0.0" }, { name = "django-jinja", specifier = ">=2.11.0,<3.0.0" },
{ name = "django-modeltranslation", specifier = ">=0.20.6" },
{ name = "django-ninja", specifier = ">=1.7.1,<2.0.0" }, { name = "django-ninja", specifier = ">=1.7.1,<2.0.0" },
{ name = "django-ninja-extra", specifier = ">=0.31.7" }, { name = "django-ninja-extra", specifier = ">=0.31.7" },
{ name = "django-ordered-model", specifier = ">=3.7.4,<4.0.0" }, { name = "django-ordered-model", specifier = ">=3.7.4,<4.0.0" },