1649: Ajouter wysiwyg pour la description d'une offre emploi
[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 tinymce import models as tinymce_models
7 from django.db import models
8 import settings
9 #from private_files import PrivateFileField
10
11 import datamaster_modeles.models as ref
12 from project.rh import models as rh
13
14 ### CONSTANTES
15 #NOTES
16 NOTE_MIN = 1
17 NOTE_RANGE = 1
18 NOTE_MAX = 11
19 NOTES = [(i, i) for i in range(NOTE_MIN, NOTE_MAX, NOTE_RANGE)]
20
21 # Abstracts
22 class Metadata(models.Model):
23 """Méta-données AUF.
24 Metadata.actif = flag remplaçant la suppression.
25 actif == False : objet réputé supprimé.
26 """
27 actif = models.BooleanField(default=True)
28 date_creation = models.DateField(auto_now_add=True)
29
30 class Meta:
31 abstract = True
32
33 class OffreEmploiManager(models.Manager):
34 def get_query_set(self):
35 fkeys = ('region',)
36 return super(OffreEmploiManager, self).get_query_set().select_related(*fkeys).all()
37
38 class ProxyPoste(rh.Poste):
39 class Meta:
40 proxy = True
41
42 def __unicode__(self):
43 return '%s [%s]' % (self.nom, self.id)
44
45 class OffreEmploi(Metadata):
46 objects = OffreEmploiManager()
47 nom = models.CharField(max_length=255)
48 resume = models.TextField(verbose_name="Résumé")
49 description = tinymce_models.HTMLField()
50 poste = models.ForeignKey(ProxyPoste, db_column='poste')
51 date_limite = models.DateField(verbose_name="Date limite")
52 region = models.ForeignKey(ref.Region, db_column='region',
53 verbose_name="Région")
54 bureau = models.ForeignKey(ref.Bureau, db_column='bureau', )
55 duree_affectation = models.CharField(max_length=255,
56 verbose_name="Durée de l'affectation")
57 renumeration = models.CharField(max_length=255,
58 verbose_name='Rénumération')
59 debut_affectation = models.DateField(verbose_name="Début de l'affectation")
60 lieu_affectation = models.ForeignKey(ref.Implantation,
61 db_column='implantation',
62 verbose_name="Lieu d'affectation")
63
64 class Meta:
65 verbose_name_plural = "offres d'emploi"
66
67 def __unicode__(self):
68 return '%s [%s]' % (self.nom, self.id)
69
70
71 ### CANDIDAT
72
73 GENRE_CHOICES = (
74 ('M', 'Homme'),
75 ('F', 'Femme'),
76 )
77 SITUATION_CHOICES = (
78 ('C', 'Célibataire'),
79 ('F', 'Fiancé'),
80 ('M', 'Marié'),
81 ('D', 'Divorcé'),
82 )
83 STATUT_CHOICES = (
84 ('NOUV', 'Nouveau'),
85 ('REF', 'Refusé'),
86 ('SEL', 'Sélectionné'),
87 ('ACC', 'Accepté'),
88 ('REC', 'Recevable'), # Trouver une lettre plus appropriée?
89 )
90
91 class Candidat(Metadata):
92 statut = models.CharField(max_length=4, choices=STATUT_CHOICES,
93 default='NOUV')
94 offre_emploi = models.ForeignKey('OffreEmploi', db_column='offre_emploi',
95 related_name='+')
96 prenom = models.CharField(max_length=255, verbose_name='Prénom', )
97 nom = models.CharField(max_length=255)
98 genre = models.CharField(max_length=1, choices=GENRE_CHOICES)
99 nationalite = models.ForeignKey(ref.Pays,
100 db_column='nationalite', related_name='+',
101 verbose_name='Nationalité')
102 date_naissance = models.DateField(verbose_name='Date de naissance')
103 situation_famille = models.CharField(max_length=1,
104 choices=SITUATION_CHOICES,
105 verbose_name='Situation familiale')
106 nombre_dependant = models.IntegerField(verbose_name='Nombre de dépendant')
107 niveau_diplome = models.CharField(max_length=255,
108 verbose_name='Niveau du diplôme')
109 employeur_actuel = models.CharField(max_length=255)
110 poste_actuel = models.CharField(max_length=255)
111 domaine_professionnel = models.CharField(max_length=255)
112 telephone = models.CharField(max_length=255, verbose_name='Téléphone', )
113 email = models.EmailField(max_length=255, verbose_name = 'Courriel', )
114
115 # Adresse
116 adresse = models.CharField(max_length=255)
117 ville = models.CharField(max_length=255)
118 etat_province = models.CharField(max_length=255,
119 verbose_name="État/Province")
120 code_postal = models.CharField(max_length=255, blank=True)
121 pays = models.ForeignKey(ref.Pays, db_column='pays',
122 related_name='+')
123
124 def __unicode__(self):
125 return '%s %s [%s]' % (self.prenom, self.nom, self.id)
126
127 ### PIECE CANDIDAT
128 # Upload de fichiers
129 storage_prive = FileSystemStorage(settings.PRIVE_MEDIA_ROOT,
130 base_url=settings.PRIVE_MEDIA_URL)
131
132 def candidat_piece_dispatch(instance, filename):
133 path = "offre_emploi/%s_%s/%s/%s_%s" % (instance.candidat.nom,
134 instance.candidat.prenom, instance.nom, instance.candidat.id,
135 filename)
136 return path
137
138 class CandidatPiece(models.Model):
139 candidat = models.ForeignKey(Candidat, db_column='candidat',
140 related_name='candidat_piece')
141 nom = models.CharField(max_length=255)
142 #path = PrivateFileField("file", upload_to=candidat_piece_dispatch)
143 path = models.FileField(verbose_name="Fichier",
144 upload_to=candidat_piece_dispatch,
145 storage=storage_prive, )
146
147 class Meta:
148 verbose_name = "pièce jointe"
149 verbose_name_plural = "pièces jointes"
150
151 def __unicode__(self):
152 return '%s' % (self.nom)
153
154 class UserProfile(models.Model):
155 user = models.ForeignKey("auth.User", unique=True,
156 verbose_name="permission")
157 candidats = models.ManyToManyField(Candidat, verbose_name='candidats',
158 blank=True, null=True,related_name="evaluateurs")
159 regions = models.ManyToManyField(ref.Region,
160 verbose_name="Régions", )
161
162 class Meta:
163 verbose_name = "évaluateur"
164
165 def __unicode__(self):
166 return '%s %s' % (self.user.first_name, self.user.last_name)
167
168 UserProfile.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
169
170 class CandidatEvaluation(models.Model):
171 candidat = models.ForeignKey(Candidat, db_column='candidat',
172 related_name='+',)
173 evaluateur = models.ForeignKey(UserProfile, db_column='evaluateur',
174 related_name='+', verbose_name='Évaluateur')
175 note = models.IntegerField(choices=NOTES, blank=True, null=True)
176 commentaire = models.TextField(null=True, blank=True)
177 date = models.DateField(auto_now_add=True)
178
179 class Meta:
180 verbose_name = 'évaluation du candidat'
181 verbose_name_plural = 'évaluations des candidats'
182
183 '''class CandidatLettre(models.Model):
184 candidat = models.ForeignKey(Candidat, db_column='candidat',
185 related_name='+',)
186 titre = models.CharField(max_length=255, )
187 texte = models.TextField(null=True, blank=True)
188
189 def __unicode__(self):
190 return '%s' % (self.titre)
191 '''
192