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 | ||
44 | class ChercheurQuerySet(models.query.QuerySet): | |
45 | ||
46 | def search(self, text): | |
47 | qs = self | |
48 | for word in text.split(): | |
49 | qs = qs.filter(Q(personne__nom__icontains=word) | | |
50 | Q(personne__prenom__icontains=word) | | |
5b9abc81 | 51 | Q(theme_recherche__icontains=word) | |
a2c6bb72 | 52 | Q(etablissement_autre_nom__icontains=word) | |
1c24a7d5 EMS |
53 | Q(etablissement__nom__icontains=word) | |
54 | Q(etablissement__pays__nom__icontains=word) | | |
55 | Q(discipline__nom__icontains=word) | | |
56 | Q(publication1__titre__icontains=word) | | |
57 | Q(publication2__titre__icontains=word) | | |
58 | Q(publication3__titre__icontains=word) | | |
59 | Q(publication4__titre__icontains=word) | | |
60 | Q(these__titre__icontains=word)).distinct() | |
a2c6bb72 EMS |
61 | return qs |
62 | ||
a4e383ac | 63 | STATUT_CHOICES = (('enseignant', 'Enseignant-chercheur dans un établissement'), ('etudiant', 'Étudiant-chercheur doctorant'), ('independant', 'Chercheur indépendant docteur')) |
932eef9a AJ |
64 | class Chercheur(models.Model): |
65 | id = models.AutoField(primary_key=True, db_column='id') | |
73cabd75 | 66 | personne = models.ForeignKey('Personne', db_column='personne') |
00755d9b AJ |
67 | nationalite = models.ForeignKey(Pays, null = True, db_column='nationalite', to_field='code', |
68 | verbose_name = 'Nationalité', related_name='nationalite') | |
5b9abc81 | 69 | #fonction = models.CharField(max_length=36, choices=FONCTION_CHOICES) |
a4e383ac | 70 | statut = models.CharField(max_length=36, choices=STATUT_CHOICES) |
00755d9b | 71 | diplome = models.CharField(max_length=255, null=True, |
7c596de2 | 72 | verbose_name = 'Diplôme le plus élevé') |
73cabd75 | 73 | etablissement = models.ForeignKey(Etablissement, db_column='etablissement', null=True, blank=True) |
00755d9b AJ |
74 | etablissement_autre_nom = models.CharField(max_length=255, null=True, blank=True, |
75 | verbose_name = 'Autre établissement') | |
76 | etablissement_autre_pays = models.ForeignKey(Pays, null = True, blank=True, db_column='etablissement_autre_pays', | |
77 | to_field='code', related_name='etablissement_autre_pays', | |
78 | verbose_name = 'Pays de l\'établissement') | |
7c596de2 | 79 | #Domaine |
00755d9b | 80 | thematique = models.ForeignKey(Thematique, db_column='thematique', null=True, verbose_name='Thematique') |
73cabd75 | 81 | |
a4e383ac | 82 | mots_cles = models.CharField(max_length=255, null=True, |
00755d9b | 83 | verbose_name='Mots-clés') |
a4e383ac AJ |
84 | discipline = models.ForeignKey(Discipline, db_column='discipline', null=True, |
85 | verbose_name='Discipline') | |
2a36714f AJ |
86 | theme_recherche = models.TextField(null=True, blank=True, verbose_name='Thème de recherche') |
87 | expertise = models.ForeignKey('Expertise', db_column='expertise', null=True, blank=True, related_name='expertise') | |
00755d9b | 88 | url_site_web = models.URLField(max_length=255, null=True, blank=True, |
54ab837c | 89 | verbose_name='Adresse site Internet') |
00755d9b AJ |
90 | url_blog = models.URLField(max_length=255, null=True, blank=True, |
91 | verbose_name='Blog') | |
92 | url_facebook = models.URLField(max_length=255, null=True, blank=True, | |
93 | verbose_name='Facebook') | |
94 | url_linkedin = models.URLField(max_length=255, null=True, blank=True, | |
95 | verbose_name='Linkedin') | |
96 | ||
73cabd75 | 97 | groupes = models.ManyToManyField('Groupe', through='ChercheurGroupe', blank=True, verbose_name = 'Domaines de recherche') |
932eef9a | 98 | |
00755d9b AJ |
99 | #Refactoring, mettre les publications comme etant des many2many; |
100 | publication1 = models.ForeignKey('Publication', db_column='publication1', null=True, blank=True, related_name='publication1', verbose_name = 'Publication 1') | |
101 | publication2 = models.ForeignKey('Publication', db_column='publication2', null=True, blank=True, related_name='publication2', verbose_name = 'Publication 2') | |
102 | publication3 = models.ForeignKey('Publication', db_column='publication3', null=True, blank=True, related_name='publication3', verbose_name = 'Publication 3') | |
103 | publication4 = models.ForeignKey('Publication', db_column='publication4', null=True, blank=True, related_name='publication4', verbose_name = 'Publication 4') | |
104 | ||
105 | these = models.ForeignKey('Publication', db_column='these', null=True, blank=True, related_name='These') | |
5ecd9e43 | 106 | |
00755d9b | 107 | #meta |
5ecd9e43 | 108 | actif = models.BooleanField(editable = False) |
00755d9b AJ |
109 | date_creation = models.DateField(auto_now_add=True, db_column='date_creation') |
110 | date_modification = models.DateField(auto_now=True, db_column='date_modification') | |
111 | ||
a2c6bb72 EMS |
112 | # Manager |
113 | objects = ChercheurManager() | |
114 | ||
588d6b93 | 115 | def __unicode__(self): |
221f4f6c | 116 | return u"%s %s" % (self.personne.nom.upper(), self.personne.prenom.title()) |
e427f068 AJ |
117 | |
118 | def fonction_display(self): | |
119 | for f in FONCTION_CHOICES: | |
120 | if self.fonction == f[0]: | |
121 | return f[1] | |
122 | return "-" | |
588d6b93 | 123 | |
00755d9b AJ |
124 | class Publication(models.Model): |
125 | id = models.AutoField(primary_key=True, db_column='id') | |
126 | titre = models.CharField(max_length=255, db_column='titre', null=True, blank=True, verbose_name = 'Titre') | |
127 | annee = models.IntegerField(db_column='annee', null=True, blank=True, verbose_name='Année de publication') | |
128 | revue = models.CharField(max_length=255, db_column='revue', null=True, blank=True, verbose_name = 'Revue') | |
129 | editeur = models.CharField(max_length=255, db_column='editeur', null=True, blank=True, verbose_name = 'Éditeur') | |
130 | lieu_edition = models.CharField(max_length=255, db_column='lieu_edition', null=True, blank=True, verbose_name = 'Lieu d\'édition') | |
131 | nb_pages = models.CharField(max_length=255, db_column='nb_pages', null=True, blank=True, verbose_name = 'Nombre de pages') | |
132 | url = models.CharField(max_length=255, db_column='url', null=True, blank=True, verbose_name = 'Lien vers la publication') | |
6befc7c9 AJ |
133 | #Migration des publications depuis l'ancien repertoire de chercheurs |
134 | publication_affichage = models.TextField(verbose_name = 'Publication', null = True, | |
135 | blank = True) | |
5ecd9e43 | 136 | actif = models.BooleanField(editable = False, db_column='actif') |
2a36714f AJ |
137 | |
138 | def __unicode__(self): | |
139 | return u"%s" % (self.titre) | |
140 | ||
141 | class Expertise(models.Model): | |
142 | id = models.AutoField(primary_key=True, db_column='id') | |
a4e383ac | 143 | nom = models.CharField(max_length=255, null=True, blank=True, verbose_name = 'Objet de la dernière expertise') |
2a36714f | 144 | date = models.DateField(db_column='date_expertise', null=True, blank=True) |
a4e383ac AJ |
145 | lieu = models.CharField(max_length=255, null=True, blank=True, verbose_name = 'Lieu de la dernière expertise') |
146 | organisme_demandeur = models.CharField(max_length=255, null=True, blank=True, verbose_name = 'Organisme commanditaire') | |
147 | organisme_demandeur_visible = models.BooleanField(verbose_name="Afficher l'organisme commanditaire") | |
2a36714f | 148 | actif = models.BooleanField(editable = False, db_column='actif') |
5b9abc81 AJ |
149 | |
150 | def __unicode__(self): | |
151 | return u"%s" % (self.nom) | |
2a36714f | 152 | |
932eef9a AJ |
153 | class Groupe(models.Model): |
154 | id = models.AutoField(primary_key=True, db_column='id') | |
155 | nom = models.CharField(max_length=255, db_column='nom') | |
00755d9b AJ |
156 | url = models.URLField(max_length=255, null=True, blank=True, |
157 | verbose_name='Site web') | |
158 | liste_diffusion = models.URLField(max_length=255, null=True, blank=True, | |
159 | verbose_name='Liste de diffusion') | |
160 | bulletin = models.URLField(max_length=255, null=True, blank=True, | |
161 | verbose_name='Bulletin') | |
932eef9a AJ |
162 | actif = models.BooleanField(editable = False, db_column='actif') |
163 | ||
164 | def __unicode__(self): | |
165 | return u"%s" % (self.nom) | |
166 | ||
167 | class ChercheurGroupe(models.Model): | |
73cabd75 AJ |
168 | id = models.AutoField(primary_key=True, db_column='id') |
169 | chercheur = models.ForeignKey('Chercheur', db_column='chercheur') | |
170 | groupe = models.ForeignKey('Groupe', db_column='groupe') | |
00755d9b AJ |
171 | date_inscription = models.DateField(auto_now_add=True) |
172 | date_modification = models.DateField(auto_now=True) | |
5ecd9e43 | 173 | actif = models.BooleanField(editable = False, db_column='actif') |
2a36714f AJ |
174 | |
175 | def __unicode__(self): | |
176 | return u"%s - %s" % (self.chercheur, self.groupe) |