2015-05-25 23:27:14 +02:00
|
|
|
# coding: utf-8
|
|
|
|
|
2015-05-24 17:36:01 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.contrib.auth.models import User
|
2015-05-25 00:17:00 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from django.contrib.gis.db import models as geomodels
|
2015-05-25 00:27:04 +02:00
|
|
|
from django_cas_ng.signals import cas_user_authenticated
|
2015-05-24 17:36:01 +02:00
|
|
|
|
2015-06-14 23:04:43 +02:00
|
|
|
from taggit.managers import TaggableManager
|
|
|
|
|
2015-06-14 16:41:24 +02:00
|
|
|
from monstage.listepays import PAYS_CHOICES
|
|
|
|
|
2015-05-24 17:36:01 +02:00
|
|
|
TYPE_STAGE_CHOICES = (
|
2015-05-25 00:17:00 +02:00
|
|
|
('stage', _(u"Stage")),
|
|
|
|
)
|
|
|
|
|
|
|
|
TYPE_LIEU_CHOICES = (
|
|
|
|
('universite', _(u"Université")),
|
|
|
|
('entreprise', _(u"Entreprise")),
|
|
|
|
('centrerecherche', _(u"Centre de recherche")),
|
|
|
|
('administration', _(u"Administration")),
|
|
|
|
('autre', _(u"Autre")),
|
2015-05-24 17:36:01 +02:00
|
|
|
)
|
|
|
|
|
2015-05-25 23:27:14 +02:00
|
|
|
def choices_length (choices):
|
|
|
|
return reduce (lambda m, choice: max (m, len (choice[0])), choices, 0)
|
|
|
|
|
2015-05-24 17:36:01 +02:00
|
|
|
class Normalien(models.Model):
|
2015-05-25 00:17:00 +02:00
|
|
|
user = models.OneToOneField(User, related_name = "profil")
|
2015-05-24 17:36:01 +02:00
|
|
|
permanent_mail = models.CharField("Adresse e-mail permanente", max_length = 200, blank = True)
|
|
|
|
|
|
|
|
class Meta:
|
2015-05-26 00:27:22 +02:00
|
|
|
verbose_name = u"Profil élève"
|
|
|
|
verbose_name_plural = u"Profils élèves"
|
2015-05-24 17:36:01 +02:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return unicode(self.user.username)
|
|
|
|
|
|
|
|
|
2015-05-25 00:28:16 +02:00
|
|
|
def create_user_profile(sender, user, created, **kwargs):
|
2015-05-25 00:27:04 +02:00
|
|
|
if created:
|
2015-05-25 00:28:16 +02:00
|
|
|
Normalien.objects.get_or_create(user = user)
|
2015-05-25 00:27:04 +02:00
|
|
|
cas_user_authenticated.connect(create_user_profile)
|
|
|
|
|
2015-05-25 23:27:14 +02:00
|
|
|
class Lieu(models.Model):
|
|
|
|
name = models.CharField(_(u"Nom de l'institution d'accueil"), max_length = 250)
|
2015-06-13 22:11:05 +02:00
|
|
|
ville = models.CharField(_(u"Ville"), max_length = 200)
|
2015-06-14 16:41:24 +02:00
|
|
|
pays = models.CharField(_(u"Pays"),
|
|
|
|
choices = PAYS_CHOICES,
|
|
|
|
max_length = choices_length (TYPE_STAGE_CHOICES))
|
2015-05-25 23:27:14 +02:00
|
|
|
coord = geomodels.PointField(_(u"Coordonnées"), geography = True)
|
|
|
|
objects = geomodels.GeoManager() # Requis par GeoDjango
|
|
|
|
type_lieu = models.CharField( _(u"Type de structure d'accueil"),
|
|
|
|
default = "universite",
|
|
|
|
choices = TYPE_LIEU_CHOICES,
|
|
|
|
max_length = choices_length (TYPE_LIEU_CHOICES))
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u"%s (%s)" % (self.name, self.ville)
|
2015-05-26 00:27:22 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Lieu"
|
|
|
|
verbose_name_plural = "Lieux"
|
|
|
|
|
|
|
|
class StageMatiere(models.Model):
|
|
|
|
name = models.CharField(_(u"Matière"), max_length = 30)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Matière des stages"
|
|
|
|
verbose_name_plural = "Matières des stages"
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
2015-05-25 23:27:14 +02:00
|
|
|
|
2015-05-24 17:36:01 +02:00
|
|
|
class Stage(models.Model):
|
2015-06-12 20:17:24 +02:00
|
|
|
profil_user = models.ForeignKey(Normalien, related_name = "stages")
|
2015-05-25 00:17:00 +02:00
|
|
|
published = models.BooleanField(_("Visible publiquement"), default = False)
|
|
|
|
type_stage = models.CharField (_(u"Type"),
|
|
|
|
default = "stage",
|
2015-05-24 17:36:01 +02:00
|
|
|
choices = TYPE_STAGE_CHOICES,
|
|
|
|
max_length = choices_length (TYPE_STAGE_CHOICES))
|
2015-05-25 00:17:00 +02:00
|
|
|
start_date = models.DateField(_(u"Date de début"), null = True)
|
|
|
|
end_date = models.DateField(_(u"Date de fin"), null = True)
|
|
|
|
sujet = models.CharField(_(u"Sujet"), max_length = 500)
|
2015-06-14 23:04:43 +02:00
|
|
|
thematiques = TaggableManager(_(u"Thématiques"), blank = True)
|
2015-05-25 00:17:00 +02:00
|
|
|
encadrants = models.CharField(_(u"Encadrants"), max_length = 500, blank = True)
|
|
|
|
lieux = models.ManyToManyField(Lieu, related_name = "stages", through = "LieuStage")
|
2015-05-26 00:27:22 +02:00
|
|
|
matieres = models.ManyToManyField(StageMatiere, related_name = "stages")
|
2015-05-25 00:17:00 +02:00
|
|
|
|
|
|
|
# Avis
|
2015-05-25 23:27:14 +02:00
|
|
|
avis_encadrants = models.TextField(_(u"Avis sur les encadrants"), blank = True)
|
|
|
|
avis_equipe = models.TextField(_(u"Avis sur l'équipe"), blank = True)
|
|
|
|
avis_stage = models.TextField(_(u"Intérêt du stage"), blank = True)
|
2015-05-25 00:17:00 +02:00
|
|
|
avis_admin = models.TextField(_(u"Visa et administratif"), blank = True)
|
2015-05-24 17:36:01 +02:00
|
|
|
|
2015-05-25 00:17:00 +02:00
|
|
|
def __unicode__(self):
|
2015-06-12 20:17:24 +02:00
|
|
|
return u"%s : %s" % (self.profil_user.user.username, self.sujet)
|
2015-05-26 00:27:22 +02:00
|
|
|
|
2015-05-24 17:36:01 +02:00
|
|
|
class Meta:
|
2015-05-26 00:27:22 +02:00
|
|
|
verbose_name = "Stage"
|
|
|
|
verbose_name_plural = "Stages"
|
2015-05-25 00:17:00 +02:00
|
|
|
|
|
|
|
class LieuStage(models.Model):
|
|
|
|
stage = models.ForeignKey(Stage)
|
|
|
|
lieu = models.ForeignKey(Lieu)
|
|
|
|
|
|
|
|
# Avis
|
|
|
|
avis_global = models.TextField(_(u"Ressenti global"), blank = True)
|
|
|
|
avis_lieudevie = models.TextField(_(u"Mon lieu de vie"), blank = True)
|
|
|
|
avis_lieustage = models.TextField(_(u"Le lieu du stage"), blank = True)
|
|
|
|
avis_pratique = models.TextField(_(u"S'installer / Conseils pratiques"), blank = True)
|
|
|
|
avis_visite = models.TextField(_(u"Que voir / que faire"), blank = True)
|
2015-05-26 00:27:22 +02:00
|
|
|
avis_anecdotes = models.TextField(_(u"Anecdotes"), blank = True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = "Avis sur un lieu de stage"
|
|
|
|
verbose_name_plural = "Avis sur un lieu de stage"
|