Select Git revision
ThomasBidot
authored and
GitHub
committed
* Password reset feature (#8) * Add Django Rest auth module * Try to make the send reset password email work * Modified template mail for reset * Add Django Rest auth module * Try to make the send reset password email work * Modified template mail for reset * test * Added utf-8 support to exported csv and switched delimiter from , to ; in admin interface * Disabled emails while in dev * Added multi selection filter in admin * Fixed mail settings * Added year field to Tutor serializer * Fixed year updated before registration form filled * commit for automatic deploy * Testing CI * Added filtering in admin for registration validation * Added filter to student admin * Added school info * Fixed typo in filters * Sorties (#30) * Custom participation_inline css * Ordered student profiles by last modification date in admin * Ajouté infos sorties * Sortie thomas (#32) * Updated student admin filters (#28) * Password reset feature (#8) * Add Django Rest auth module * Try to make the send reset password email work * Modified template mail for reset * Add Django Rest auth module * Try to make the send reset password email work * Modified template mail for reset * test * Added utf-8 support to exported csv and switched delimiter from , to ; in admin interface * Disabled emails while in dev * Added multi selection filter in admin * Fixed mail settings * Added year field to Tutor serializer * Fixed year updated before registration form filled * commit for automatic deploy * Testing CI * Added filtering in admin for registration validation * Added filter to student admin Co-authored-by:chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by:
florimondmanca <florimond.manca@gmail.com> Co-authored-by:
Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by:
Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> * Ajout filtre sur register * Ajout filtre participation * Ajout de 3 filtres par etablissements * Ajout 3 filtres pour etablissement V2 Co-authored-by:
Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by:
chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by:
florimondmanca <florimond.manca@gmail.com> Co-authored-by:
Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by:
Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by:
Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by:
Witeden <58004019+Witeden@users.noreply.github.com> * Sortie thomas (export CSV sorties) (#33) * Updated student admin filters (#28) * Password reset feature (#8) * Add Django Rest auth module * Try to make the send reset password email work * Modified template mail for reset * Add Django Rest auth module * Try to make the send reset password email work * Modified template mail for reset * test * Added utf-8 support to exported csv and switched delimiter from , to ; in admin interface * Disabled emails while in dev * Added multi selection filter in admin * Fixed mail settings * Added year field to Tutor serializer * Fixed year updated before registration form filled * commit for automatic deploy * Testing CI * Added filtering in admin for registration validation * Added filter to student admin Co-authored-by:
chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by:
florimondmanca <florimond.manca@gmail.com> Co-authored-by:
Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by:
Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> * Ajout filtre sur register * Ajout filtre participation * Ajout de 3 filtres par etablissements * Ajout 3 filtres pour etablissement V2 * Ajout export CSV sorties Co-authored-by:
Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by:
chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by:
florimondmanca <florimond.manca@gmail.com> Co-authored-by:
Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by:
Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by:
Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by:
Dylan Sechet <dylan.sechet82@gmail.com> Co-authored-by:
Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by:
chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by:
florimondmanca <florimond.manca@gmail.com> Co-authored-by:
Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by:
Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by:
Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by:
Witeden <58004019+Witeden@users.noreply.github.com> * Update runtime.txt Changement version python * Ordering students by updated_date * Notifications for Sec-Gen (#35) * Custom participation_inline css * Ajout filtre sur register * Ajout filtre participation * Ordered student profiles by last modification date in admin * Ajouté infos sorties * Ajout de 3 filtres par etablissements * Ajout 3 filtres pour etablissement V2 * Sortie thomas (#32) * Updated student admin filters (#28) * Password reset feature (#8) * Add Django Rest auth module * Try to make the send reset password email work * Modified template mail for reset * Add Django Rest auth module * Try to make the send reset password email work * Modified template mail for reset * test * Added utf-8 support to exported csv and switched delimiter from , to ; in admin interface * Disabled emails while in dev * Added multi selection filter in admin * Fixed mail settings * Added year field to Tutor serializer * Fixed year updated before registration form filled * commit for automatic deploy * Testing CI * Added filtering in admin for registration validation * Added filter to student admin Co-authored-by:
chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by:
florimondmanca <florimond.manca@gmail.com> Co-authored-by:
Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by:
Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> * Ajout filtre sur register * Ajout filtre participation * Ajout de 3 filtres par etablissements * Ajout 3 filtres pour etablissement V2 Co-authored-by:
Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by:
chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by:
florimondmanca <florimond.manca@gmail.com> Co-authored-by:
Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by:
Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by:
Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by:
Witeden <58004019+Witeden@users.noreply.github.com> * Ajout export CSV sorties * Sortie thomas (export CSV sorties) (#33) * Updated student admin filters (#28) * Password reset feature (#8) * Add Django Rest auth module * Try to make the send reset password email work * Modified template mail for reset * Add Django Rest auth module * Try to make the send reset password email work * Modified template mail for reset * test * Added utf-8 support to exported csv and switched delimiter from , to ; in admin interface * Disabled emails while in dev * Added multi selection filter in admin * Fixed mail settings * Added year field to Tutor serializer * Fixed year updated before registration form filled * commit for automatic deploy * Testing CI * Added filtering in admin for registration validation * Added filter to student admin Co-authored-by:
chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by:
florimondmanca <florimond.manca@gmail.com> Co-authored-by:
Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by:
Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> * Ajout filtre sur register * Ajout filtre participation * Ajout de 3 filtres par etablissements * Ajout 3 filtres pour etablissement V2 * Ajout export CSV sorties Co-authored-by:
Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by:
chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by:
florimondmanca <florimond.manca@gmail.com> Co-authored-by:
Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by:
Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by:
Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> * Erreurs dans visits/admin résolus * Notifications for Sec-Gen Co-authored-by:
Dylan Sechet <dylan.sechet82@gmail.com> Co-authored-by:
Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by:
Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by:
chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by:
florimondmanca <florimond.manca@gmail.com> Co-authored-by:
Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by:
Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by:
Witeden <58004019+Witeden@users.noreply.github.com> Co-authored-by:
chiahetcho <44137047+chiahetcho@users.noreply.github.com> Co-authored-by:
florimondmanca <florimond.manca@gmail.com> Co-authored-by:
Dylan Sechet <dylan.sechet82@gmail.com> Co-authored-by:
Arthur Guédon <arthur.guedon@student-cs.fr> Co-authored-by:
Arthur Guédon <60623551+arthurgdn@users.noreply.github.com> Co-authored-by:
Seon82 <46298009+Seon82@users.noreply.github.com> Co-authored-by:
Bidot-Naude Thomas <thomas.bidotnaude@student-cs.fr> Co-authored-by:
Witeden <58004019+Witeden@users.noreply.github.com>
models.py 7.84 KiB
"""Profiles models."""
from django.db import models
from django.shortcuts import reverse
from dry_rest_permissions.generics import authenticated_users
from .utils import get_promotion_range
from datetime import datetime
from .notifications import SendDocs
import telegram
from django.conf import settings
from django.template.loader import render_to_string
class ProfileMixin:
"""Mixin with common functionnality for profiles."""
detail_view_name = None
def __str__(self):
"""Represent with full name or email."""
full_name = self.user.get_full_name()
if full_name:
return full_name
return self.user.email
def get_absolute_url(self):
return reverse(self.detail_view_name, args=[self.pk])
@staticmethod
@authenticated_users
def has_read_permission(request):
return True
@authenticated_users
def has_object_read_permission(self, request):
return True
class Student(ProfileMixin, models.Model):
"""Represents a student profile."""
detail_view_name = 'api:student-detail'
updated_date = models.DateTimeField(auto_now=True)
user = models.OneToOneField(
'users.User',
on_delete=models.CASCADE,
null=True,
verbose_name='utilisateur',
related_name='student')
registration = models.OneToOneField(
'register.Registration',
on_delete=models.SET_NULL,
null=True,
blank=True,
verbose_name="dossier d'inscription",
related_name='student',
)
classType = models.CharField(max_length=50,
null=True,
blank=True,
verbose_name="général/techno",
)
nationality = models.CharField(max_length=50,
null=True,
blank=True,
verbose_name="nationalité",
)
specialTeaching = models.CharField(max_length=50,
null=True,
blank=True,
verbose_name="enseignement de spécialité",
)
zipCode = models.CharField(max_length=10,
null=True,
blank=True,
verbose_name="code postal",
)
gender = models.CharField(max_length=20,
null=True,
blank=True,
verbose_name="genre",
)
addressNumber = models.IntegerField(
null=True,
blank=True,
verbose_name="numéro de rue"
)
street = models.CharField(max_length=70,
null=True,
blank=True,
verbose_name="nom de rue"
)
city = models.CharField(max_length=50,
null=True,
blank=True,
verbose_name="nom de ville"
)
personalPhone = models.CharField(max_length=12,
null=True,
blank=True,
verbose_name="numéro de téléphone personnel"
)
parentsPhone = models.CharField(max_length=12,
null=True,
blank=True,
verbose_name="numéro de téléphone parental"
)
parentsEmail = models.EmailField(max_length=70,
null=True,
blank=True,
verbose_name="adresse mail parentale"
)
school = models.CharField(max_length=70,
null=True,
blank=True,
verbose_name="établissement"
)
grade = models.CharField(max_length=20,
null=True,
blank=True,
verbose_name="niveau de la classe"
)
scholarship = models.CharField(max_length=50,
null=True,
blank=True,
verbose_name="boursier"
)
fatherActivity = models.CharField(max_length=70,
null=True,
blank=True,
verbose_name="métier du père"
)
motherActivity = models.CharField(max_length=70,
null=True,
blank=True,
verbose_name="métier de la mère"
)
parentsStatus = models.CharField(max_length=70,
null=True,
blank=True,
verbose_name="statut des parents"
)
dependantsNumber = models.IntegerField(
null=True,
blank=True,
verbose_name="nombre de personnes à charge"
)
year = models.CharField(max_length=10,
null=True,
blank=True,
verbose_name="année"
)
@staticmethod
def has_write_permission(request):
return True
def has_object_write_permission(self, request):
return request.user == self.user
def save(self, *args, **kwargs):
"""Updates the year field based on the last modified date"""
if self.city != None: # Ne mettre à jour que quand les données personnelles sont remplies
date_now = datetime.now()
if date_now.month >= 9:
self.year = f"{date_now.year}/{date_now.year+1}"
else:
self.year = f"{date_now.year-1}/{date_now.year}"
# send email with link to registration docs
SendDocs(user=self.user).send()
# send a telegram message to oserSECGEN
telegram_settings = settings.TELEGRAM
if telegram_settings['bot_token'] != None:
message_telegram = "Un tutoré a renseigné ses données personnelles, il attend ta validation !"
bot = telegram.Bot(token=telegram_settings['bot_token'])
bot.send_message(
chat_id="@%s" % telegram_settings['channel_name'], text=message_telegram, parse_mode=telegram.ParseMode.HTML)
return super(Student, self).save(*args, **kwargs)
class Meta: # noqa
verbose_name = 'lycéen'
class Tutor(ProfileMixin, models.Model):
"""Represents a tutor profile."""
detail_view_name = 'api:tutor-detail'
user = models.OneToOneField(
'users.User',
on_delete=models.CASCADE,
null=True,
verbose_name='utilisateur',
related_name='tutor')
address = models.OneToOneField(
'core.Address',
on_delete=models.SET_NULL,
null=True,
verbose_name='adresse',
related_name='tutor')
PROMOTION_CHOICES = tuple(
(year, str(year)) for year in get_promotion_range()
)
promotion = models.IntegerField(choices=PROMOTION_CHOICES,
default=PROMOTION_CHOICES[0][0])
class Meta: # noqa
verbose_name = 'tuteur'