diff --git a/example/example/demo/views.py b/example/example/demo/views.py index f2255b4..4da1832 100644 --- a/example/example/demo/views.py +++ b/example/example/demo/views.py @@ -1,7 +1,10 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from django.shortcuts import render +from django.shortcuts import render, redirect +from django.contrib import messages +from django.urls import reverse +from example.utils import notify def home(request): @@ -17,10 +20,33 @@ def notification_handler(request, action): """ template_name = 'notification.html' if action == 'email': - pass + html_message = None + if request.POST.get('html_message') is True: + html_message = request.POST.get('body') + + context = { + 'subject': request.POST.get('subject', ''), + 'body': request.POST.get('body', ''), + 'html_message': html_message + } + + data = { + 'source': 'admin@example.com', + 'destination': request.POST.get('to'), + 'notification_type': 'email', + 'provider': request.POST.get('provider'), + 'context': context, + } + + try: + notify(**data) + messages.add_message(request, messages.SUCCESS, 'Email successfully sent.') + except Exception as e: + messages.add_message(request, messages.ERROR, e) + elif action == 'sms': pass elif action == 'push': pass - return render(request, template_name) + return redirect(reverse('home')) diff --git a/example/example/settings.py b/example/example/settings.py index 3f7a04c..0320789 100644 --- a/example/example/settings.py +++ b/example/example/settings.py @@ -40,6 +40,8 @@ # 3rd party apps 'notifyAll', + 'django_extensions', + # own apps 'example.demo', ] diff --git a/example/example/templates/notification.html b/example/example/templates/notification.html index c3268f9..3f82bb9 100644 --- a/example/example/templates/notification.html +++ b/example/example/templates/notification.html @@ -15,6 +15,17 @@