[Zope3-checkins] SVN: messageboard/trunk/step05/ Updated step.
Added forgotten test.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed Aug 11 16:56:12 EDT 2004
Log message for revision 27038:
Updated step. Added forgotten test.
Changed:
U messageboard/trunk/step05/browser/widgets.py
U messageboard/trunk/step05/configure.zcml
U messageboard/trunk/step05/fields.py
U messageboard/trunk/step05/interfaces.py
U messageboard/trunk/step05/message.py
-=-
Modified: messageboard/trunk/step05/browser/widgets.py
===================================================================
--- messageboard/trunk/step05/browser/widgets.py 2004-08-11 20:48:38 UTC (rev 27037)
+++ messageboard/trunk/step05/browser/widgets.py 2004-08-11 20:56:12 UTC (rev 27038)
@@ -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/step05/configure.zcml
===================================================================
--- messageboard/trunk/step05/configure.zcml 2004-08-11 20:48:38 UTC (rev 27037)
+++ messageboard/trunk/step05/configure.zcml 2004-08-11 20:56:12 UTC (rev 27038)
@@ -65,6 +65,10 @@
interface=".interfaces.IMessage"
/>
<require
+ permission="book.messageboard.View"
+ interface=".interfaces.IMessageContainer"
+ />
+ <require
permission="book.messageboard.Add"
set_schema=".interfaces.IMessage"
/>
Modified: messageboard/trunk/step05/fields.py
===================================================================
--- messageboard/trunk/step05/fields.py 2004-08-11 20:48:38 UTC (rev 27037)
+++ messageboard/trunk/step05/fields.py 2004-08-11 20:56:12 UTC (rev 27038)
@@ -21,7 +21,7 @@
from zope.schema.interfaces import ValidationError
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__ = u"""Forbidden HTML Tags used."""
@@ -46,7 +46,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/step05/interfaces.py
===================================================================
--- messageboard/trunk/step05/interfaces.py 2004-08-11 20:48:38 UTC (rev 27037)
+++ messageboard/trunk/step05/interfaces.py 2004-08-11 20:56:12 UTC (rev 27038)
@@ -17,24 +17,22 @@
$Id$
"""
+from zope.interface import Interface
from zope.interface import classImplements
from zope.schema import Text, TextLine, Field, Tuple
from zope.schema.interfaces import IText
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
-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=u"Title/Subject",
description=u"Title and/or subject of the message.",
@@ -69,12 +67,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/step05/message.py
===================================================================
--- messageboard/trunk/step05/message.py 2004-08-11 20:48:38 UTC (rev 27037)
+++ messageboard/trunk/step05/message.py 2004-08-11 20:56:12 UTC (rev 27038)
@@ -22,6 +22,7 @@
from zope.app.size.interfaces import ISized
from book.messageboard.interfaces import IMessage
+from book.messageboard.interfaces import IMessageContained, IMessageContainer
class Message(BTreeContainer):
"""A simple implementation of a message.
@@ -46,7 +47,7 @@
>>> message.body
u'Message Body'
"""
- implements(IMessage)
+ implements(IMessage, IMessageContained, IMessageContainer)
# See book.messageboard.interfaces.IMessage
title = u''
@@ -84,7 +85,29 @@
return ('item', len(self._message))
def sizeForDisplay(self):
- 'See ISized'
+ """See ISized
+
+ Create the adapter first.
+
+ >>> size = MessageSized(Message())
+
+ Here are some examples of the expected output.
+
+ >>> size.sizeForDisplay()
+ u'0 replies, 0 attachments'
+ >>> size._message['msg1'] = Message()
+ >>> size.sizeForDisplay()
+ u'1 reply, 0 attachments'
+ >>> size._message['msg2'] = Message()
+ >>> size.sizeForDisplay()
+ u'2 replies, 0 attachments'
+ >>> size._message['att1'] = object()
+ >>> size.sizeForDisplay()
+ u'2 replies, 1 attachment'
+ >>> size._message['att2'] = object()
+ >>> size.sizeForDisplay()
+ u'2 replies, 2 attachments'
+ """
messages = 0
for obj in self._message.values():
if IMessage.providedBy(obj):
More information about the Zope3-Checkins
mailing list