add cronjob for sending agenda mail 48 hours before the next meeting
This commit is contained in:
@@ -59,6 +59,8 @@ else:
|
||||
|
||||
ALLOWED_HOSTS = ["127.0.0.1", env('HOST_NAME')]
|
||||
|
||||
HOST_NAME = env('HOST_NAME')
|
||||
|
||||
|
||||
DATA_UPLOAD_MAX_MEMORY_SIZE = 1024 * 1024 * 1024
|
||||
# Application definition
|
||||
@@ -77,6 +79,7 @@ INSTALLED_APPS = [
|
||||
'ckeditor_uploader',
|
||||
'easy_thumbnails',
|
||||
'rest_framework',
|
||||
'django_crontab',
|
||||
'django_filters',
|
||||
'django_static_jquery_ui',
|
||||
'posts.apps.PostsConfig',
|
||||
@@ -212,6 +215,7 @@ CKEDITOR_CONFIGS = {
|
||||
}
|
||||
}
|
||||
|
||||
# THUMBNAIL
|
||||
THUMBNAIL_ALIASES = {
|
||||
'': {
|
||||
'avatar': {'size': (50, 50), 'crop': True},
|
||||
@@ -219,9 +223,20 @@ THUMBNAIL_ALIASES = {
|
||||
},
|
||||
}
|
||||
|
||||
# ETHERPAD SETTINGS
|
||||
ETHERPAD_CLIENT = {
|
||||
'url': "http://localhost:9003",
|
||||
'exturl': "https://etherpad2.2020.fet.at/",
|
||||
'apikey': "/srv/andis_test/etherpad_test2/etherpad-lite/APIKEY.txt"
|
||||
|
||||
'apikey': "/srv/andis_test/etherpad_test2/etherpad-lite/APIKEY.txt",
|
||||
}
|
||||
|
||||
# DJANGO MAIL
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
EMAIL_HOST = 'buran.htu.tuwien.ac.at'
|
||||
EMAIL_PORT = 587
|
||||
EMAIL_USE_TLS = True
|
||||
|
||||
# CRON JOBS
|
||||
CRONJOBS = [
|
||||
('0 16 * * *', 'posts.cronjobs.check_to_send_agenda_mail'),
|
||||
]
|
||||
|
||||
23
fet2020/posts/cronjobs.py
Normal file
23
fet2020/posts/cronjobs.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# HOW TO ADD CRONJOBS
|
||||
# write a cronjob function
|
||||
# add cronjob to fet2020/settings.py
|
||||
# add cronjob with cmd 'fet2020/manage.py crontab add'
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import FetMeeting
|
||||
from .mails import send_agenda_mail
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
def check_to_send_agenda_mail():
|
||||
agenda_date = timezone.now().date() + timedelta(days=2)
|
||||
next_meeting = FetMeeting.objects.filter(event_start__date=agenda_date).first()
|
||||
|
||||
if next_meeting and next_meeting.has_agenda:
|
||||
send_agenda_mail(
|
||||
self.event_start.date().strftime("%d.%m.%Y"),
|
||||
self.event_start.time(),
|
||||
self.slug,
|
||||
)
|
||||
17
fet2020/posts/mails.py
Normal file
17
fet2020/posts/mails.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from django.conf import settings
|
||||
from django.core.mail import send_mail
|
||||
|
||||
|
||||
def send_agenda_mail(date, time, slug):
|
||||
msg = "Liebe Alle,\n\n" \
|
||||
"wir haben am " + str(date) + " um " + str(time) + " wieder Sitzung.\n" \
|
||||
"du hast noch bis morgen Zeit, weitere Themen auf die Agenda zu schreiben: " \
|
||||
+ settings.HOST_NAME + '/posts/' + str(slug) + ".\n\n" \
|
||||
"LG deine FET"
|
||||
|
||||
send_mail(
|
||||
subject = 'Test - Agenda der FET Sitzung von ' + str(date),
|
||||
message = msg,
|
||||
from_email = 'patrick@fet.at',
|
||||
recipient_list = ['all@fet.at', ],
|
||||
)
|
||||
@@ -1,17 +1,18 @@
|
||||
django==3.1.*
|
||||
django==3.1.2
|
||||
django-ckeditor==6.0.0
|
||||
django-crontab==0.7.1
|
||||
django-environ==0.4.5
|
||||
django-filter==2.3.0
|
||||
django-static-jquery-ui==1.12.1.1
|
||||
django-taggit==1.3.0
|
||||
djangorestframework==3.12.1
|
||||
configparser==5.0.1
|
||||
docutils==0.16
|
||||
easy-thumbnails==2.7.0
|
||||
configparser
|
||||
etherpad-lite==0.5
|
||||
#mysql-python
|
||||
ghostscript==0.6
|
||||
ldap3==2.8.1
|
||||
mysqlclient==2.0.1
|
||||
Pillow==7.2.0
|
||||
ghostscript==0.6
|
||||
|
||||
|
||||
Reference in New Issue
Block a user