Commit ce5e410b authored by Adrián Ribao's avatar Adrián Ribao
Browse files

general fixes

parent 4f73389a
......@@ -25,8 +25,7 @@ class EmailBackend(NotificationBackendBase):
def render_template_email(self, data):
template = loader.get_template(self.template_name)
json_data = json.loads(data)[0]
render = template.render(Context(json_data))
render = template.render(Context(data))
#output = pynliner.fromString(render)
p = Premailer(render)
output = p.transform()
......@@ -44,10 +43,12 @@ class EmailBackend(NotificationBackendBase):
Sends an email with data as a context for the template.
"""
recipients = kwargs.get('to', [])
html_content = self.render_template_email(data)
json_data = json.loads(data)[0]
html_content = self.render_template_email(json_data)
text_content = self.convert_email_to_text(html_content)
subject = self.subject.format(**json_data)
msg = EmailMultiAlternatives(
subject=self.subject,
subject=subject,
body=text_content,
to=recipients)
msg.attach_alternative(html_content, "text/html")
......
......@@ -26,13 +26,15 @@ class ZeroMQBackend(NotificationBackendBase):
pub = context.socket(zmq.PUB)
pub.connect(self.pub_url)
if self.channels:
for channel in self.channels:
processed_data = u'%s %s' % (channel, data)
pub.send_unicode(processed_data)
else:
processed_data = u'%s' % (data)
pub.send_unicode(processed_data)
#print "Sending", self.channels + [str(data), ]
pub.send_multipart(self.channels + [str(data), ])
#if self.channels:
#for channel in self.channels:
#processed_data = u'%s %s' % (channel, data)
#pub.send_unicode(processed_data)
#else:
#processed_data = u'%s' % (data)
#pub.send_unicode(processed_data)
def receive(self, *args, **kwargs):
......@@ -40,15 +42,22 @@ class ZeroMQBackend(NotificationBackendBase):
receiver = context.socket(zmq.SUB)
receiver.connect(self.receiver_url)
if self.channels:
for channel in self.channels:
receiver.setsockopt(zmq.SUBSCRIBE, str(channel))
channel, message = receiver.recv_unicode().split(' ', 1)
else:
receiver.setsockopt(zmq.SUBSCRIBE, '')
message = receiver.recv_unicode()
# This match like OR
for channel in self.channels:
receiver.setsockopt(zmq.SUBSCRIBE, channel)
#receiver.setsockopt(zmq.SUBSCRIBE, ''.join(self.channels))
message = receiver.recv_multipart()
message = message[-1]
#if self.channels:
#for channel in self.channels:
#receiver.setsockopt(zmq.SUBSCRIBE, str(channel))
#channel, message = receiver.recv_unicode().split(' ', 1)
#else:
#receiver.setsockopt(zmq.SUBSCRIBE, '')
#message = receiver.recv_unicode()
return message
def subscribe(self, channel):
self.channels.append(channel)
self.channels.append(str(channel))
......@@ -9,14 +9,14 @@ pip install notifications
Setup
=====
Add to installed apps
Add `notifintime` to installed apps
Getting started
===============
Create a file named `notifications`
Create class that extends `notifications.Notification`
Create class that extends `notifintime.Notification`
Register the Notification
......
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand, CommandError
import zmq
#from zmq.devices.basedevice import ProcessDevice
#from zmq.devices import Device
#from multiprocessing import Process
#import zmq.green as zmq
import os
class Command(BaseCommand):
#args = '<poll_id poll_id ...>'
......@@ -9,20 +13,34 @@ class Command(BaseCommand):
def handle(self, *args, **options):
context = zmq.Context()
print "Connecting to the server..."
print("Starting device...")
pid = os.getpid()
print("PID:{0}".format(pid))
# Using Python Devices.
# More info at: http://blog.pythonisito.com/2012/08/using-zeromq-devices-to-support-complex.html
# Listen for events
sub = context.socket(zmq.SUB)
sub.bind("tcp://*:5555")
print "Listening in port 5555 and echoing to 5556"
sub.setsockopt(zmq.SUBSCRIBE, '')
# Emit events
pub = context.socket(zmq.PUB)
#pub.connect(u'tcp://localhost:5556')
pub.bind("tcp://*:5556")
while True:
message = sub.recv()
pub.send(message)
zmq.device(zmq.FORWARDER, sub, pub)
## Listen for events
#sub = context.socket(zmq.SUB)
#sub.bind("tcp://*:5555")
#print "Listening in port 5555 and echoing to 5556"
#sub.setsockopt(zmq.SUBSCRIBE, '')
## Emit events
#pub = context.socket(zmq.PUB)
##pub.connect(u'tcp://localhost:5556')
#pub.bind("tcp://*:5556")
#while True:
# message = sub.recv()
# pub.send(message)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment