Skip to content

Commit

Permalink
Merge branch 'example'
Browse files Browse the repository at this point in the history
  • Loading branch information
inforian committed Mar 13, 2017
2 parents 8011eb4 + 579dbb1 commit 570363e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
32 changes: 29 additions & 3 deletions example/example/demo/views.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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'))
2 changes: 2 additions & 0 deletions example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

# 3rd party apps
'notifyAll',
'django_extensions',

# own apps
'example.demo',
]
Expand Down
24 changes: 18 additions & 6 deletions example/example/templates/notification.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
<h1 style="text-align: center;">NotifyAll Example</h1>
</div>
</div>
<div class="row">
<div class="col-lg-6">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
<div class="row">
<div class="col-lg-6" style="padding-right: 20px; border-right:1px solid #ccc;">
<form class="form-horizontal" name="emailNotificationForm" method="post" action="{% url 'notification' 'email' %}">
Expand All @@ -24,34 +35,35 @@ <h1 style="text-align: center;">NotifyAll Example</h1>
<div class="form-group">
<label for="inputEmail" class="control-label col-xs-2">Email</label>
<div class="col-xs-10">
<input type="email" class="form-control" id="inputEmail" placeholder="Email Id">
<input type="email" class="form-control" id="inputEmail" name="to" placeholder="Email Id">
</div>
</div>
<div class="form-group">
<label for="inputSubject" class="control-label col-xs-2">Email Subject</label>
<div class="col-xs-10">
<input type="text" class="form-control" id="inputSubject" placeholder="Email Subject">
<input type="text" class="form-control" id="inputSubject" name="subject" placeholder="Email Subject">
</div>
</div>
<div class="form-group">
<label for="inputBody" class="control-label col-xs-2">Email Body</label>
<div class="col-xs-10">
<textarea class="form-control" id="inputBody" rows="5" cols="10"></textarea>
<textarea class="form-control" id="inputBody" name="body" rows="5" cols="10"></textarea>
</div>
</div>
<div class="form-group">
<label for="inputProvider" class="control-label col-xs-2">Email Provider</label>
<div class="col-xs-10">
<select class="form-control" id="inputProvider">
<select name="provider" class="form-control" id="inputProvider">
<option id="">Select Email Provider</option>
<option id="abc">abc</option>
<option value="gmail">Gmail</option>
<option value="sendgrid">SendGrid</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputHTML" class="control-label col-xs-2">HTML Message</label>
<div class="col-xs-10">
<input type="checkbox" class="form-control" id="inputHTML" >
<input type="checkbox" class="form-control" name="html_message" id="inputHTML" >
</div>
</div>
<div class="form-group">
Expand Down
18 changes: 18 additions & 0 deletions example/example/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from notifyAll.services import notifier


def notify(**kwargs):
"""
"""
notification = notifier.Notifier(
source=kwargs.get('source'),
destination=kwargs.get('destination'),
notification_type=kwargs.get('notification_type'),
provider=kwargs.get('provider'),
context=kwargs.get('context')
)

return notification.notify()

0 comments on commit 570363e

Please sign in to comment.