Skip to content

Commit

Permalink
User.year field: no more limitation in the model but limit at current…
Browse files Browse the repository at this point in the history
… year + 1 in create and update forms.
  • Loading branch information
AlexandrePalo committed Nov 10, 2024
1 parent a8a0811 commit 9cb350d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ th {
@font-face {
font-family: 'Glyphicons Halflings';
src: url('/static/fonts/glyphicons-halflings-regular.eot');
src: url('/static/fonts/glyphicons-halflings-regular.eot#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
src: url('/static/fonts/glyphicons-halflings-regular.eot#iefix') format('embedded-opentype'), url('../../fonts/glyphicons-halflings-regular.woff2') format('woff2'), url('../../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}
.glyphicon {
position: relative;
Expand Down
6 changes: 3 additions & 3 deletions borgia/users/forms.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import datetime
from django import forms
from django.core.exceptions import ValidationError
from django.forms.widgets import PasswordInput

from users.models import User, get_list_year


class UserCreationCustomForm(forms.Form):
first_name = forms.CharField(label='Prenom', max_length=255)
last_name = forms.CharField(label='Nom', max_length=255)
Expand All @@ -14,7 +14,7 @@ class UserCreationCustomForm(forms.Form):
campus = forms.ChoiceField(
label='Tabagn\'s', choices=User.CAMPUS_CHOICES, required=False)
year = forms.ChoiceField(
label='Prom\'ss', choices=User.YEAR_CHOICES[::-1], required=True)
label='Prom\'ss', choices=tuple((year,year) for year in list(range(1953, datetime.datetime.now().year + 2))[::-1]), required=True) # +2 as last item is omitted
username = forms.CharField(label='Username', max_length=255)
is_external_member = forms.BooleanField(
label='Externe à l\'association', required=False)
Expand Down Expand Up @@ -42,7 +42,7 @@ class UserUpdateForm(forms.Form):
campus = forms.ChoiceField(
label='Tabagn\'s', choices=User.CAMPUS_CHOICES, required=False)
year = forms.ChoiceField(
label='Prom\'ss', choices=User.YEAR_CHOICES, required=False)
label='Prom\'ss', choices=tuple((year,year) for year in list(range(1953, datetime.datetime.now().year + 2))[::-1]), required=False) # +2 as last item is omitted

def __init__(self, **kwargs):
self.user = kwargs.pop('user')
Expand Down
18 changes: 18 additions & 0 deletions borgia/users/migrations/0003_auto_20241110_1157.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.28 on 2024-11-10 11:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0002_auto_20230423_1543'),
]

operations = [
migrations.AlterField(
model_name='user',
name='year',
field=models.IntegerField(blank=True, choices=[(1953, 1953), (1954, 1954), (1955, 1955), (1956, 1956), (1957, 1957), (1958, 1958), (1959, 1959), (1960, 1960), (1961, 1961), (1962, 1962), (1963, 1963), (1964, 1964), (1965, 1965), (1966, 1966), (1967, 1967), (1968, 1968), (1969, 1969), (1970, 1970), (1971, 1971), (1972, 1972), (1973, 1973), (1974, 1974), (1975, 1975), (1976, 1976), (1977, 1977), (1978, 1978), (1979, 1979), (1980, 1980), (1981, 1981), (1982, 1982), (1983, 1983), (1984, 1984), (1985, 1985), (1986, 1986), (1987, 1987), (1988, 1988), (1989, 1989), (1990, 1990), (1991, 1991), (1992, 1992), (1993, 1993), (1994, 1994), (1995, 1995), (1996, 1996), (1997, 1997), (1998, 1998), (1999, 1999), (2000, 2000), (2001, 2001), (2002, 2002), (2003, 2003), (2004, 2004), (2005, 2005), (2006, 2006), (2007, 2007), (2008, 2008), (2009, 2009), (2010, 2010), (2011, 2011), (2012, 2012), (2013, 2013), (2014, 2014), (2015, 2015), (2016, 2016), (2017, 2017), (2018, 2018), (2019, 2019), (2020, 2020), (2021, 2021), (2022, 2022), (2023, 2023), (2024, 2024)], null=True, verbose_name="Prom'ss"),
),
]
19 changes: 19 additions & 0 deletions borgia/users/migrations/0004_auto_20241110_1247.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.28 on 2024-11-10 12:47

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0003_auto_20241110_1157'),
]

operations = [
migrations.AlterField(
model_name='user',
name='year',
field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(1953)], verbose_name="Prom'ss"),
),
]
8 changes: 2 additions & 6 deletions borgia/users/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import datetime
import decimal
import itertools

from django.contrib.auth.models import AbstractUser
from django.core.validators import RegexValidator
from django.core.validators import RegexValidator, MinValueValidator
from django.db import models
from django.utils import timezone

Expand Down Expand Up @@ -63,9 +62,6 @@ class User(AbstractUser):
('KA', 'Ka'),
('KIN', 'Kin')
)
YEAR_CHOICES = []
for i in range(1953, datetime.datetime.now().year + 1):
YEAR_CHOICES.append((i, i))

THEME_CHOICES = (
('light', 'Light'),
Expand All @@ -79,7 +75,7 @@ class User(AbstractUser):
decimal_places=2)
virtual_balance = models.DecimalField('Solde prévisionnel', default=0, max_digits=9,
decimal_places=2)
year = models.IntegerField('Prom\'ss', choices=YEAR_CHOICES, blank=True,
year = models.IntegerField('Prom\'ss', validators=[MinValueValidator(1953)], blank=True,
null=True)
campus = models.CharField('Tabagn\'ss', choices=CAMPUS_CHOICES,
max_length=3, blank=True, null=True)
Expand Down

0 comments on commit 9cb350d

Please sign in to comment.