1
0
Fork 0

added two sendmails functions, that are executed when admins change status of ended project

This commit is contained in:
corsaronero 2022-11-16 21:19:49 +00:00
parent 8356460242
commit 8d6be910f3
6 changed files with 225 additions and 7 deletions

View File

@ -0,0 +1,151 @@
"""
Django settings for foerderbarometer project.
Generated by 'django-admin startproject' using Django 3.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import json
import os
from pathlib import Path
from django.core.exceptions import ImproperlyConfigured
# prefix for urls in mails
URLPREFIX = 'http://localhost:8000'
# mails in development go to stdout
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# get secrets
with open(os.path.join(BASE_DIR, 'secrets.json')) as secrets_file:
secrets = json.load(secrets_file)
def get_secret(setting, secrets=secrets):
"""Get secret setting or fail with ImproperlyConfigured"""
try:
return secrets[setting]
except KeyError:
raise ImproperlyConfigured("Set the {} setting".format(setting))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '*&7p9#_n$@^%0z49s+7jpy@+j1rw_hqh05knyd6y2*!0)r&b6h'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
STATIC_ROOT = BASE_DIR / 'staticfiles'
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'input.apps.InputConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'formtools',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'foerderbarometer.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'foerderbarometer.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'PASSWORD': get_secret('DATABASE_PASSWORD')
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
# needed since django 3.2
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

View File

@ -20,7 +20,14 @@ from django.core.exceptions import ImproperlyConfigured
URLPREFIX = 'http://localhost:8000' URLPREFIX = 'http://localhost:8000'
# mails in development go to stdout # mails in development go to stdout
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'email.wikimedia.de'
EMAIL_PORT = '587'
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '636ea784dd6ec43'
EMAIL_HOST_PASSWORD = 'wsgqp4ZaVRZZEpRJ'
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent

View File

@ -19,8 +19,11 @@ from django.core.exceptions import ImproperlyConfigured
# mails in development go to stdout # mails in development go to stdout
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = '10.0.6.25' EMAIL_HOST = 'email.wikimedia.de'
EMAIL_PORT = '25' EMAIL_PORT = '587'
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '636ea784dd6ec43'
EMAIL_HOST_PASSWORD = 'wsgqp4ZaVRZZEpRJ'
# prefix for urls in mails # prefix for urls in mails
URLPREFIX = 'http://foerderung.wikimedia.de' URLPREFIX = 'http://foerderung.wikimedia.de'

View File

@ -63,7 +63,7 @@ class Command(BaseCommand):
send_mail('Projektende erreicht', send_mail('Projektende erreicht',
mail_template.render(context), mail_template.render(context),
IF_EMAIL, IF_EMAIL,
[IF_EMAIL], ['luca@cannabinieri.de'],
fail_silently=False) fail_silently=False)
project.end_mail_send = True project.end_mail_send = True
project.save() project.save()
@ -79,7 +79,10 @@ class Command(BaseCommand):
approved_end = Project.objects.filter(status = 'END')\ approved_end = Project.objects.filter(status = 'END')\
.exclude(end_mail_send = False) .exclude(end_mail_send = False)
print(approved_end) print(approved_end)
mail_template = get_template('input/if_end_of_project.txt') mail_template = get_template('input/if_end_of_project_approved.txt')
informMail_template = get_template('input/if_end_of_project_orginformed.txt')
# send the mail to project.email, which would be the mail of the volunteer filling out the form
for project in approved_end: for project in approved_end:
context = {'project': project} context = {'project': project}
context['URLPREFIX'] = settings.URLPREFIX context['URLPREFIX'] = settings.URLPREFIX
@ -87,14 +90,54 @@ class Command(BaseCommand):
send_mail('Projektende erreicht', send_mail('Projektende erreicht',
mail_template.render(context), mail_template.render(context),
IF_EMAIL, IF_EMAIL,
[project.email],
fail_silently=False)
send_mail('Projektorganisator*in wurde informiert',
informMail_template.render(context),
IF_EMAIL,
[IF_EMAIL], [IF_EMAIL],
fail_silently=False) fail_silently=False)
project.end_mail_send = True project.end_mail_send = True
project.save() project.save()
except BadHeaderError: except BadHeaderError:
self.stdout.write(self.style.ERROR('Invalid header found.')) self.stdout.write(self.style.ERROR('Invalid header found.'))
self.stdout.write(self.style.SUCCESS('end_of_projects_reached() executed.')) self.stdout.write(self.style.SUCCESS('end_of_projects_approved() executed.'))
def notHappened_of_projects_approved(self):
''' notHappened of project approved '''
# get all projects where end was reached already, and send mails for the ones where status was put to NOT by admins
approved_notHappened = Project.objects.filter(status = 'NOT')\
.exclude(end_mail_send = False)
mail_template = get_template('input/if_not_of_project_approved.txt')
informMail_template = get_template('input/if_end_of_project_orginformed.txt')
# send the mail to project.email, which would be the mail of the volunteer that filled out the form
for project in approved_notHappened:
context = {'project': project}
context['URLPREFIX'] = settings.URLPREFIX
try:
send_mail('Projektende erreicht',
mail_template.render(context),
IF_EMAIL,
[project.email],
fail_silently=False)
send_mail('Projektorganisator*in wurde informiert',
informMail_template.render(context),
IF_EMAIL,
[IF_EMAIL],
fail_silently=False)
project.end_mail_send = True
project.save()
except BadHeaderError:
self.stdout.write(self.style.ERROR('Invalid header found.'))
self.stdout.write(self.style.SUCCESS('notHappened_of_projects_approved() executed.'))
def surveymails_to_object(self, supported, name='', type='LIB'): def surveymails_to_object(self, supported, name='', type='LIB'):
@ -186,6 +229,7 @@ class Command(BaseCommand):
self.end_of_projects_reached() self.end_of_projects_reached()
self.end_of_projects_approved() self.end_of_projects_approved()
self.notHappened_of_projects_approved()
self.surveymails_to_lib() self.surveymails_to_lib()
self.surveymails_to_hon() self.surveymails_to_hon()
self.surveymails_to_ifg() self.surveymails_to_ifg()

View File

@ -1,6 +1,6 @@
# mail for IF-OTRS # mail for IF-OTRS
#IF_EMAIL = 'community@wikimedia.de' #IF_EMAIL = 'community@wikimedia.de'
IF_EMAIL = 'luca@cannabinieri.de' IF_EMAIL = 'test-luca-ext@wikimedia.de'
#SURVEY_EMAIL = 'christof.pins@wikimedia.de' #SURVEY_EMAIL = 'christof.pins@wikimedia.de'
SURVEY_EMAIL = 'luca.wulf@cannabinieri.de' SURVEY_EMAIL = 'luca.wulf@cannabinieri.de'

View File

@ -0,0 +1,13 @@
Hallo Team Communitys und Engagement!
Das Project {{project.name}} hat am {{project.end}} sein vorraussichtliches
Ende erreicht.
Hier könnt ihr es in der Datenbank editieren:
{{URLPREFIX}}/admin/input/project/{{project.pk}}/change
Projektorganisator*in wurde über den Projektabschluss informiert.
mit freundlichen Grüßen, Eure Lieblingsdatenbank