[Zope3-checkins] SVN: messageboard/trunk/step08/ Synced with code
updates of previous chapters.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sun Aug 15 15:20:32 EDT 2004
Log message for revision 27139:
Synced with code updates of previous chapters.
Removed explicit query/getAdapter calles.
Changed:
U messageboard/trunk/step08/browser/messageboard.py
U messageboard/trunk/step08/browser/widgets.py
U messageboard/trunk/step08/configure.zcml
U messageboard/trunk/step08/fields.py
U messageboard/trunk/step08/interfaces.py
U messageboard/trunk/step08/message.py
-=-
Modified: messageboard/trunk/step08/browser/messageboard.py
===================================================================
--- messageboard/trunk/step08/browser/messageboard.py 2004-08-15 19:19:35 UTC (rev 27138)
+++ messageboard/trunk/step08/browser/messageboard.py 2004-08-15 19:20:31 UTC (rev 27139)
@@ -112,7 +112,7 @@
def hasMessageStatus(msg, status, workflow='publish-message'):
"""Check whether a particular message matches a given status"""
- adapter = zapi.queryAdapter(msg, IProcessInstanceContainer)
+ adapter = IProcessInstanceContainer(msg)
if adapter:
# No workflow is defined, so the message is always shown.
if not adapter.keys():
Modified: messageboard/trunk/step08/browser/widgets.py
===================================================================
--- messageboard/trunk/step08/browser/widgets.py 2004-08-15 19:19:35 UTC (rev 27138)
+++ messageboard/trunk/step08/browser/widgets.py 2004-08-15 19:20:31 UTC (rev 27139)
@@ -30,7 +30,7 @@
input = re.sub(regex, '', input)
if self.context.allowed_tags:
- regex = allowed_regex %'|'.join(
+ regex = allowed_regex %'[ />]|'.join(
self.context.allowed_tags)
input = re.sub(regex, '', input)
Modified: messageboard/trunk/step08/configure.zcml
===================================================================
--- messageboard/trunk/step08/configure.zcml 2004-08-15 19:19:35 UTC (rev 27138)
+++ messageboard/trunk/step08/configure.zcml 2004-08-15 19:20:31 UTC (rev 27139)
@@ -1,7 +1,6 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:i18n="http://namespaces.zope.org/i18n"
- xmlns:event="http://namespaces.zope.org/event"
xmlns:mail="http://namespaces.zope.org/mail"
i18n_domain="messageboard">
@@ -76,6 +75,10 @@
interface=".interfaces.IMessage"
/>
<require
+ permission="book.messageboard.View"
+ interface=".interfaces.IMessageContainer"
+ />
+ <require
permission="book.messageboard.Add"
set_schema=".interfaces.IMessage"
/>
@@ -90,7 +93,9 @@
<adapter
factory=".message.MailSubscriptions"
provides=".interfaces.IMailSubscriptions"
- for=".interfaces.IMessage" />
+ for=".interfaces.IMessage"
+ permission="book.messageboard.Add"
+ trusted="true" />
<mail:smtpMailer name="msgboard-smtp" hostname="localhost" port="25" />
@@ -100,13 +105,18 @@
queuePath="./mail-queue"
mailer="msgboard-smtp" />
- <event:subscribe
- subscriber=".message.mailer"
- event_types="zope.app.event.interfaces.IObjectModifiedEvent
- zope.app.container.interfaces.IObjectAddedEvent
- zope.app.container.interfaces.IObjectRemovedEvent" />
+ <subscriber
+ factory=".message.mailer"
+ for="zope.app.event.interfaces.IObjectModifiedEvent" />
+ <subscriber
+ factory=".message.mailer"
+ for="zope.app.container.interfaces.IObjectAddedEvent" />
+ <subscriber
+ factory=".message.mailer"
+ for="zope.app.container.interfaces.IObjectRemovedEvent" />
+
<i18n:registerTranslations directory="locales" />
<include package=".browser" />
Modified: messageboard/trunk/step08/fields.py
===================================================================
--- messageboard/trunk/step08/fields.py 2004-08-15 19:19:35 UTC (rev 27138)
+++ messageboard/trunk/step08/fields.py 2004-08-15 19:20:31 UTC (rev 27139)
@@ -24,7 +24,7 @@
_ = MessageIDFactory('messageboard')
forbidden_regex = r'</?(?:%s).*?/?>'
-allowed_regex = r'</??(?!%s)[a-zA-Z0-9]*? ?(?:[a-z0-9]*?=?".*?")*/??>'
+allowed_regex = r'</??(?!%s[ />])[a-zA-Z0-9]*? ?(?:[a-z0-9]*?=?".*?")*/??>'
class ForbiddenTags(ValidationError):
__doc__ = _("Forbidden HTML Tags used.")
@@ -49,7 +49,7 @@
raise ForbiddenTags(value, self.forbidden_tags)
if self.allowed_tags:
- regex = allowed_regex %'|'.join(self.allowed_tags)
+ regex = allowed_regex %'[ />]|'.join(self.allowed_tags)
if re.findall(regex, value):
raise ForbiddenTags(value, self.allowed_tags)
Modified: messageboard/trunk/step08/interfaces.py
===================================================================
--- messageboard/trunk/step08/interfaces.py 2004-08-15 19:19:35 UTC (rev 27138)
+++ messageboard/trunk/step08/interfaces.py 2004-08-15 19:20:31 UTC (rev 27139)
@@ -24,7 +24,7 @@
from zope.app.container.constraints import ContainerTypesConstraint
from zope.app.container.constraints import ItemTypePrecondition
-from zope.app.container.interfaces import IContainer
+from zope.app.container.interfaces import IContained, IContainer
from zope.app.file.interfaces import IFile
from fields import HTML
@@ -32,12 +32,9 @@
_ = MessageIDFactory('messageboard')
-class IMessage(IContainer):
- """A message object. It can contain its own responses."""
+class IMessage(Interface):
+ """A message object."""
- def __setitem__(name, object):
- """Add a IMessage object."""
-
title = TextLine(
title=_("Title/Subject"),
description=_("Title and/or subject of the message."),
@@ -72,12 +69,23 @@
required=False)
-IMessage['__setitem__'].setTaggedValue('precondition',
- ItemTypePrecondition(IMessage, IFile))
-IMessage.setTaggedValue('__parent__', Field(
- constraint=ContainerTypesConstraint(IMessageBoard, IMessage)))
+class IMessageContained(IContained):
+ """Interface that specifies the type of objects that can contain
+ messages."""
+ __parent__ = Field(
+ constraint = ContainerTypesConstraint(IMessageBoard, IMessage))
+class IMessageContainer(IContainer):
+ """We also want to make the message object a container that can contain
+ responses (other messages) and attachments (files and images)."""
+
+ def __setitem__(name, object):
+ """Add a IMessage object."""
+
+ __setitem__.precondition = ItemTypePrecondition(IMessage, IFile)
+
+
class IHTML(IText):
"""A text field that handles HTML input."""
Modified: messageboard/trunk/step08/message.py
===================================================================
--- messageboard/trunk/step08/message.py 2004-08-15 19:19:35 UTC (rev 27138)
+++ messageboard/trunk/step08/message.py 2004-08-15 19:20:31 UTC (rev 27139)
@@ -26,11 +26,11 @@
from zope.app.container.interfaces import IObjectAddedEvent
from zope.app.container.interfaces import IObjectRemovedEvent
from zope.app.event.interfaces import IObjectModifiedEvent
-from zope.app.event.interfaces import ISubscriber
from zope.app.mail.interfaces import IMailDelivery
from zope.app.size.interfaces import ISized
from book.messageboard.interfaces import IMessage
+from book.messageboard.interfaces import IMessageContained, IMessageContainer
from book.messageboard.interfaces import IMailSubscriptions
_ = MessageIDFactory('messageboard')
@@ -59,7 +59,7 @@
>>> message.body
u'Message Body'
"""
- implements(IMessage)
+ implements(IMessage, IMessageContained, IMessageContainer)
# See book.messageboard.interfaces.IMessage
title = u''
@@ -231,19 +231,10 @@
class MessageMailer:
- """Class to handle all outgoing mail.
-
- Verify the interface implementation
-
- >>> from zope.interface.verify import verifyClass
- >>> verifyClass(ISubscriber, MessageMailer)
- True
- """
+ """Class to handle all outgoing mail."""
- implements(ISubscriber)
-
- def notify(self, event):
- r"""See zope.app.event.interfaces.ISubscriber
+ def __call__(self, event):
+ r"""Called by the event system.
Here is a demonstration on how the notification process and mail
sending works.
@@ -287,7 +278,7 @@
>>> from zope.app.event.objectevent import ObjectModifiedEvent
>>> event = ObjectModifiedEvent(msg)
- >>> mailer.notify(event)
+ >>> mailer(event)
>>> from pprint import pprint
>>> pprint(mail_result)
@@ -364,8 +355,7 @@
if not toaddrs:
return
msg = 'Subject: %s\n\n\n%s' %(subject, body)
- mail_utility = zapi.getUtility(None, IMailDelivery,
- 'msgboard-delivery')
+ mail_utility = zapi.getUtility(IMailDelivery, 'msgboard-delivery')
mail_utility.send('mailer at messageboard.org' , toaddrs, msg)
mailer = MessageMailer()
More information about the Zope3-Checkins
mailing list