1627: Modèles: s'assurer que les nom des modèles soient "human-readable"
[auf_rh_dae.git] / project / recrutement / models.py
1 # -=- encoding: utf-8 -=-
2
3 import datetime
4 from django.contrib.auth.models import User
5 from django.core.files.storage import FileSystemStorage
6 from django.db import models
7 import settings
8 #from private_files import PrivateFileField
9
10 import datamaster_modeles.models as ref
11 from project.rh import models as rh
12
13 ### CONSTANTES
14 #NOTES
15 NOTE_MIN = 1
16 NOTE_RANGE = 1
17 NOTE_MAX = 10
18 NOTES = [(i, i) for i in range(NOTE_MIN, NOTE_MAX, NOTE_RANGE)]
19
20 # Abstracts
21 class 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
33 class OffreEmploi(Metadata):
34 nom = models.CharField(max_length=255)
35 resume = models.TextField(verbose_name="Résumé")
36 description = models.TextField()
37 poste = models.ForeignKey(rh.Poste, db_column='poste')
38 date_limite = models.DateField(verbose_name="Date limite")
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"
45
46 def __unicode__(self):
47 return '%s [%s]' % (self.nom, self.id)
48
49
50 ### CANDIDAT
51
52 GENRE_CHOICES = (
53 ('M', 'Homme'),
54 ('F', 'Femme'),
55 )
56 SITUATION_CHOICES = (
57 ('C', 'Célibataire'),
58 ('F', 'Fiancé'),
59 ('M', 'Marié'),
60 ('D', 'Divorcé'),
61 )
62 STATUT_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
70 class Candidat(Metadata):
71 statut = models.CharField(max_length=4, choices=STATUT_CHOICES,
72 default='NOUV')
73 offre_emploi = models.ForeignKey('OffreEmploi', db_column='offre_emploi',
74 related_name='+')
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,
79 db_column='nationalite',
80 related_name='+')
81 date_naissance = models.DateField(verbose_name="Date de naissance")
82 situation_famille = models.CharField(max_length=1,
83 choices=SITUATION_CHOICES)
84 nombre_dependant = models.IntegerField(verbose_name="Nombre de dépendant")
85 niveau_diplome = models.CharField(max_length=255,
86 verbose_name="Niveau du diplôme")
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,
95 verbose_name="État/Province")
96 pays = models.ForeignKey(ref.Pays, db_column='pays',
97 related_name='+')
98
99 def __unicode__(self):
100 return '%s %s [%s]' % (self.prenom, self.nom, self.id)
101
102 ### PIECE CANDIDAT
103 # Upload de fichiers
104 storage_prive = FileSystemStorage(settings.PRIVE_MEDIA_ROOT,
105 base_url=settings.PRIVE_MEDIA_URL)
106
107 def 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
113 class CandidatPiece(models.Model):
114 candidat = models.ForeignKey(Candidat, db_column='candidat',
115 related_name='candidat_piece')
116 nom = models.CharField(max_length=255)
117 #path = PrivateFileField("file", upload_to=candidat_piece_dispatch)
118 path = models.FileField(verbose_name="Fichier",
119 upload_to=candidat_piece_dispatch,
120 storage=storage_prive, )
121
122 class Meta:
123 verbose_name = "pièce jointe du candidat"
124 verbose_name_plural = "pièces jointes des candidats"
125
126 def __unicode__(self):
127 return '%s' % (self.nom)
128
129 class UserProfile(models.Model):
130 user = models.ForeignKey("auth.User", unique=True,
131 verbose_name="Permission")
132 candidats = models.ManyToManyField(Candidat, verbose_name='Candidats',
133 blank=True, null=True,related_name="evaluateurs")
134 regions = models.ManyToManyField(ref.Region,
135 verbose_name="Régions", )
136
137 class Meta:
138 verbose_name = "permission"
139
140 def __unicode__(self):
141 return '%s %s' % (self.user.first_name, self.user.last_name)
142
143 UserProfile.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
144
145 class CandidatEvaluation(models.Model):
146 candidat = models.ForeignKey(Candidat, db_column='candidat',
147 related_name='+')
148 evaluateur = models.ForeignKey(UserProfile, db_column='evaluateur',
149 related_name='+', verbose_name="Évaluateur")
150 note = models.IntegerField(choices=NOTES, blank=True, null=True)
151 commentaire = models.TextField(null=True, blank=True)
152 date = models.DateField(auto_now_add=True)
153
154 class Meta:
155 verbose_name = "évaluation du candidat"
156 verbose_name_plural = "évaluations des candidats"