Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython

horae.subscription is unavailable in PyPM, because there aren't any builds for it in the package repositories. Click the linked icons to find out why.

 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
Linux (64-bit)
 
Links
Author
License
GPL
Depended by

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:

System Message: WARNING/2 (<string>, line 20)

Literal block expected; none found.

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)

System Message: ERROR/3 (<string>, line 81)

Inconsistent literal block quoting.

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)

System Message: ERROR/3 (<string>, line 92)

Inconsistent literal block quoting.

John Smith: (Test subject) Test message >>> sent 1 >>> failed 0

Dependencies

Third party

Changelog

1.0a1 (2012-01-16)
  • Initial release

Subscribe to package updates

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.