Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Adrián Ribao
Notifintime
Commits
ce5e410b
Commit
ce5e410b
authored
Jan 30, 2013
by
Adrián Ribao
Browse files
general fixes
parent
4f73389a
Changes
4
Hide whitespace changes
Inline
Side-by-side
notifintime/backends/email.py
View file @
ce5e410b
...
...
@@ -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"
)
...
...
notifintime/backends/zeromq.py
View file @
ce5e410b
...
...
@@ -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
)
)
notifintime/docs/notifintime/design.rst
View file @
ce5e410b
...
...
@@ -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 `notifi
cations
.Notification`
Create class that extends `notifi
ntime
.Notification`
Register the Notification
...
...
notifintime/management/commands/zeromq_server.py
View file @
ce5e410b
# -*- 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)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment