Commit 503b121a authored by Louis Dod's avatar Louis Dod
Browse files

Add initial implementation of global_preferences

(for mail_notification of organization)
parent 64dc0ac4
......@@ -23,3 +23,12 @@ Intended for us with Reverseproxy (Port: 1337)!
- Website based on Bootstrap
# Development
WIP:\
### TODO:
Registriung anmeldedatum -> Reihenfolge
doppelte Mail entfernen?
......@@ -16,6 +16,7 @@ rm -r /code/static/* # clears static files (if something should have changed in
python manage.py collectstatic --noinput
python manage.py migrate
python manage.py migrate dynamic_preference
python manage.py createsuperuser --noinput
......
......@@ -7,8 +7,6 @@ KEY = '...'
# Mail:
ORGANIZATION_ADDRESS = 'registrations@example-domain.com'
EMAIL_HOST = 'mail.example-domain.com'
EMAIL_PORT = 465 # SMTP-Port (could also be 587)
EMAIL_HOST_USER = ''
......
......@@ -50,6 +50,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
# imports:
'crispy_forms',
'dynamic_preferences',
# custom:
'ui'
]
......@@ -77,6 +78,8 @@ TEMPLATES = [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
# imports
'dynamic_preferences.processors.global_preferences'
],
},
},
......@@ -140,21 +143,19 @@ if os.environ.get("PRODUCTION") != None:
STATIC_ROOT = os.path.join(BASE_DIR, "static")
# settings for imported packages:
# IMPORTED PACKAGES
CRISPY_TEMPLATE_PACK = 'bootstrap4'
# CUSTOM SETTINGS
# Time at which the registration is activated on the corresponding day
REGISTRATION_OPENING_TIME = datetime.time(15, 00)
# Mail-Settings:
ORGANIZATION_ADDRESS = projectSecrets.ORGANIZATION_ADDRESS
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = projectSecrets.EMAIL_HOST
EMAIL_PORT = projectSecrets. EMAIL_PORT
......
django==3.0.4
django-crispy-forms==1.9.2
psycopg2-binary==2.8.3
gunicorn==19.9.0
\ No newline at end of file
gunicorn==19.9.0
django-dynamic-preferences==1.10.1
\ No newline at end of file
......@@ -2,8 +2,18 @@ import logging
from django.core.mail import send_mail
from django.template.loader import render_to_string
from django.conf import settings
from dynamic_preferences.registries import global_preferences_registry
logger = logging.getLogger(__name__)
global_preferences = global_preferences_registry.manager()
def successful_registration_action(candidate, project):
''' handles response-mail and other optional defined processes
'''
send_registration_confirmation_mail(candidate, project)
if global_preferences['organization_mail_alert']:
send_registration_alert_mail(candidate, project)
def send_registration_confirmation_mail(candidate, project):
......@@ -34,7 +44,7 @@ def send_registration_alert_mail(candidate, project):
'''
logger.info('Start sending Alert-Mail')
from_email = settings.EMAIL_HOST_USER
to_email = settings.ORGANIZATION_ADDRESS
to_email = global_preferences['organization_mail_address']
subject = 'Neue Projektanmeldung auf Webseite'
......
from dynamic_preferences.types import BooleanPreference, StringPreference
from dynamic_preferences.preferences import Section
from dynamic_preferences.registries import global_preferences_registry
general = Section('general')
@global_preferences_registry.register
class OrganizationMailSwitch(BooleanPreference):
section = general
name = 'organization_mail_alert'
verbose_name = "Bei jeder neuen Anmeldung Mail-Adresse benachrichtigen"
default = False
@global_preferences_registry.register
class OrganizationMailAddress(StringPreference):
section = general
name = 'organization_mail_address'
verbose_name = "Mail-Adresse für Benachrichtigung"
default = ''
......@@ -4,7 +4,7 @@ from datetime import date
from .models import Project
from .forms import RegisterForm, RegisterFormWithPrevMembership
from django.conf import settings
from .mailactions import send_registration_confirmation_mail, send_registration_alert_mail
from .actions import successful_registration_action
# Create your views here.
......@@ -42,7 +42,7 @@ def show_project(request, project_id):
return RegisterForm(*args)
project = Project.objects.get(project_id=project_id)
if request.method == "POST":
# RegisterForm(request.POST)
form = select_form(project, request.POST)
......@@ -50,8 +50,7 @@ def show_project(request, project_id):
instance = form.save()
instance.project = project
instance.save()
send_registration_confirmation_mail(instance, project)
send_registration_alert_mail(instance, project)
successful_registration_action(instance, project)
return redirect('/project/{}/success'.format(project.project_id))
else:
form = select_form(project)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment