From f70eacfc37278f0d3535a1fb8d70f4a2087f8712 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sun, 27 Jun 2021 00:23:49 +0200 Subject: [PATCH] =?UTF-8?q?D=C3=A9place=20le=20choix=20de=20la=20promo=20d?= =?UTF-8?q?ans=20le=20formulaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kfet/forms.py | 19 ++++++++++++++++++- kfet/migrations/0079_auto_20210627_0022.py | 18 ++++++++++++++++++ kfet/models.py | 11 +---------- kfet/templates/kfet/left_account.html | 10 ++++++++-- 4 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 kfet/migrations/0079_auto_20210627_0022.py diff --git a/kfet/forms.py b/kfet/forms.py index 5cc9d83f..315f9165 100644 --- a/kfet/forms.py +++ b/kfet/forms.py @@ -1,4 +1,4 @@ -from datetime import timedelta +from datetime import date, timedelta from decimal import Decimal from django import forms @@ -50,7 +50,24 @@ class DateTimeWidget(forms.DateTimeInput): # ----- +def default_promo(): + now = date.today() + 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) +] + + class AccountForm(forms.ModelForm): + promo = forms.TypedChoiceField( + choices=PROMO_CHOICES, + coerce=int, + empty_value=None, + initial=default_promo(), + required=False, + ) # Surcharge pour passer data à Account.save() def save(self, data={}, *args, **kwargs): diff --git a/kfet/migrations/0079_auto_20210627_0022.py b/kfet/migrations/0079_auto_20210627_0022.py new file mode 100644 index 00000000..52900ed0 --- /dev/null +++ b/kfet/migrations/0079_auto_20210627_0022.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.17 on 2021-06-26 22:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("kfet", "0078_negative_end"), + ] + + operations = [ + migrations.AlterField( + model_name="account", + name="promo", + field=models.IntegerField(null=True), + ), + ] diff --git a/kfet/models.py b/kfet/models.py index 887d3701..8e9a6e42 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -1,5 +1,4 @@ import re -from datetime import date from django.contrib.auth.models import User from django.core.validators import RegexValidator @@ -19,11 +18,6 @@ from .config import kfet_config from .utils import to_ukf -def default_promo(): - now = date.today() - return now.month <= 8 and now.year - 1 or now.year - - class AccountManager(models.Manager): """Manager for Account Model.""" @@ -66,10 +60,7 @@ class Account(models.Model): is_frozen = models.BooleanField("est gelé", default=False) created_at = models.DateTimeField(default=timezone.now) # Optional - PROMO_CHOICES = [(r, r) for r in range(1980, date.today().year + 1)] - promo = models.IntegerField( - choices=PROMO_CHOICES, blank=True, null=True, default=default_promo() - ) + promo = models.IntegerField(null=True) nickname = models.CharField("surnom(s)", max_length=255, blank=True, default="") password = models.CharField( max_length=255, unique=True, blank=True, null=True, default=None diff --git a/kfet/templates/kfet/left_account.html b/kfet/templates/kfet/left_account.html index a68845ed..f4a3d4dc 100644 --- a/kfet/templates/kfet/left_account.html +++ b/kfet/templates/kfet/left_account.html @@ -35,7 +35,13 @@
  • {{ account.nickname }}
  • {% endif %}
  • {{ account.email|default:"Pas d'email!" }}
  • -
  • {{ account.departement }} {{ account.promo }}
  • +
  • + {% if account.promo %} + {{ account.departement }} {{ account.promo }} + {% else %} + Sans Promo + {% endif %} +
  • {% if account.is_cof %} \ No newline at end of file +