forked from DGNum/gestioCOF
Merge branch 'thubrecht/promo' into 'master'
Déplace le choix de la promo dans le formulaire Closes #215 See merge request klub-dev-ens/gestioCOF!501
This commit is contained in:
commit
df180d7446
4 changed files with 44 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
||||||
from datetime import timedelta
|
from datetime import date, timedelta
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
|
@ -50,7 +50,23 @@ class DateTimeWidget(forms.DateTimeInput):
|
||||||
# -----
|
# -----
|
||||||
|
|
||||||
|
|
||||||
|
def default_promo():
|
||||||
|
now = date.today()
|
||||||
|
return now.month <= 8 and now.year - 1 or now.year
|
||||||
|
|
||||||
|
|
||||||
|
def get_promo_choices():
|
||||||
|
return [("", "Sans promo")] + [(r, r) for r in range(1980, date.today().year + 1)]
|
||||||
|
|
||||||
|
|
||||||
class AccountForm(forms.ModelForm):
|
class AccountForm(forms.ModelForm):
|
||||||
|
promo = forms.TypedChoiceField(
|
||||||
|
choices=get_promo_choices,
|
||||||
|
coerce=int,
|
||||||
|
empty_value=None,
|
||||||
|
initial=default_promo,
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
# Surcharge pour passer data à Account.save()
|
# Surcharge pour passer data à Account.save()
|
||||||
def save(self, data={}, *args, **kwargs):
|
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
|
import re
|
||||||
from datetime import date
|
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
|
@ -19,11 +18,6 @@ from .config import kfet_config
|
||||||
from .utils import to_ukf
|
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):
|
class AccountManager(models.Manager):
|
||||||
"""Manager for Account Model."""
|
"""Manager for Account Model."""
|
||||||
|
|
||||||
|
@ -66,10 +60,7 @@ class Account(models.Model):
|
||||||
is_frozen = models.BooleanField("est gelé", default=False)
|
is_frozen = models.BooleanField("est gelé", default=False)
|
||||||
created_at = models.DateTimeField(default=timezone.now)
|
created_at = models.DateTimeField(default=timezone.now)
|
||||||
# Optional
|
# Optional
|
||||||
PROMO_CHOICES = [(r, r) for r in range(1980, date.today().year + 1)]
|
promo = models.IntegerField(null=True)
|
||||||
promo = models.IntegerField(
|
|
||||||
choices=PROMO_CHOICES, blank=True, null=True, default=default_promo()
|
|
||||||
)
|
|
||||||
nickname = models.CharField("surnom(s)", max_length=255, blank=True, default="")
|
nickname = models.CharField("surnom(s)", max_length=255, blank=True, default="")
|
||||||
password = models.CharField(
|
password = models.CharField(
|
||||||
max_length=255, unique=True, blank=True, null=True, default=None
|
max_length=255, unique=True, blank=True, null=True, default=None
|
||||||
|
|
|
@ -35,7 +35,13 @@
|
||||||
<li>{{ account.nickname }}</li>
|
<li>{{ account.nickname }}</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li>{{ account.email|default:"Pas d'email!" }}</li>
|
<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>
|
<li>
|
||||||
{% if account.is_cof %}
|
{% if account.is_cof %}
|
||||||
<span title="Réduction de {{ kfet_config.reduction_cof }} % sur tes commandes" data-toggle="tooltip"
|
<span title="Réduction de {{ kfet_config.reduction_cof }} % sur tes commandes" data-toggle="tooltip"
|
||||||
|
@ -112,4 +118,4 @@
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue