diff --git a/README.md b/README.md index 412f74e..4cdc538 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,13 @@ purpose: gather data from intern(WMDE) and extern(volunteers) forms to create a database ('förderdatenbank') and send emails with links for a questionary. -## Should be executed daily +## installation and development setup - python3 manage.py sendmails + ln -sr foerderbarometer/settings_development.py foerderbarometer/settings.py + +run the development server with + + python3 manage.py runserver ## versions used in development @@ -16,7 +20,7 @@ purpose: gather data from intern(WMDE) and extern(volunteers) forms to create a ## production setup - ln -s foerderbarometer/settings_production.py foerderbarometer/settings.py + ln -sr foerderbarometer/settings_production.py foerderbarometer/settings.py edit /secrets.json to contain something similar to @@ -28,14 +32,19 @@ edit foerderbarometer/settings_production.py according to your database setup (t run the following commands: - python manage.py makemigrations - python manage.py migrate - python manage.py collectstatic + python3 manage.py makemigrations + python3 manage.py migrate + python3 manage.py collectstatic add to cron at least one time a day: - python manage.py sendmails + python3 manage.py sendmails server starts with nohup gunicorn --forwarded-allow-ips="*" -b '0:8000' foerderbarometer.wsgi 2&> logfile & + + +Should be executed at least daily e.g. in crontab + + python3 manage.py sendmails diff --git a/input/views.py b/input/views.py index 4160530..83df689 100644 --- a/input/views.py +++ b/input/views.py @@ -1,4 +1,5 @@ from datetime import date +from smtplib import SMTPException from django.shortcuts import render from django.forms import modelformset_factory @@ -154,19 +155,19 @@ class ExternView(CookieWizardView): print(data) # write data to database - form = form.save(commit=False) + modell = form.save(commit=False) # we have to copy the data from the first form here - # this is a bit ugly code. how can we copy this without explicit writing? - form.realname = data['realname'] + # this is a bit ugly code. can we copy this without explicit writing? + modell.realname = data['realname'] # form.username = data['username'] - form.email = data['email'] + modell.email = data['email'] # write type of form in some cases if data['choice'] in ('BIB', 'ELIT', 'SOFT'): - form.type = data['choice'] + modell.type = data['choice'] form.save() # add some data to context for mail templates - data['pk'] = form.pk + data['pk'] = modell.pk data['urlprefix'] = settings.URLPREFIX data['grant'] = ('LIT', 'SOFT', 'ELIT', 'BIB', 'IFG') data['DOMAIN'] = ('MAIL', 'LIST') @@ -181,7 +182,7 @@ class ExternView(CookieWizardView): 'Formular ausgefüllt', mail_template.render(context), IF_EMAIL, - [form.email], + [data['email']], fail_silently=False) # - mail to IF with link to accept/decline mail_template = get_template('input/if_mail.txt') @@ -193,6 +194,9 @@ class ExternView(CookieWizardView): fail_silently=False) except BadHeaderError: - return HttpResponse('Invalid header found.') + return HttpResponse('Invalid header found. Data not saved!') + except SMTPException: + return HttpResponse('Error in sending mails (propably wrong adress?). Data not saved!') + return done(self.request)