From 2d677b209338bb01a43b3a0e20bed37b5257db9c Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Thu, 1 Jul 2021 10:29:14 +0200 Subject: [PATCH] Utilise des callables pour les choix --- kfet/forms.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kfet/forms.py b/kfet/forms.py index 315f9165..8ab301a1 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -55,17 +55,16 @@ def default_promo(): return now.month <= 8 and now.year - 1 or now.year -PROMO_CHOICES = [("", "Sans promo")] + [ - (r, r) for r in range(1980, date.today().year + 1) -] +def get_promo_choices(): + return [("", "Sans promo")] + [(r, r) for r in range(1980, date.today().year + 1)] class AccountForm(forms.ModelForm): promo = forms.TypedChoiceField( - choices=PROMO_CHOICES, + choices=get_promo_choices, coerce=int, empty_value=None, - initial=default_promo(), + initial=default_promo, required=False, )