Commit | Line | Data |
---|---|---|
932eef9a AJ |
1 | # -*- encoding: utf-8 -*- |
2 | from django.db import models | |
a2c6bb72 | 3 | from django.db.models import Q |
4248e029 | 4 | from datamaster_modeles.models import * |
2a36714f | 5 | #from auf_references_modeles.models import Thematique |
73cabd75 | 6 | from savoirs.models import Discipline |
932eef9a | 7 | |
13146d99 | 8 | GENRE_CHOICES = (('m', 'Homme'), ('f', 'Femme')) |
932eef9a AJ |
9 | class Personne(models.Model): |
10 | ||
11 | id = models.AutoField(primary_key=True) | |
12 | salutation = models.CharField(max_length=128, null = True, blank = True) | |
13 | nom = models.CharField(max_length=255) | |
14 | prenom = models.CharField(max_length=128, verbose_name = 'Prénom') | |
a4e383ac | 15 | courriel = models.EmailField(max_length=128, unique=True, verbose_name="Adresse électronique") |
932eef9a | 16 | fonction = models.CharField(max_length=128, null = True, blank = True) |
c18af6bd | 17 | date_naissance = models.DateField(null=True, blank=True) |
932eef9a AJ |
18 | sousfonction = models.CharField(max_length=128, null = True, blank = True, |
19 | verbose_name = 'Sous-fonction') | |
20 | mobile = models.CharField(max_length=32, null = True, blank = True, | |
21 | verbose_name = 'Numéro de téléphone portable ') | |
22 | genre = models.CharField(max_length=1, choices=GENRE_CHOICES) | |
23 | commentaire = models.TextField(verbose_name = 'Commentaires', null = True, | |
24 | blank = True) | |
25 | actif = models.BooleanField(editable = False) | |
26 | ||
27 | def __unicode__(self): | |
28 | return u"%s %s, %s" % (self.prenom, self.nom, self.courriel) | |
29 | ||
30 | class Meta: | |
31 | ordering = ["prenom", "nom"] | |
32 | ||
9af73c99 | 33 | class Utilisateur(Personne): |
e427f068 | 34 | password = models.CharField(max_length=35, verbose_name = 'Mot de passe') |
9af73c99 | 35 | |
a2c6bb72 EMS |
36 | class ChercheurManager(models.Manager): |
37 | ||
38 | def get_query_set(self): | |
39 | return ChercheurQuerySet(self.model) | |
40 | ||
41 | def search(self, text): | |
42 | return self.get_query_set().search(text) | |
43 | ||
3efbacbe EMS |
44 | def search_nom(self, nom): |
45 | return self.get_query_set().search_nom(nom) | |
46 | ||
a2c6bb72 EMS |
47 | class ChercheurQuerySet(models.query.QuerySet): |
48 | ||
49 | def search(self, text): | |
0b1ddc11 | 50 | q = None |
a2c6bb72 | 51 | for word in text.split(): |
0b1ddc11 EMS |
52 | part = (Q(personne__nom__icontains=word) | |
53 | Q(personne__prenom__icontains=word) | | |
54 | Q(theme_recherche__icontains=word) | | |
55 | Q(etablissement_autre_nom__icontains=word) | | |
56 | Q(etablissement__nom__icontains=word) | | |
57 | Q(etablissement__pays__nom__icontains=word) | | |
58 | Q(discipline__nom__icontains=word) | | |
59 | Q(publication1__titre__icontains=word) | | |
60 | Q(publication2__titre__icontains=word) | | |
61 | Q(publication3__titre__icontains=word) | | |
62 | Q(publication4__titre__icontains=word) | | |
ff442411 EMS |
63 | Q(these__titre__icontains=word) | |
64 | Q(groupes__nom__icontains=word)) | |
0b1ddc11 EMS |
65 | if q is None: |
66 | q = part | |
67 | else: | |
68 | q = q & part | |
69 | return self.filter(q).distinct() if q is not None else self | |
a2c6bb72 | 70 | |
3efbacbe EMS |
71 | def search_nom(self, nom): |
72 | q = None | |
73 | for word in nom.split(): | |
74 | part = Q(personne__nom__icontains=word) | Q(personne__prenom__icontains=word) | |
75 | if q is None: | |
76 | q = part | |
77 | else: | |
78 | q = q & part | |
79 | return self.filter(q) if q is not None else self | |
80 | ||
81 | ||
a4e383ac | 82 | STATUT_CHOICES = (('enseignant', 'Enseignant-chercheur dans un établissement'), ('etudiant', 'Étudiant-chercheur doctorant'), ('independant', 'Chercheur indépendant docteur')) |
932eef9a AJ |
83 | class Chercheur(models.Model): |
84 | id = models.AutoField(primary_key=True, db_column='id') | |
73cabd75 | 85 | personne = models.ForeignKey('Personne', db_column='personne') |
00755d9b AJ |
86 | nationalite = models.ForeignKey(Pays, null = True, db_column='nationalite', to_field='code', |
87 | verbose_name = 'Nationalité', related_name='nationalite') | |
5b9abc81 | 88 | #fonction = models.CharField(max_length=36, choices=FONCTION_CHOICES) |
a4e383ac | 89 | statut = models.CharField(max_length=36, choices=STATUT_CHOICES) |
00755d9b | 90 | diplome = models.CharField(max_length=255, null=True, |
7c596de2 | 91 | verbose_name = 'Diplôme le plus élevé') |
73cabd75 | 92 | etablissement = models.ForeignKey(Etablissement, db_column='etablissement', null=True, blank=True) |
00755d9b AJ |
93 | etablissement_autre_nom = models.CharField(max_length=255, null=True, blank=True, |
94 | verbose_name = 'Autre établissement') | |
95 | etablissement_autre_pays = models.ForeignKey(Pays, null = True, blank=True, db_column='etablissement_autre_pays', | |
96 | to_field='code', related_name='etablissement_autre_pays', | |
97 | verbose_name = 'Pays de l\'établissement') | |
7c596de2 | 98 | #Domaine |
00755d9b | 99 | thematique = models.ForeignKey(Thematique, db_column='thematique', null=True, verbose_name='Thematique') |
73cabd75 | 100 | |
a4e383ac | 101 | mots_cles = models.CharField(max_length=255, null=True, |
00755d9b | 102 | verbose_name='Mots-clés') |
a4e383ac AJ |
103 | discipline = models.ForeignKey(Discipline, db_column='discipline', null=True, |
104 | verbose_name='Discipline') | |
2a36714f AJ |
105 | theme_recherche = models.TextField(null=True, blank=True, verbose_name='Thème de recherche') |
106 | expertise = models.ForeignKey('Expertise', db_column='expertise', null=True, blank=True, related_name='expertise') | |
00755d9b | 107 | url_site_web = models.URLField(max_length=255, null=True, blank=True, |
54ab837c | 108 | verbose_name='Adresse site Internet') |
00755d9b AJ |
109 | url_blog = models.URLField(max_length=255, null=True, blank=True, |
110 | verbose_name='Blog') | |
111 | url_facebook = models.URLField(max_length=255, null=True, blank=True, | |
112 | verbose_name='Facebook') | |
113 | url_linkedin = models.URLField(max_length=255, null=True, blank=True, | |
114 | verbose_name='Linkedin') | |
115 | ||
73cabd75 | 116 | groupes = models.ManyToManyField('Groupe', through='ChercheurGroupe', blank=True, verbose_name = 'Domaines de recherche') |
932eef9a | 117 | |
00755d9b AJ |
118 | #Refactoring, mettre les publications comme etant des many2many; |
119 | publication1 = models.ForeignKey('Publication', db_column='publication1', null=True, blank=True, related_name='publication1', verbose_name = 'Publication 1') | |
120 | publication2 = models.ForeignKey('Publication', db_column='publication2', null=True, blank=True, related_name='publication2', verbose_name = 'Publication 2') | |
121 | publication3 = models.ForeignKey('Publication', db_column='publication3', null=True, blank=True, related_name='publication3', verbose_name = 'Publication 3') | |
122 | publication4 = models.ForeignKey('Publication', db_column='publication4', null=True, blank=True, related_name='publication4', verbose_name = 'Publication 4') | |
123 | ||
124 | these = models.ForeignKey('Publication', db_column='these', null=True, blank=True, related_name='These') | |
5ecd9e43 | 125 | |
00755d9b | 126 | #meta |
5ecd9e43 | 127 | actif = models.BooleanField(editable = False) |
00755d9b AJ |
128 | date_creation = models.DateField(auto_now_add=True, db_column='date_creation') |
129 | date_modification = models.DateField(auto_now=True, db_column='date_modification') | |
130 | ||
a2c6bb72 EMS |
131 | # Manager |
132 | objects = ChercheurManager() | |
133 | ||
588d6b93 | 134 | def __unicode__(self): |
221f4f6c | 135 | return u"%s %s" % (self.personne.nom.upper(), self.personne.prenom.title()) |
e427f068 | 136 | |
b57a7362 AJ |
137 | def statut_display(self): |
138 | for s in STATUT_CHOICES: | |
139 | if self.statut == s[0]: | |
140 | return s[1] | |
e427f068 | 141 | return "-" |
588d6b93 | 142 | |
00755d9b AJ |
143 | class Publication(models.Model): |
144 | id = models.AutoField(primary_key=True, db_column='id') | |
145 | titre = models.CharField(max_length=255, db_column='titre', null=True, blank=True, verbose_name = 'Titre') | |
146 | annee = models.IntegerField(db_column='annee', null=True, blank=True, verbose_name='Année de publication') | |
147 | revue = models.CharField(max_length=255, db_column='revue', null=True, blank=True, verbose_name = 'Revue') | |
148 | editeur = models.CharField(max_length=255, db_column='editeur', null=True, blank=True, verbose_name = 'Éditeur') | |
149 | lieu_edition = models.CharField(max_length=255, db_column='lieu_edition', null=True, blank=True, verbose_name = 'Lieu d\'édition') | |
150 | nb_pages = models.CharField(max_length=255, db_column='nb_pages', null=True, blank=True, verbose_name = 'Nombre de pages') | |
151 | url = models.CharField(max_length=255, db_column='url', null=True, blank=True, verbose_name = 'Lien vers la publication') | |
6befc7c9 AJ |
152 | #Migration des publications depuis l'ancien repertoire de chercheurs |
153 | publication_affichage = models.TextField(verbose_name = 'Publication', null = True, | |
154 | blank = True) | |
5ecd9e43 | 155 | actif = models.BooleanField(editable = False, db_column='actif') |
2a36714f AJ |
156 | |
157 | def __unicode__(self): | |
158 | return u"%s" % (self.titre) | |
159 | ||
160 | class Expertise(models.Model): | |
161 | id = models.AutoField(primary_key=True, db_column='id') | |
a4e383ac | 162 | nom = models.CharField(max_length=255, null=True, blank=True, verbose_name = 'Objet de la dernière expertise') |
2a36714f | 163 | date = models.DateField(db_column='date_expertise', null=True, blank=True) |
a4e383ac AJ |
164 | lieu = models.CharField(max_length=255, null=True, blank=True, verbose_name = 'Lieu de la dernière expertise') |
165 | organisme_demandeur = models.CharField(max_length=255, null=True, blank=True, verbose_name = 'Organisme commanditaire') | |
166 | organisme_demandeur_visible = models.BooleanField(verbose_name="Afficher l'organisme commanditaire") | |
2a36714f | 167 | actif = models.BooleanField(editable = False, db_column='actif') |
5b9abc81 AJ |
168 | |
169 | def __unicode__(self): | |
170 | return u"%s" % (self.nom) | |
2a36714f | 171 | |
932eef9a AJ |
172 | class Groupe(models.Model): |
173 | id = models.AutoField(primary_key=True, db_column='id') | |
174 | nom = models.CharField(max_length=255, db_column='nom') | |
00755d9b AJ |
175 | url = models.URLField(max_length=255, null=True, blank=True, |
176 | verbose_name='Site web') | |
177 | liste_diffusion = models.URLField(max_length=255, null=True, blank=True, | |
178 | verbose_name='Liste de diffusion') | |
179 | bulletin = models.URLField(max_length=255, null=True, blank=True, | |
180 | verbose_name='Bulletin') | |
932eef9a AJ |
181 | actif = models.BooleanField(editable = False, db_column='actif') |
182 | ||
183 | def __unicode__(self): | |
184 | return u"%s" % (self.nom) | |
185 | ||
186 | class ChercheurGroupe(models.Model): | |
73cabd75 AJ |
187 | id = models.AutoField(primary_key=True, db_column='id') |
188 | chercheur = models.ForeignKey('Chercheur', db_column='chercheur') | |
189 | groupe = models.ForeignKey('Groupe', db_column='groupe') | |
00755d9b AJ |
190 | date_inscription = models.DateField(auto_now_add=True) |
191 | date_modification = models.DateField(auto_now=True) | |
5ecd9e43 | 192 | actif = models.BooleanField(editable = False, db_column='actif') |
2a36714f AJ |
193 | |
194 | def __unicode__(self): | |
195 | return u"%s - %s" % (self.chercheur, self.groupe) |