Merge branch 'develop' into feature/webhooks
This commit is contained in:
+19
-20
@@ -18,7 +18,7 @@ from webapp.models import processHooks
|
||||
def ohlhafv_view(request, *args, **kwargs):
|
||||
"""Render Ohlhafv form page."""
|
||||
form = OhlhafvForm()
|
||||
return render(request, 'ohlhafv:new.html', {'form': form})
|
||||
return render(request, "ohlhafv:new.html", {"form": form})
|
||||
|
||||
|
||||
@ensure_csrf_cookie
|
||||
@@ -29,33 +29,32 @@ def ohlhafv_submit(request, *args, **kwargs):
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
challenge = form.instance
|
||||
email = form.cleaned_data.get('victim_email', '')
|
||||
|
||||
url = f'https://{URL}/ohlhafv/list'
|
||||
subject = _('You have been challenged at Ohlhafv!')
|
||||
url = f"https://{URL}/ohlhafv/list"
|
||||
|
||||
email_body = render_to_string(
|
||||
'ohlhafv:email.html', {
|
||||
'challenge': challenge,
|
||||
'url': url,
|
||||
}
|
||||
"ohlhafv:email.html",
|
||||
{
|
||||
"challenge": challenge,
|
||||
"url": url,
|
||||
},
|
||||
)
|
||||
send_email(email, subject, email_body)
|
||||
|
||||
to_email = form.cleaned_data.get("victim_email", "")
|
||||
subject = "Sinut on haastettu Øhlhäfviin!"
|
||||
send_email(to=to_email, subject=subject, body=email_body)
|
||||
logging.debug(f"Sent ohlhafv email to recipient <{to_email}>")
|
||||
|
||||
try:
|
||||
webhook_message = render_to_string(
|
||||
'ohlhafv:tgmsg.tpl', {
|
||||
'challenge': challenge,
|
||||
'url': url})
|
||||
"ohlhafv:tgmsg.tpl", {"challenge": challenge, "url": url}
|
||||
)
|
||||
processHooks(message=webhook_message, eventType="ohlhafv")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
logging.debug(
|
||||
'Sent ohlhafv email to recipient <{}>'.format(email))
|
||||
else:
|
||||
pass
|
||||
return HttpResponseRedirect('/ohlhafv/list/')
|
||||
return HttpResponseRedirect("/ohlhafv/list/")
|
||||
|
||||
|
||||
@ensure_csrf_cookie
|
||||
@@ -63,9 +62,9 @@ def ohlhafv_submit(request, *args, **kwargs):
|
||||
def ohlhafv_list(request, *args, **kwargs):
|
||||
"""Present Ohlhafv challenges list."""
|
||||
challenges = OhlhafvChallenge.objects.all()
|
||||
challenges = challenges.order_by('-id')
|
||||
challenges = challenges.order_by("-id")
|
||||
context = {
|
||||
'challenges': challenges,
|
||||
'challenge_count': len(challenges),
|
||||
"challenges": challenges,
|
||||
"challenge_count": len(challenges),
|
||||
}
|
||||
return render(request, 'ohlhafv:list.html', context)
|
||||
return render(request, "ohlhafv:list.html", context)
|
||||
|
||||
Reference in New Issue
Block a user