Add Email sending to Ohlhafv

This commit is contained in:
Aarni Halinen
2018-01-30 16:23:19 +02:00
parent bdc21f79e8
commit 23c00ce167
6 changed files with 1074 additions and 1011 deletions
Binary file not shown.
File diff suppressed because it is too large Load Diff
Binary file not shown.
File diff suppressed because it is too large Load Diff
+8
View File
@@ -0,0 +1,8 @@
{% load i18n %}
{% trans "Moikka" %} {{ challenge.victim }},
{{ challenge.challenger }} {% trans "on haastanut sinut oluenjuontimittelöön" %} {{ challenge.get_series_display }} {% trans "-sarjassa" %}!
{% trans "Muistattehan vahvistaa haasteen paikan päällä Smökissä torstaina 15.3" %}.
{% trans "Käy kurkkaamassa muutkin haasteet osoitteessa" %} {{ url }}
+21
View File
@@ -8,6 +8,8 @@ from django.views.decorators.csrf import ensure_csrf_cookie
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import permission_required, login_required
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.template.loader import render_to_string
import logging
import requests
@@ -16,6 +18,7 @@ from dealer.git import git
from ohlhafv.models import OhlhafvChallenge
from ohlhafv.forms import OhlhafvForm
from ohlhafv.tables import OhlhafvTable
from webapp.utils import send_email
@require_http_methods(["GET"])
@@ -32,6 +35,24 @@ def ohlhafv_submit(request, *args, **kwargs):
form = OhlhafvForm(request.POST)
if form.is_valid():
form.save()
challenge = form.instance
email = form.cleaned_data.get('victim_email', '')
#challenger = form.cleaned_data.get('challenger', 'Anonymous')
#victim = form.cleaned_data.get('victim', 'Anonymous')
#series = form.cleaned_data.get('series', '')
url = 'https://sika.sahkoinsinoorikilta.fi/ohlhafv/list'
subject = _('Sinut on haastettu Øhlhäfviin!')
message = render_to_string(
'ohlhafv:email.html', {
'challenge': challenge,
'url': url,
}
)
send_email(email, subject, message)
logging.debug(
'Sent ohlhafv email to recipient <{}>'.format(email))
else:
pass
return HttpResponseRedirect('/ohlhafv/list/')