Browse Source

strange bugs, wrong ideas, not sure what this was all about?!?

master
Benni Baermann 4 years ago
parent
commit
06a3d727ca
2 changed files with 28 additions and 15 deletions
  1. +16
    -7
      README.md
  2. +12
    -8
      input/views.py

+ 16
- 7
README.md View File

@ -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. 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 ## versions used in development
@ -16,7 +20,7 @@ purpose: gather data from intern(WMDE) and extern(volunteers) forms to create a
## production setup ## 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 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: 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: add to cron at least one time a day:
python manage.py sendmails
python3 manage.py sendmails
server starts with server starts with
nohup gunicorn --forwarded-allow-ips="*" -b '0:8000' foerderbarometer.wsgi 2&> logfile & 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

+ 12
- 8
input/views.py View File

@ -1,4 +1,5 @@
from datetime import date from datetime import date
from smtplib import SMTPException
from django.shortcuts import render from django.shortcuts import render
from django.forms import modelformset_factory from django.forms import modelformset_factory
@ -154,19 +155,19 @@ class ExternView(CookieWizardView):
print(data) print(data)
# write data to database # 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 # 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.username = data['username']
form.email = data['email']
modell.email = data['email']
# write type of form in some cases # write type of form in some cases
if data['choice'] in ('BIB', 'ELIT', 'SOFT'): if data['choice'] in ('BIB', 'ELIT', 'SOFT'):
form.type = data['choice']
modell.type = data['choice']
form.save() form.save()
# add some data to context for mail templates # add some data to context for mail templates
data['pk'] = form.pk
data['pk'] = modell.pk
data['urlprefix'] = settings.URLPREFIX data['urlprefix'] = settings.URLPREFIX
data['grant'] = ('LIT', 'SOFT', 'ELIT', 'BIB', 'IFG') data['grant'] = ('LIT', 'SOFT', 'ELIT', 'BIB', 'IFG')
data['DOMAIN'] = ('MAIL', 'LIST') data['DOMAIN'] = ('MAIL', 'LIST')
@ -181,7 +182,7 @@ class ExternView(CookieWizardView):
'Formular ausgefüllt', 'Formular ausgefüllt',
mail_template.render(context), mail_template.render(context),
IF_EMAIL, IF_EMAIL,
[form.email],
[data['email']],
fail_silently=False) fail_silently=False)
# - mail to IF with link to accept/decline # - mail to IF with link to accept/decline
mail_template = get_template('input/if_mail.txt') mail_template = get_template('input/if_mail.txt')
@ -193,6 +194,9 @@ class ExternView(CookieWizardView):
fail_silently=False) fail_silently=False)
except BadHeaderError: 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) return done(self.request)

Loading…
Cancel
Save