21462f815ffe4a268f629dcd8821f47b02ad1858
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / chercheurs / models.py
1 # -*- encoding: utf-8 -*-
2 from django.db import models
3 from django.db.models import Q
4 from datamaster_modeles.models import *
5 from auf_references_modeles.models import Thematique
6 from savoirs.models import Discipline
7
8 GENRE_CHOICES = (('m', 'Homme'), ('f', 'Femme'))
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')
15 courriel = models.EmailField(max_length=128, unique=True)
16 fonction = models.CharField(max_length=128, null = True, blank = True)
17 date_naissance = models.DateField(null=True, blank=True)
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
33 class Utilisateur(Personne):
34 password = models.CharField(max_length=35, verbose_name = 'Mot de passe')
35
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
56 FONCTION_CHOICES = (('Professeur', 'Professeur'), ('Chercheur', 'Chercheur'), ('Chercheur_independant', 'Chercheur indépendant'), ('Doctorant', 'Doctorant'))
57 class Chercheur(models.Model):
58 id = models.AutoField(primary_key=True, db_column='id')
59 personne = models.ForeignKey('Personne', db_column='personne')
60 nationalite = models.ForeignKey(Pays, null = True, db_column='nationalite', to_field='code',
61 verbose_name = 'Nationalité', related_name='nationalite')
62 fonction = models.CharField(max_length=36, choices=FONCTION_CHOICES)
63 diplome = models.CharField(max_length=255, null=True,
64 verbose_name = 'Diplôme le plus élevé')
65 etablissement = models.ForeignKey(Etablissement, db_column='etablissement', null=True, blank=True)
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')
71 #Domaine
72 thematique = models.ForeignKey(Thematique, db_column='thematique', null=True, verbose_name='Thematique')
73
74 mots_cles = models.CharField(max_length=255, null=True, blank=True,
75 verbose_name='Mots-clés')
76 discipline = models.ForeignKey(Discipline, db_column='discipline', null=True, blank=True,
77 verbose_name='Champ disciplinaire')
78 expertise = models.TextField(null=True, blank=True, verbose_name='Domaine d\'expertise et thèmes de recherche')
79 url_site_web = models.URLField(max_length=255, null=True, blank=True,
80 verbose_name='Adresse site Internet')
81 url_blog = models.URLField(max_length=255, null=True, blank=True,
82 verbose_name='Blog')
83 url_facebook = models.URLField(max_length=255, null=True, blank=True,
84 verbose_name='Facebook')
85 url_linkedin = models.URLField(max_length=255, null=True, blank=True,
86 verbose_name='Linkedin')
87
88 groupes = models.ManyToManyField('Groupe', through='ChercheurGroupe', blank=True, verbose_name = 'Domaines de recherche')
89
90 #Refactoring, mettre les publications comme etant des many2many;
91 publication1 = models.ForeignKey('Publication', db_column='publication1', null=True, blank=True, related_name='publication1', verbose_name = 'Publication 1')
92 publication2 = models.ForeignKey('Publication', db_column='publication2', null=True, blank=True, related_name='publication2', verbose_name = 'Publication 2')
93 publication3 = models.ForeignKey('Publication', db_column='publication3', null=True, blank=True, related_name='publication3', verbose_name = 'Publication 3')
94 publication4 = models.ForeignKey('Publication', db_column='publication4', null=True, blank=True, related_name='publication4', verbose_name = 'Publication 4')
95
96 these = models.ForeignKey('Publication', db_column='these', null=True, blank=True, related_name='These')
97
98 #meta
99 actif = models.BooleanField(editable = False)
100 date_creation = models.DateField(auto_now_add=True, db_column='date_creation')
101 date_modification = models.DateField(auto_now=True, db_column='date_modification')
102
103 # Manager
104 objects = ChercheurManager()
105
106 def __unicode__(self):
107 return u"%s %s" % (self.personne.nom.upper(), self.personne.prenom.title())
108
109 def fonction_display(self):
110 for f in FONCTION_CHOICES:
111 if self.fonction == f[0]:
112 return f[1]
113 return "-"
114
115 class Publication(models.Model):
116 id = models.AutoField(primary_key=True, db_column='id')
117 titre = models.CharField(max_length=255, db_column='titre', null=True, blank=True, verbose_name = 'Titre')
118 annee = models.IntegerField(db_column='annee', null=True, blank=True, verbose_name='Année de publication')
119 revue = models.CharField(max_length=255, db_column='revue', null=True, blank=True, verbose_name = 'Revue')
120 editeur = models.CharField(max_length=255, db_column='editeur', null=True, blank=True, verbose_name = 'Éditeur')
121 lieu_edition = models.CharField(max_length=255, db_column='lieu_edition', null=True, blank=True, verbose_name = 'Lieu d\'édition')
122 nb_pages = models.CharField(max_length=255, db_column='nb_pages', null=True, blank=True, verbose_name = 'Nombre de pages')
123 url = models.CharField(max_length=255, db_column='url', null=True, blank=True, verbose_name = 'Lien vers la publication')
124 #Migration des publications depuis l'ancien repertoire de chercheurs
125 publication_affichage = models.TextField(verbose_name = 'Publication', null = True,
126 blank = True)
127 actif = models.BooleanField(editable = False, db_column='actif')
128
129 class Groupe(models.Model):
130 id = models.AutoField(primary_key=True, db_column='id')
131 nom = models.CharField(max_length=255, db_column='nom')
132 url = models.URLField(max_length=255, null=True, blank=True,
133 verbose_name='Site web')
134 liste_diffusion = models.URLField(max_length=255, null=True, blank=True,
135 verbose_name='Liste de diffusion')
136 bulletin = models.URLField(max_length=255, null=True, blank=True,
137 verbose_name='Bulletin')
138 actif = models.BooleanField(editable = False, db_column='actif')
139
140 def __unicode__(self):
141 return u"%s" % (self.nom)
142
143 class ChercheurGroupe(models.Model):
144 id = models.AutoField(primary_key=True, db_column='id')
145 chercheur = models.ForeignKey('Chercheur', db_column='chercheur')
146 groupe = models.ForeignKey('Groupe', db_column='groupe')
147 date_inscription = models.DateField(auto_now_add=True)
148 date_modification = models.DateField(auto_now=True)
149 actif = models.BooleanField(editable = False, db_column='actif')