2017-02-10 20:10:45 +01:00
|
|
|
from django.contrib.auth.models import User
|
2017-02-09 21:04:32 +01:00
|
|
|
from django.db import models
|
2017-02-10 20:10:45 +01:00
|
|
|
from django.dispatch import receiver
|
|
|
|
from django.db.models.signals import post_save, post_delete
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2017-02-09 21:04:32 +01:00
|
|
|
|
2017-02-10 20:10:45 +01:00
|
|
|
from cof.petits_cours_models import choices_length
|
|
|
|
|
|
|
|
OCCUPATION_CHOICES = (
|
|
|
|
('exterieur', _("Extérieur")),
|
|
|
|
('1A', _("1A")),
|
|
|
|
('2A', _("2A")),
|
|
|
|
('3A', _("3A")),
|
|
|
|
('4A', _("4A")),
|
|
|
|
('archicube', _("Archicube")),
|
|
|
|
('doctorant', _("Doctorant")),
|
|
|
|
('CST', _("CST")),
|
|
|
|
)
|
|
|
|
|
|
|
|
class Profile(models.Model):
|
|
|
|
user = models.OneToOneField(User, related_name="profile")
|
|
|
|
|
|
|
|
login_clipper = models.CharField("Login clipper", max_length=8, blank=True)
|
|
|
|
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)
|
|
|
|
comments = models.TextField(
|
|
|
|
"Commentaires visibles par l'utilisateur", blank=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Profil"
|
|
|
|
verbose_name_plural = "Profils"
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.user.username
|
|
|
|
|
|
|
|
@receiver(post_save, sender=User)
|
|
|
|
def create_user_profile(sender, instance, created, **kwargs):
|
|
|
|
if created:
|
|
|
|
Profile.objects.get_or_create(user=instance)
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_delete, sender=Profile)
|
|
|
|
def post_delete_user(sender, instance, *args, **kwargs):
|
|
|
|
instance.user.delete()
|