from datetime import date from os.path import splitext from django.contrib.auth import get_user_model from django.db import models from django.utils.translation import ugettext_lazy as _ from shared.utils import choices_length User = get_user_model() class BDSProfile(models.Model): OCCUPATION_CHOICES = ( ("EXT", "Extérieur"), ("1A", "1A"), ("2A", "2A"), ("3A", "3A"), ("4A", "4A"), ("MAG", "Magistérien"), ("ARC", "Archicube"), ("DOC", "Doctorant"), ("CST", "CST"), ("PER", "Personnel ENS"), ) TYPE_COTIZ_CHOICES = ( ("ETU", "Étudiant"), ("NOR", "Normalien"), ("EXT", "Extérieur"), ("ARC", "Archicube"), ) COTIZ_DURATION_CHOICES = ( ("ANN", "Année"), ("SE1", "Premier semestre"), ("SE2", "Deuxième semestre"), ("NO", "Aucune"), ) def get_certificate_filename(instance, filename): _, ext = splitext(filename) # récupère l'extension du fichier year = str(date.now().year) return "certifs/{username}-{year}.{ext}".format( username=instance.user.username, year=year, ext=ext ) user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="bds") phone = models.CharField(_("Téléphone"), max_length=20, blank=True) occupation = models.CharField( _("Occupation"), default="1A", choices=OCCUPATION_CHOICES, max_length=choices_length(OCCUPATION_CHOICES), ) departement = models.CharField(_("Département"), max_length=50, blank=True) birthdate = models.DateField( auto_now_add=False, auto_now=False, verbose_name="Date de naissance", blank=True, null=True, ) mails_bds = models.BooleanField(_("Recevoir les mails du BDS"), default=False) is_buro = models.BooleanField(_("Membre du Burô du BDS"), default=False) has_certificate = models.BooleanField(_("Certificat médical"), default=False) certificate_file = models.FileField( _("Fichier de certificat médical"), upload_to=get_certificate_filename, blank=True, ) ASPSL_number = models.CharField( "Numéro AS PSL", max_length=50, blank=True, null=True ) FFSU_number = models.CharField("Numéro FFSU", max_length=50, blank=True, null=True) cotisation_period = models.CharField( "Inscription", default="NO", choices=COTIZ_DURATION_CHOICES, max_length=3 ) registration_date = models.DateField( auto_now_add=True, verbose_name="Date d'inscription" ) class Meta: verbose_name = "Profil BDS" verbose_name_plural = "Profils BDS" def __str__(self): return self.user.username