1627: Modèles: s'assurer que les nom des modèles soient "human-readable"
[auf_rh_dae.git] / project / recrutement / models.py
CommitLineData
df59fcab 1# -=- encoding: utf-8 -=-
2
3import datetime
b235ec9d 4from django.contrib.auth.models import User
4418c732 5from django.core.files.storage import FileSystemStorage
6f2d5d58 6from django.db import models
4418c732 7import settings
362a3534 8#from private_files import PrivateFileField
6f2d5d58 9
df59fcab 10import datamaster_modeles.models as ref
11from project.rh import models as rh
12
596fe324 13### CONSTANTES
14#NOTES
15NOTE_MIN = 1
16NOTE_RANGE = 1
17NOTE_MAX = 10
18NOTES = [(i, i) for i in range(NOTE_MIN, NOTE_MAX, NOTE_RANGE)]
19
df59fcab 20# Abstracts
21class Metadata(models.Model):
22 """Méta-données AUF.
23 Metadata.actif = flag remplaçant la suppression.
24 actif == False : objet réputé supprimé.
25 """
26 actif = models.BooleanField(default=True)
27 date_creation = models.DateField(auto_now_add=True)
28
29 class Meta:
30 abstract = True
31
32
33class OffreEmploi(Metadata):
34 nom = models.CharField(max_length=255)
b235ec9d 35 resume = models.TextField(verbose_name="Résumé")
df59fcab 36 description = models.TextField()
37 poste = models.ForeignKey(rh.Poste, db_column='poste')
38 date_limite = models.DateField(verbose_name="Date limite")
b235ec9d 39 region = models.ForeignKey(ref.Region, db_column='region',
40 verbose_name="Région")
41 bureau = models.ForeignKey(ref.Bureau, db_column='bureau', )
42
43 class Meta:
44 verbose_name_plural = "offres d'emploi"
4418c732 45
46 def __unicode__(self):
47 return '%s [%s]' % (self.nom, self.id)
df59fcab 48
49
50### CANDIDAT
51
52GENRE_CHOICES = (
53 ('M', 'Homme'),
54 ('F', 'Femme'),
55)
56SITUATION_CHOICES = (
57 ('C', 'Célibataire'),
58 ('F', 'Fiancé'),
59 ('M', 'Marié'),
60 ('D', 'Divorcé'),
61)
62STATUT_CHOICES = (
63 ('NOUV', 'Nouveau'),
64 ('REF', 'Refusé'),
65 ('SEL', 'Sélectionné'),
66 ('ACC', 'Accepté'),
67 ('REC', 'Recevable'), # Trouver une lettre plus appropriée?
68)
69
b235ec9d 70class Candidat(Metadata):
8ea41642 71 statut = models.CharField(max_length=4, choices=STATUT_CHOICES,
72 default='NOUV')
df59fcab 73 offre_emploi = models.ForeignKey('OffreEmploi', db_column='offre_emploi',
7f9e891e 74 related_name='+')
df59fcab 75 prenom = models.CharField(max_length=255)
76 nom = models.CharField(max_length=255)
77 genre = models.CharField(max_length=1, choices=GENRE_CHOICES)
78 nationalite = models.ForeignKey(ref.Pays,
4418c732 79 db_column='nationalite',
7f9e891e 80 related_name='+')
df59fcab 81 date_naissance = models.DateField(verbose_name="Date de naissance")
82 situation_famille = models.CharField(max_length=1,
4418c732 83 choices=SITUATION_CHOICES)
df59fcab 84 nombre_dependant = models.IntegerField(verbose_name="Nombre de dépendant")
85 niveau_diplome = models.CharField(max_length=255,
4418c732 86 verbose_name="Niveau du diplôme")
df59fcab 87 employeur_actuel = models.CharField(max_length=255)
88 poste_actuel = models.CharField(max_length=255)
89 domaine_professionnel = models.CharField(max_length=255)
90
91 # Adresse
92 adresse = models.CharField(max_length=255)
93 ville = models.CharField(max_length=255)
94 etat_province = models.CharField(max_length=255,
4418c732 95 verbose_name="État/Province")
df59fcab 96 pays = models.ForeignKey(ref.Pays, db_column='pays',
7f9e891e 97 related_name='+')
4418c732 98
99 def __unicode__(self):
100 return '%s %s [%s]' % (self.prenom, self.nom, self.id)
101
102### PIECE CANDIDAT
103# Upload de fichiers
104storage_prive = FileSystemStorage(settings.PRIVE_MEDIA_ROOT,
105 base_url=settings.PRIVE_MEDIA_URL)
106
107def candidat_piece_dispatch(instance, filename):
108 path = "offre_emploi/%s_%s/%s/%s_%s" % (instance.candidat.nom,
109 instance.candidat.prenom, instance.nom, instance.candidat.id,
110 filename)
111 return path
112
113class CandidatPiece(models.Model):
114 candidat = models.ForeignKey(Candidat, db_column='candidat',
2b3edf33 115 related_name='candidat_piece')
4418c732 116 nom = models.CharField(max_length=255)
362a3534 117 #path = PrivateFileField("file", upload_to=candidat_piece_dispatch)
f6749f29 118 path = models.FileField(verbose_name="Fichier",
119 upload_to=candidat_piece_dispatch,
2b3edf33 120 storage=storage_prive, )
4418c732 121
b235ec9d 122 class Meta:
123 verbose_name = "pièce jointe du candidat"
124 verbose_name_plural = "pièces jointes des candidats"
125
4418c732 126 def __unicode__(self):
127 return '%s' % (self.nom)
128
f6749f29 129class UserProfile(models.Model):
b235ec9d 130 user = models.ForeignKey("auth.User", unique=True,
131 verbose_name="Permission")
2adf9e0c 132 candidats = models.ManyToManyField(Candidat, verbose_name='Candidats',
133 blank=True, null=True,related_name="evaluateurs")
3b4bfad3 134 regions = models.ManyToManyField(ref.Region,
135 verbose_name="Régions", )
eb579d40 136
b235ec9d 137 class Meta:
138 verbose_name = "permission"
139
2adf9e0c 140 def __unicode__(self):
141 return '%s %s' % (self.user.first_name, self.user.last_name)
142
f6749f29 143UserProfile.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
4418c732 144
145class CandidatEvaluation(models.Model):
146 candidat = models.ForeignKey(Candidat, db_column='candidat',
7f9e891e 147 related_name='+')
f6749f29 148 evaluateur = models.ForeignKey(UserProfile, db_column='evaluateur',
b235ec9d 149 related_name='+', verbose_name="Évaluateur")
596fe324 150 note = models.IntegerField(choices=NOTES, blank=True, null=True)
362a3534 151 commentaire = models.TextField(null=True, blank=True)
4418c732 152 date = models.DateField(auto_now_add=True)
b235ec9d 153
154 class Meta:
155 verbose_name = "évaluation du candidat"
156 verbose_name_plural = "évaluations des candidats"