[Checkins] SVN: gocept.registration/trunk/ add support for optionally passing in a factory to the register method.
Paul Carduner
paulcarduner at gmail.com
Fri Oct 24 19:20:22 EDT 2008
Log message for revision 92535:
add support for optionally passing in a factory to the register method.
Changed:
U gocept.registration/trunk/CHANGES.txt
U gocept.registration/trunk/src/gocept/registration/README.txt
U gocept.registration/trunk/src/gocept/registration/registrations.py
-=-
Modified: gocept.registration/trunk/CHANGES.txt
===================================================================
--- gocept.registration/trunk/CHANGES.txt 2008-10-24 22:51:31 UTC (rev 92534)
+++ gocept.registration/trunk/CHANGES.txt 2008-10-24 23:20:21 UTC (rev 92535)
@@ -2,9 +2,12 @@
=======
-0.3.0 (2008-??-??)
+0.3.0 (unreleased)
------------------
+- Feature: Allowing passing in a factory to the register of the
+ ``Registrations`` object.
+
0.2.0 (2008-05-10)
------------------
Modified: gocept.registration/trunk/src/gocept/registration/README.txt
===================================================================
--- gocept.registration/trunk/src/gocept/registration/README.txt 2008-10-24 22:51:31 UTC (rev 92534)
+++ gocept.registration/trunk/src/gocept/registration/README.txt 2008-10-24 23:20:21 UTC (rev 92535)
@@ -43,7 +43,32 @@
Traceback (most recent call last):
KeyError: '<SHA-HASH>'
+Customizing the Registration Object
+===================================
+When calling the ``register`` method, we can also optionally pass in a
+factory to construct the registration. This is useful when
+subclassing the ``Registration`` class.
+
+ >>> from gocept.registration.registrations import Registration
+ >>> class MyRegistration(Registration):
+ ... def __init__(self, hash, email, data):
+ ... assert data.has_key('agentNumber'), 'missing agent number!'
+ ... super(MyRegistration, self).__init__(hash, email, data)
+
+ >>> registrations.register('james at bond.com',
+ ... {'name': u'James Bond'},
+ ... factory=MyRegistration)
+ Traceback (most recent call last):
+ ...
+ AssertionError: missing agent number!
+ >>> registrations.register('james at bond.com',
+ ... {'name': u'James Bond',
+ ... 'agentNumber': u'007'},
+ ... factory=MyRegistration)
+ <MyRegistration object at ...>
+
+
Application hooks
=================
Modified: gocept.registration/trunk/src/gocept/registration/registrations.py
===================================================================
--- gocept.registration/trunk/src/gocept/registration/registrations.py 2008-10-24 22:51:31 UTC (rev 92534)
+++ gocept.registration/trunk/src/gocept/registration/registrations.py 2008-10-24 23:20:21 UTC (rev 92535)
@@ -20,6 +20,18 @@
import zope.app.container.btree
import zope.interface
+
+class Registration(zope.app.container.contained.Contained,
+ persistent.Persistent):
+
+ zope.interface.implements(gocept.registration.interfaces.IRegistration)
+
+ def __init__(self, hash, email, data):
+ self.hash = hash
+ self.email = email
+ self.data = data
+
+
class Registrations(zope.app.container.btree.BTreeContainer):
zope.interface.implements(gocept.registration.interfaces.IRegistrations)
@@ -27,10 +39,10 @@
def _createHash(self, email, data=None):
return sha.new(email+datetime.datetime.now().isoformat()).hexdigest()
- def register(self, email, data=None):
+ def register(self, email, data=None, factory=Registration):
"""Create a new registration for the given email address and data."""
hash = self._createHash(email, data)
- self[hash] = registration = Registration(hash, email, data)
+ self[hash] = registration = factory(hash, email, data)
return registration
def confirm(self, hash):
@@ -42,14 +54,3 @@
zope.event.notify(event)
del self[hash]
-
-
-class Registration(zope.app.container.contained.Contained,
- persistent.Persistent):
-
- zope.interface.implements(gocept.registration.interfaces.IRegistration)
-
- def __init__(self, hash, email, data):
- self.hash = hash
- self.email = email
- self.data = data
More information about the Checkins
mailing list