Skip to content
Snippets Groups Projects
Commit f60ee13c authored by Bidot-Naude Thomas's avatar Bidot-Naude Thomas
Browse files

Notifications for Sec-Gen

parent 9199de7c
Branches
No related tags found
5 merge requests!39Solve public permission files on AWS,!41Rectification Exportation excel sorties,!37Add context_sheet for visits,!38Add context sheet for visits V4,!35Notifications for Sec-Gen
......@@ -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,
}
......@@ -57,5 +57,15 @@ class StudentAdmin(ProfileAdminMixin, admin.ModelAdmin, ExportCsvMixin):
class Meta: # noqa
model = Student
ordering = ['updated_date']
ordering = ['-updated_date']
actions = ["export_as_csv"]
"""def post_event_on_telegram(event):
#message_html = render_to_string('telegram_message.html', {
# 'event': event
#})
telegram_settings = settings.TELEGRAM
bot = telegram.Bot(token=telegram_settings['bot_token'])
bot.send_message(chat_id="@%s" % telegram_settings['channel_name'],
text="test", parse_mode=telegram.ParseMode.HTML)"""
......@@ -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."""
......@@ -189,6 +193,14 @@ class Student(ProfileMixin, models.Model):
# 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
......
......@@ -5,44 +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'
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
......
python-3.6.5
python-3.6.13
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment