Skip to content
Snippets Groups Projects
Unverified Commit 8769aefe authored by ThomasBidot's avatar ThomasBidot Committed by GitHub
Browse files

Notifications for Sec-Gen (#36)


* 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: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur 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: default avatarSeon82 <46298009+Seon82@users.noreply.github.com>
Co-authored-by: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur Guédon <60623551+arthurgdn@users.noreply.github.com>
Co-authored-by: default avatarBidot-Naude Thomas <thomas.bidotnaude@student-cs.fr>
Co-authored-by: default avatarWiteden <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: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur 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: default avatarSeon82 <46298009+Seon82@users.noreply.github.com>
Co-authored-by: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur Guédon <60623551+arthurgdn@users.noreply.github.com>
Co-authored-by: default avatarBidot-Naude Thomas <thomas.bidotnaude@student-cs.fr>

Co-authored-by: default avatarDylan Sechet <dylan.sechet82@gmail.com>
Co-authored-by: default avatarSeon82 <46298009+Seon82@users.noreply.github.com>
Co-authored-by: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur Guédon <60623551+arthurgdn@users.noreply.github.com>
Co-authored-by: default avatarBidot-Naude Thomas <thomas.bidotnaude@student-cs.fr>
Co-authored-by: default avatarWiteden <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: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur 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: default avatarSeon82 <46298009+Seon82@users.noreply.github.com>
Co-authored-by: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur Guédon <60623551+arthurgdn@users.noreply.github.com>
Co-authored-by: default avatarBidot-Naude Thomas <thomas.bidotnaude@student-cs.fr>
Co-authored-by: default avatarWiteden <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: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur 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: default avatarSeon82 <46298009+Seon82@users.noreply.github.com>
Co-authored-by: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur Guédon <60623551+arthurgdn@users.noreply.github.com>
Co-authored-by: default avatarBidot-Naude Thomas <thomas.bidotnaude@student-cs.fr>

* Erreurs dans visits/admin résolus

* Notifications for Sec-Gen

Co-authored-by: default avatarDylan Sechet <dylan.sechet82@gmail.com>
Co-authored-by: default avatarBidot-Naude Thomas <thomas.bidotnaude@student-cs.fr>
Co-authored-by: default avatarSeon82 <46298009+Seon82@users.noreply.github.com>
Co-authored-by: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur Guédon <60623551+arthurgdn@users.noreply.github.com>
Co-authored-by: default avatarWiteden <58004019+Witeden@users.noreply.github.com>

Co-authored-by: default avatarchiahetcho <44137047+chiahetcho@users.noreply.github.com>
Co-authored-by: default avatarflorimondmanca <florimond.manca@gmail.com>
Co-authored-by: default avatarDylan Sechet <dylan.sechet82@gmail.com>
Co-authored-by: default avatarArthur Guédon <arthur.guedon@student-cs.fr>
Co-authored-by: default avatarArthur Guédon <60623551+arthurgdn@users.noreply.github.com>
Co-authored-by: default avatarSeon82 <46298009+Seon82@users.noreply.github.com>
Co-authored-by: default avatarBidot-Naude Thomas <thomas.bidotnaude@student-cs.fr>
Co-authored-by: default avatarWiteden <58004019+Witeden@users.noreply.github.com>
parent 14283adb
Branches
No related tags found
No related merge requests found
......@@ -288,3 +288,12 @@ STATICFILES_DIRS = [
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Telegram bot
TELEGRAM_BOT_TOKEN = os.getenv(
"TELEGRAM_BOT_TOKEN")
TELEGRAM = {
'bot_token': TELEGRAM_BOT_TOKEN,
'channel_name': 'oserSECGEN',
'production': False,
}
......@@ -7,6 +7,8 @@ import codecs
import csv
from django.http import HttpResponse
class ExportCsvMixin:
def export_as_csv(self, request, queryset):
......@@ -14,13 +16,15 @@ class ExportCsvMixin:
field_names = [field.name for field in meta.fields]
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename={}.csv'.format(meta)
response['Content-Disposition'] = 'attachment; filename={}.csv'.format(
meta)
response.write(codecs.BOM_UTF8) # force response to be UTF-8
writer = csv.writer(response, delimiter=';')
writer.writerow(field_names)
for obj in queryset:
row = writer.writerow([getattr(obj, field) for field in field_names])
row = writer.writerow([getattr(obj, field)
for field in field_names])
return response
......@@ -33,6 +37,7 @@ class ProfileAdminMixin:
search_fields = ('user__email', 'user__first_name', 'user__last_name',)
actions = ["export_as_csv"]
@admin.register(Tutor)
class TutorAdmin(ProfileAdminMixin, admin.ModelAdmin, ExportCsvMixin):
"""Tutor admin panel."""
......@@ -47,7 +52,9 @@ class TutorAdmin(ProfileAdminMixin, admin.ModelAdmin,ExportCsvMixin):
@admin.register(Student)
class StudentAdmin(ProfileAdminMixin, admin.ModelAdmin, ExportCsvMixin):
"""Student admin panel."""
list_filter = (('school',MultiSelectFieldListFilter), 'year', 'registration__validated')
list_filter = (('school', MultiSelectFieldListFilter),
'year', 'registration__validated')
class Meta: # noqa
model = Student
ordering = ['-updated_date']
......
......@@ -7,6 +7,10 @@ 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."""
......@@ -80,7 +84,6 @@ class Student(ProfileMixin, models.Model):
verbose_name="code postal",
)
gender = models.CharField(max_length=20,
null=True,
blank=True,
......@@ -123,49 +126,42 @@ class Student(ProfileMixin, models.Model):
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,
......@@ -194,7 +190,16 @@ class Student(ProfileMixin, models.Model):
else:
self.year = f"{date_now.year-1}/{date_now.year}"
SendDocs(user=self.user).send() # send email with link to registration docs
# 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)
......
......@@ -5,25 +5,6 @@ from .models import Registration
from profiles.models import Student
class SchoolFilter(admin.SimpleListFilter):
title = 'établissement'
parameter_name = 'profiles__school'
def lookups(self, request, model_admin):
list_of_school = []
query = Student.objects.values_list(
"school", flat=True).distinct()
for school in query:
list_of_school.append((school, school))
return list_of_school
def queryset(self, request, queryset):
if self.value():
emails = Student.objects.filter(
school=self.value()).values_list("user__email", flat=True)
return queryset.filter(email__in=emails)
class SchoolFilter(admin.SimpleListFilter):
title = 'établissement'
parameter_name = 'profiles__school'
......
......@@ -12,6 +12,10 @@ django-sendgrid-v5
django-filter
django-rest-auth
# Telegram messages via python-telegram-bot
tornado==5.1.1
python-telegram-bot==12.2.0
# Storage of files in AWS S3
django-storages
boto3
......
......@@ -110,13 +110,11 @@ class ParticipationInline(admin.TabularInline):
school = Student.objects.get(user = participation.user).school
return school
school.short_description = "Établissement"
def name(self, participation: Participation):
"""Returns the participation's user's name"""
return participation.user.first_name + " " + participation.user.last_name
name.short_description = "Nom"
class Media:
css = { "all" : ("css/hide_admin_original.css",) }
......@@ -175,7 +173,6 @@ class ParticipationAdmin(admin.ModelAdmin):
return school
school.short_description = "Établissement"
def export_as_csv(self, request, queryset):
meta = self.model._meta
field_names = [field.name for field in meta.fields]
......@@ -205,7 +202,6 @@ class ParticipationAdmin(admin.ModelAdmin):
export_as_csv.short_description = "Exporter sélection (en .csv)"
@ admin.register(Visit.organizers.through)
class VisitOrganizersAdmin(admin.ModelAdmin):
"""Admin panel for visit organizers."""
......@@ -239,7 +235,6 @@ class VisitAdmin(admin.ModelAdmin):
return obj.participants.count()
num_participants.short_description = 'Participants'
@ admin.register(Place)
class PlaceAdmin(admin.ModelAdmin):
"""Admin panel for places."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment