Gestion automatique de la scolarité
This commit is contained in:
parent
9004c802eb
commit
126bce9be3
4 changed files with 50 additions and 9 deletions
|
@ -1,6 +1,9 @@
|
||||||
from django.core.management.base import BaseCommand, CommandError
|
from django.core.management.base import BaseCommand, CommandError
|
||||||
from avisstage.models import Normalien
|
from avisstage.models import Normalien
|
||||||
|
|
||||||
|
from django.utils import timezone
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = 'Réinitialise les statuts "en scolarité" de tout le monde'
|
help = 'Réinitialise les statuts "en scolarité" de tout le monde'
|
||||||
|
|
||||||
|
@ -8,5 +11,6 @@ class Command(BaseCommand):
|
||||||
return
|
return
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
Normalien.objects.all().update(en_scolarite=False)
|
old_conn = timezone.now() - timedelta(days=365)
|
||||||
|
Normalien.objects.all().update(last_cas_connect=t)
|
||||||
self.stdout.write(self.style.SUCCESS(u'Terminé'))
|
self.stdout.write(self.style.SUCCESS(u'Terminé'))
|
||||||
|
|
32
avisstage/migrations/0006_auto_20210131_1954.py
Normal file
32
avisstage/migrations/0006_auto_20210131_1954.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
# Generated by Django 2.2.17 on 2021-01-31 18:54
|
||||||
|
|
||||||
|
import avisstage.models
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('avisstage', '0005_normalien_en_scolarite'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='normalien',
|
||||||
|
name='en_scolarite',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='normalien',
|
||||||
|
name='mail',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='normalien',
|
||||||
|
name='last_cas_login',
|
||||||
|
field=models.DateField(default=avisstage.models._default_cas_login),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='normalien',
|
||||||
|
name='contactez_moi',
|
||||||
|
field=models.BooleanField(default=True, help_text='Affiche votre adresse e-mail principale sur votre profil public', verbose_name='Inviter les visiteurs à me contacter'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -16,12 +16,17 @@ from tinymce.models import HTMLField as RichTextField
|
||||||
from authens.signals import post_cas_connect
|
from authens.signals import post_cas_connect
|
||||||
from authens.models import CASAccount
|
from authens.models import CASAccount
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
from .utils import choices_length, is_email_ens
|
from .utils import choices_length, is_email_ens
|
||||||
from .statics import (
|
from .statics import (
|
||||||
DEPARTEMENTS_DEFAUT, PAYS_OPTIONS, TYPE_LIEU_OPTIONS, TYPE_STAGE_OPTIONS, TYPE_LIEU_DICT,
|
DEPARTEMENTS_DEFAUT, PAYS_OPTIONS, TYPE_LIEU_OPTIONS, TYPE_STAGE_OPTIONS, TYPE_LIEU_DICT,
|
||||||
TYPE_STAGE_DICT, NIVEAU_SCOL_OPTIONS, NIVEAU_SCOL_DICT
|
TYPE_STAGE_DICT, NIVEAU_SCOL_OPTIONS, NIVEAU_SCOL_DICT
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _default_cas_login():
|
||||||
|
return (timezone.now()-timedelta(days=365)).date()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Profil Normalien (extension du modèle User)
|
# Profil Normalien (extension du modèle User)
|
||||||
#
|
#
|
||||||
|
@ -33,13 +38,11 @@ class Normalien(models.Model):
|
||||||
# Infos spécifiques
|
# Infos spécifiques
|
||||||
nom = models.CharField(u"Nom complet", max_length=255, blank=True)
|
nom = models.CharField(u"Nom complet", max_length=255, blank=True)
|
||||||
promotion = models.CharField(u"Promotion", max_length=40, blank=True)
|
promotion = models.CharField(u"Promotion", max_length=40, blank=True)
|
||||||
mail = models.EmailField(u"Adresse e-mail permanente",
|
|
||||||
max_length=200, blank=True)
|
|
||||||
contactez_moi = models.BooleanField(
|
contactez_moi = models.BooleanField(
|
||||||
u"Inviter les visiteurs à me contacter",
|
u"Inviter les visiteurs à me contacter",
|
||||||
default=True, help_text="Affiche votre adresse e-mail principale sur votre profil public")
|
default=True, help_text="Affiche votre adresse e-mail principale sur votre profil public")
|
||||||
bio = models.TextField(u"À propos de moi", blank=True, default="")
|
bio = models.TextField(u"À propos de moi", blank=True, default="")
|
||||||
en_scolarite = models.BooleanField(default=False, blank=True)
|
last_cas_login = models.DateField(default=_default_cas_login)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = u"Profil élève"
|
verbose_name = u"Profil élève"
|
||||||
|
@ -66,6 +69,10 @@ class Normalien(models.Model):
|
||||||
return self.nom
|
return self.nom
|
||||||
return self.user.username
|
return self.user.username
|
||||||
|
|
||||||
|
@property
|
||||||
|
def en_scolarite(self):
|
||||||
|
return self.last_cas_login > (timezone.now() - timedelta(days=60)).date()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def preferred_email(self):
|
def preferred_email(self):
|
||||||
return self.user.email
|
return self.user.email
|
||||||
|
@ -88,10 +95,9 @@ post_save.connect(create_basic_user_profile, sender=User)
|
||||||
def handle_cas_connection(sender, instance, created, cas_login, attributes, **kwargs):
|
def handle_cas_connection(sender, instance, created, cas_login, attributes, **kwargs):
|
||||||
profil, created = Normalien.objects.get_or_create(user=instance)
|
profil, created = Normalien.objects.get_or_create(user=instance)
|
||||||
|
|
||||||
|
profil.last_cas_login = timezone.now().date()
|
||||||
if not created:
|
if not created:
|
||||||
if not profil.en_scolarite:
|
profil.save()
|
||||||
profil.en_scolarite = True
|
|
||||||
profil.save()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
dirs = attributes.get("homeDirectory", "").split("/")
|
dirs = attributes.get("homeDirectory", "").split("/")
|
||||||
|
@ -107,7 +113,6 @@ def handle_cas_connection(sender, instance, created, cas_login, attributes, **kw
|
||||||
|
|
||||||
profil.promotion = "%s %s" % (dep, year)
|
profil.promotion = "%s %s" % (dep, year)
|
||||||
profil.nom = attributes.get("name", "")
|
profil.nom = attributes.get("name", "")
|
||||||
profil.en_scolarite = True
|
|
||||||
profil.save()
|
profil.save()
|
||||||
|
|
||||||
post_cas_connect.connect(handle_cas_connection, sender=User)
|
post_cas_connect.connect(handle_cas_connection, sender=User)
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<p>Si vous êtes encore en scolarité, merci de vous <a href="{% url "authens:login.cas" %}">reconnecter en passant par le serveur d'authentification de l'ENS</a> pour mettre à jour votre statut.</p>
|
<p>Si vous êtes encore en scolarité, merci de vous <a href="{% url "authens:login.cas" %}">reconnecter en passant par le serveur d'authentification de l'ENS</a> pour mettre à jour votre statut.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<hr />
|
<hr />
|
||||||
<p><i>Le statut est mis à jour automatiquement chaque année selon le mode de connexion que vous utilisez.</i></p>
|
<p><i>Le statut est mis à jour automatiquement tous les deux mois selon le mode de connexion que vous utilisez.</i></p>
|
||||||
</section>
|
</section>
|
||||||
<section class="profil">
|
<section class="profil">
|
||||||
<h3>Connexion</h3>
|
<h3>Connexion</h3>
|
||||||
|
|
Loading…
Reference in a new issue