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(): |
82f25472 EMS |
52 | matching_pays = list(Pays.objects.filter(Q(nom__icontains=word) | Q(region__nom__icontains=word)).values_list('pk', flat=True)) |
53 | matching_etablissements = list(Etablissement.objects.filter(Q(nom__icontains=word) | Q(pays__in=matching_pays)).values_list('pk', flat=True)) | |
54 | matching_publications = list(Publication.objects.filter(titre__icontains=word).values_list('pk', flat=True)) | |
55 | matching_groupes = list(Groupe.objects.filter(nom__icontains=word).values_list('pk', flat=True)) | |
56 | matching_disciplines = list(Discipline.objects.filter(nom__icontains=word).values_list('pk', flat=True)) | |
0b1ddc11 EMS |
57 | part = (Q(personne__nom__icontains=word) | |
58 | Q(personne__prenom__icontains=word) | | |
59 | Q(theme_recherche__icontains=word) | | |
82f25472 | 60 | Q(etablissement__in=matching_etablissements) | |
0b1ddc11 | 61 | Q(etablissement_autre_nom__icontains=word) | |
82f25472 EMS |
62 | Q(etablissement_autre_pays__in=matching_pays) | |
63 | Q(discipline__in=matching_disciplines) | | |
64 | Q(publication1__in=matching_publications) | | |
65 | Q(publication2__in=matching_publications) | | |
66 | Q(publication3__in=matching_publications) | | |
67 | Q(publication4__in=matching_publications) | | |
68 | Q(these__in=matching_publications) | | |
69 | Q(groupes__in=matching_groupes)) | |
0b1ddc11 EMS |
70 | if q is None: |
71 | q = part | |
72 | else: | |
73 | q = q & part | |
74 | return self.filter(q).distinct() if q is not None else self | |
a2c6bb72 | 75 | |
3efbacbe EMS |
76 | def search_nom(self, nom): |
77 | q = None | |
78 | for word in nom.split(): | |
79 | part = Q(personne__nom__icontains=word) | Q(personne__prenom__icontains=word) | |
80 | if q is None: | |
81 | q = part | |
82 | else: | |
83 | q = q & part | |
84 | return self.filter(q) if q is not None else self | |
85 | ||
86 | ||
a4e383ac | 87 | STATUT_CHOICES = (('enseignant', 'Enseignant-chercheur dans un établissement'), ('etudiant', 'Étudiant-chercheur doctorant'), ('independant', 'Chercheur indépendant docteur')) |
932eef9a AJ |
88 | class Chercheur(models.Model): |
89 | id = models.AutoField(primary_key=True, db_column='id') | |
73cabd75 | 90 | personne = models.ForeignKey('Personne', db_column='personne') |
00755d9b AJ |
91 | nationalite = models.ForeignKey(Pays, null = True, db_column='nationalite', to_field='code', |
92 | verbose_name = 'Nationalité', related_name='nationalite') | |
5b9abc81 | 93 | #fonction = models.CharField(max_length=36, choices=FONCTION_CHOICES) |
a4e383ac | 94 | statut = models.CharField(max_length=36, choices=STATUT_CHOICES) |
00755d9b | 95 | diplome = models.CharField(max_length=255, null=True, |
7c596de2 | 96 | verbose_name = 'Diplôme le plus élevé') |
73cabd75 | 97 | etablissement = models.ForeignKey(Etablissement, db_column='etablissement', null=True, blank=True) |
00755d9b AJ |
98 | etablissement_autre_nom = models.CharField(max_length=255, null=True, blank=True, |
99 | verbose_name = 'Autre établissement') | |
100 | etablissement_autre_pays = models.ForeignKey(Pays, null = True, blank=True, db_column='etablissement_autre_pays', | |
101 | to_field='code', related_name='etablissement_autre_pays', | |
102 | verbose_name = 'Pays de l\'établissement') | |
7c596de2 | 103 | #Domaine |
00755d9b | 104 | thematique = models.ForeignKey(Thematique, db_column='thematique', null=True, verbose_name='Thematique') |
73cabd75 | 105 | |
a4e383ac | 106 | mots_cles = models.CharField(max_length=255, null=True, |
00755d9b | 107 | verbose_name='Mots-clés') |
a4e383ac AJ |
108 | discipline = models.ForeignKey(Discipline, db_column='discipline', null=True, |
109 | verbose_name='Discipline') | |
2a36714f AJ |
110 | theme_recherche = models.TextField(null=True, blank=True, verbose_name='Thème de recherche') |
111 | expertise = models.ForeignKey('Expertise', db_column='expertise', null=True, blank=True, related_name='expertise') | |
00755d9b | 112 | url_site_web = models.URLField(max_length=255, null=True, blank=True, |
54ab837c | 113 | verbose_name='Adresse site Internet') |
00755d9b AJ |
114 | url_blog = models.URLField(max_length=255, null=True, blank=True, |
115 | verbose_name='Blog') | |
3c576696 EMS |
116 | url_reseau_social = models.URLField( |
117 | max_length=255, null=True, blank=True, verbose_name='Réseau social', | |
118 | help_text=u"Vous pouvez indiquer ici l'adresse de votre page personnelle dans votre réseau social préféré (e.g. Facebook, LinkedIn, Twitter, Identica, ...)" | |
119 | ) | |
00755d9b | 120 | |
e4d01d1d | 121 | groupes = models.ManyToManyField('Groupe', through='ChercheurGroupe', blank=True, verbose_name='Domaines de recherche') |
932eef9a | 122 | |
00755d9b AJ |
123 | #Refactoring, mettre les publications comme etant des many2many; |
124 | publication1 = models.ForeignKey('Publication', db_column='publication1', null=True, blank=True, related_name='publication1', verbose_name = 'Publication 1') | |
125 | publication2 = models.ForeignKey('Publication', db_column='publication2', null=True, blank=True, related_name='publication2', verbose_name = 'Publication 2') | |
126 | publication3 = models.ForeignKey('Publication', db_column='publication3', null=True, blank=True, related_name='publication3', verbose_name = 'Publication 3') | |
127 | publication4 = models.ForeignKey('Publication', db_column='publication4', null=True, blank=True, related_name='publication4', verbose_name = 'Publication 4') | |
128 | ||
129 | these = models.ForeignKey('Publication', db_column='these', null=True, blank=True, related_name='These') | |
5ecd9e43 | 130 | |
a7b16ec9 EMS |
131 | # Activités en francophonie |
132 | membre_instance_auf = models.BooleanField(default=False, verbose_name="est ou a déjà été membre d'une instance de l'AUF") | |
133 | membre_instance_auf_dates = models.CharField(max_length=255, blank=True, verbose_name="dates") | |
134 | expert_oif = models.BooleanField(default=False, verbose_name="est un expert de l'OIF") | |
135 | membre_fipf = models.BooleanField(default=False, verbose_name="est membre de la FIPF") | |
136 | membre_fipf_association = models.CharField(max_length=255, blank=True, verbose_name="nom de l'association") | |
137 | ||
00755d9b | 138 | #meta |
5ecd9e43 | 139 | actif = models.BooleanField(editable = False) |
00755d9b AJ |
140 | date_creation = models.DateField(auto_now_add=True, db_column='date_creation') |
141 | date_modification = models.DateField(auto_now=True, db_column='date_modification') | |
142 | ||
a2c6bb72 EMS |
143 | # Manager |
144 | objects = ChercheurManager() | |
145 | ||
588d6b93 | 146 | def __unicode__(self): |
221f4f6c | 147 | return u"%s %s" % (self.personne.nom.upper(), self.personne.prenom.title()) |
e427f068 | 148 | |
b57a7362 AJ |
149 | def statut_display(self): |
150 | for s in STATUT_CHOICES: | |
151 | if self.statut == s[0]: | |
152 | return s[1] | |
e427f068 | 153 | return "-" |
588d6b93 | 154 | |
e4d01d1d EMS |
155 | @property |
156 | def etablissement_display(self): | |
157 | if self.etablissement: | |
158 | return self.etablissement.nom + ', ' + self.etablissement.pays.nom | |
159 | else: | |
160 | return self.etablissement_autre_nom + ', ' + self.etablissement_autre_pays | |
161 | ||
00755d9b AJ |
162 | class Publication(models.Model): |
163 | id = models.AutoField(primary_key=True, db_column='id') | |
164 | titre = models.CharField(max_length=255, db_column='titre', null=True, blank=True, verbose_name = 'Titre') | |
165 | annee = models.IntegerField(db_column='annee', null=True, blank=True, verbose_name='Année de publication') | |
166 | revue = models.CharField(max_length=255, db_column='revue', null=True, blank=True, verbose_name = 'Revue') | |
167 | editeur = models.CharField(max_length=255, db_column='editeur', null=True, blank=True, verbose_name = 'Éditeur') | |
168 | lieu_edition = models.CharField(max_length=255, db_column='lieu_edition', null=True, blank=True, verbose_name = 'Lieu d\'édition') | |
169 | nb_pages = models.CharField(max_length=255, db_column='nb_pages', null=True, blank=True, verbose_name = 'Nombre de pages') | |
170 | url = models.CharField(max_length=255, db_column='url', null=True, blank=True, verbose_name = 'Lien vers la publication') | |
6befc7c9 AJ |
171 | #Migration des publications depuis l'ancien repertoire de chercheurs |
172 | publication_affichage = models.TextField(verbose_name = 'Publication', null = True, | |
173 | blank = True) | |
5ecd9e43 | 174 | actif = models.BooleanField(editable = False, db_column='actif') |
2a36714f AJ |
175 | |
176 | def __unicode__(self): | |
177 | return u"%s" % (self.titre) | |
178 | ||
179 | class Expertise(models.Model): | |
180 | id = models.AutoField(primary_key=True, db_column='id') | |
a4e383ac | 181 | nom = models.CharField(max_length=255, null=True, blank=True, verbose_name = 'Objet de la dernière expertise') |
2a36714f | 182 | date = models.DateField(db_column='date_expertise', null=True, blank=True) |
a4e383ac AJ |
183 | lieu = models.CharField(max_length=255, null=True, blank=True, verbose_name = 'Lieu de la dernière expertise') |
184 | organisme_demandeur = models.CharField(max_length=255, null=True, blank=True, verbose_name = 'Organisme commanditaire') | |
185 | organisme_demandeur_visible = models.BooleanField(verbose_name="Afficher l'organisme commanditaire") | |
2a36714f | 186 | actif = models.BooleanField(editable = False, db_column='actif') |
5b9abc81 AJ |
187 | |
188 | def __unicode__(self): | |
189 | return u"%s" % (self.nom) | |
2a36714f | 190 | |
932eef9a AJ |
191 | class Groupe(models.Model): |
192 | id = models.AutoField(primary_key=True, db_column='id') | |
193 | nom = models.CharField(max_length=255, db_column='nom') | |
00755d9b AJ |
194 | url = models.URLField(max_length=255, null=True, blank=True, |
195 | verbose_name='Site web') | |
196 | liste_diffusion = models.URLField(max_length=255, null=True, blank=True, | |
197 | verbose_name='Liste de diffusion') | |
198 | bulletin = models.URLField(max_length=255, null=True, blank=True, | |
199 | verbose_name='Bulletin') | |
932eef9a AJ |
200 | actif = models.BooleanField(editable = False, db_column='actif') |
201 | ||
202 | def __unicode__(self): | |
203 | return u"%s" % (self.nom) | |
204 | ||
205 | class ChercheurGroupe(models.Model): | |
73cabd75 AJ |
206 | id = models.AutoField(primary_key=True, db_column='id') |
207 | chercheur = models.ForeignKey('Chercheur', db_column='chercheur') | |
208 | groupe = models.ForeignKey('Groupe', db_column='groupe') | |
00755d9b AJ |
209 | date_inscription = models.DateField(auto_now_add=True) |
210 | date_modification = models.DateField(auto_now=True) | |
5ecd9e43 | 211 | actif = models.BooleanField(editable = False, db_column='actif') |
2a36714f AJ |
212 | |
213 | def __unicode__(self): | |
214 | return u"%s - %s" % (self.chercheur, self.groupe) |