This release is a pre-release and may not be stable for production use.
Introduction
horae.subscription provides generic subscription functionality for the Horae resource planning system.
Usage
Objects marked with the horae.subscription.interfaces.ISubscribeable interfaces receive the functionality of being subscribed to. Which means a viewlet is displayed rendering all subscribers and a button to subscribe and unsubscribe if an adapter implementing horae.subscription.interfaces.ISubscriber and adapting the request is available.
The subscribers of an horae.subscription.interfaces.ISubscribeable may be notified by using the horae.subscription.interfaces.ISubscription adapter. First some basic implementations are required:
import grok
from horae.subscription import interfaces
class Subscriber(object):
grok.implements(interfaces.ISubscriber)
def __init__(self, id, name, url=None):
self.id = id
self.name = name
self.url = url
def notify(self, message, subject):
""" Sends the message to the subscriber
"""
print self.name + ': (' + subject + ') ' + subject
def available(self, context):
""" Whether this subscriber is currently available or not
"""
return True
class Message(object):
grok.implements(interfaces.IMessage)
def __init__(self, subject, message):
self._subject = subject
self._message = message
def subject(self):
""" Returns the subject of the notification to be sent
"""
return self._subject
def message(self, html=False):
""" Returns the notification message to be sent
"""
return self._message
class Subscribeable(grok.Model):
grok.implements(interfaces.ISubscribeable)
With those implementations in place some subscriptions may be made and a message may be sent to them.
First we create a subscribeable object:
>>> subscribeable = Subscribeable()
Now we create two subscribers and subscribe them to the subscribeable:
>>> subscriber1 = Subscriber('jsmith', 'John Smith')
>>> subscriber2 = Subscriber('jdoe', 'John Doe')
>>> subscription = interfaces.ISubscription(subscribeable)
>>> subscription.subscribe(subscriber1)
>>> subscription.subscribe(subscriber2)
And send out a message:
>>> message = Message('Test subject', 'Test message')
>>> sent, failed = subscription.notify(message)
John Smith: (Test subject) Test message
John Doe: (Test subject) Test message
>>> sent
2
>>> failed
0
Unsubscription is also done using the subscription adapter:
>>> subscription.unsubscribe(subscriber2.id) >>> sent, failed = subscription.notify(message) John Smith: (Test subject) Test message >>> sent 1 >>> failed 0
Dependencies
Horae
Third party
Changelog
1.0a1 (2012-01-16)
Initial release
Metadata
Release files for horae.subscription 1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| horae.subscription-1.0a1.tar.gz | 5.6 kB | Without provenance | Details for horae.subscription-1.0a1.tar.gz |
Release files / horae.subscription-1.0a1.tar.gz
| Download URL | horae.subscription-1.0a1.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2125958b05819b9cf532e8b36425cd7c08ac1cbab47bc7c77f5694a1707f6563
|
|
BLAKE2b-256 checksum How to use checksums |
a3270243c7069a02db4e8d40f3990380f4cd4b2835cf106cdb4d69d0d2cf6aab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for horae.subscription 1.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.