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