Déplace le choix de la promo dans le formulaire
This commit is contained in:
parent
7ca7f7298a
commit
f70eacfc37
4 changed files with 45 additions and 13 deletions
|
@ -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):
|
||||
|
|
18
kfet/migrations/0079_auto_20210627_0022.py
Normal file
18
kfet/migrations/0079_auto_20210627_0022.py
Normal file
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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
|
||||
|
|
|
@ -35,7 +35,13 @@
|
|||
<li>{{ account.nickname }}</li>
|
||||
{% endif %}
|
||||
<li>{{ account.email|default:"Pas d'email!" }}</li>
|
||||
<li>{{ account.departement }} {{ account.promo }}</li>
|
||||
<li>
|
||||
{% if account.promo %}
|
||||
{{ account.departement }} {{ account.promo }}
|
||||
{% else %}
|
||||
Sans Promo
|
||||
{% endif %}
|
||||
</li>
|
||||
<li>
|
||||
{% if account.is_cof %}
|
||||
<span title="Réduction de {{ kfet_config.reduction_cof }} % sur tes commandes" data-toggle="tooltip"
|
||||
|
|
Loading…
Reference in a new issue