[Checkins] SVN: z3ext.statusmessage/ initial import
Nikolay Kim
fafhrd at datacom.kz
Fri Mar 21 04:15:27 EDT 2008
Log message for revision 84824:
initial import
Changed:
A z3ext.statusmessage/
A z3ext.statusmessage/branches/
A z3ext.statusmessage/tags/
A z3ext.statusmessage/trunk/
A z3ext.statusmessage/trunk/AUTHOR.txt
A z3ext.statusmessage/trunk/CHANGES.txt
A z3ext.statusmessage/trunk/LICENSE.txt
A z3ext.statusmessage/trunk/bootstrap.py
A z3ext.statusmessage/trunk/buildout.cfg
A z3ext.statusmessage/trunk/setup.py
A z3ext.statusmessage/trunk/src/
A z3ext.statusmessage/trunk/src/z3ext/
A z3ext.statusmessage/trunk/src/z3ext/__init__.py
A z3ext.statusmessage/trunk/src/z3ext/statusmessage/
A z3ext.statusmessage/trunk/src/z3ext/statusmessage/README.txt
A z3ext.statusmessage/trunk/src/z3ext/statusmessage/__init__.py
A z3ext.statusmessage/trunk/src/z3ext/statusmessage/browser.py
A z3ext.statusmessage/trunk/src/z3ext/statusmessage/browser.zcml
A z3ext.statusmessage/trunk/src/z3ext/statusmessage/configure.zcml
A z3ext.statusmessage/trunk/src/z3ext/statusmessage/interfaces.py
A z3ext.statusmessage/trunk/src/z3ext/statusmessage/message.py
A z3ext.statusmessage/trunk/src/z3ext/statusmessage/session.py
A z3ext.statusmessage/trunk/src/z3ext/statusmessage/tests.py
-=-
Added: z3ext.statusmessage/trunk/AUTHOR.txt
===================================================================
--- z3ext.statusmessage/trunk/AUTHOR.txt (rev 0)
+++ z3ext.statusmessage/trunk/AUTHOR.txt 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1 @@
+Nikolay Kim (fafhrd91 <at> gmail <dot> com)
Added: z3ext.statusmessage/trunk/CHANGES.txt
===================================================================
--- z3ext.statusmessage/trunk/CHANGES.txt (rev 0)
+++ z3ext.statusmessage/trunk/CHANGES.txt 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,24 @@
+=======
+CHANGES
+=======
+
+1.2.0 (2008-03-21)
+------------------
+
+- rename to z3ext.statusmessage
+
+- moved to svn.zope.org
+
+
+1.1.0 (2008-03-18)
+------------------
+
+- Use z3c.autoinclude
+
+- Code cleanup
+
+
+1.0.0 (2007-12-08)
+------------------
+
+- Initial release.
Added: z3ext.statusmessage/trunk/LICENSE.txt
===================================================================
--- z3ext.statusmessage/trunk/LICENSE.txt (rev 0)
+++ z3ext.statusmessage/trunk/LICENSE.txt 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,54 @@
+Zope Public License (ZPL) Version 2.1
+-------------------------------------
+
+A copyright notice accompanies this license document that
+identifies the copyright holders.
+
+This license has been certified as open source. It has also
+been designated as GPL compatible by the Free Software
+Foundation (FSF).
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the
+following conditions are met:
+
+1. Redistributions in source code must retain the
+ accompanying copyright notice, this list of conditions,
+ and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the accompanying
+ copyright notice, this list of conditions, and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+3. Names of the copyright holders must not be used to
+ endorse or promote products derived from this software
+ without prior written permission from the copyright
+ holders.
+
+4. The right to distribute this software or to use it for
+ any purpose does not give you the right to use
+ Servicemarks (sm) or Trademarks (tm) of the copyright
+ holders. Use of them is covered by separate agreement
+ with the copyright holders.
+
+5. If any files are modified, you must cause the modified
+ files to carry prominent notices stating that you changed
+ the files and the date of any change.
+
+Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS''
+ AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ NO EVENT SHALL THE COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ DAMAGE.
Added: z3ext.statusmessage/trunk/bootstrap.py
===================================================================
--- z3ext.statusmessage/trunk/bootstrap.py (rev 0)
+++ z3ext.statusmessage/trunk/bootstrap.py 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Property changes on: z3ext.statusmessage/trunk/bootstrap.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.statusmessage/trunk/buildout.cfg
===================================================================
--- z3ext.statusmessage/trunk/buildout.cfg (rev 0)
+++ z3ext.statusmessage/trunk/buildout.cfg 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,18 @@
+[buildout]
+develop = .
+parts = test coverage-test coverage-report
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3ext.statusmessage [test]
+
+[coverage-test]
+recipe = zc.recipe.testrunner
+eggs = z3ext.statusmessage [test]
+defaults = ['--coverage', '../../coverage']
+
+[coverage-report]
+recipe = zc.recipe.egg
+eggs = z3c.coverage
+scripts = coverage=coverage-report
+arguments = ('coverage', 'coverage/report')
Added: z3ext.statusmessage/trunk/setup.py
===================================================================
--- z3ext.statusmessage/trunk/setup.py (rev 0)
+++ z3ext.statusmessage/trunk/setup.py 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,68 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Setup for z3ext.statusmessage package
+
+$Id$
+"""
+import sys, os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+version = '1.2.0'
+
+
+setup(name='z3ext.statusmessage',
+ version=version,
+ description="Status messages",
+ long_description=(
+ 'Detailed Dcoumentation\n' +
+ '======================\n'
+ + '\n\n' +
+ read('src', 'z3ext', 'statusmessage', 'README.txt')
+ + '\n\n' +
+ read('CHANGES.txt')
+ ),
+ classifiers=[
+ 'Development Status :: 5 - Production/Stable',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Framework :: Zope3'],
+ author='Nikolay Kim',
+ author_email='fafhrd91 at gmail.com',
+ url='http://z3ext.net/',
+ license='ZPL 2.1',
+ packages=find_packages('src'),
+ package_dir = {'':'src'},
+ namespace_packages=['z3ext'],
+ install_requires = ['setuptools',
+ 'zope.component',
+ 'zope.interface',
+ 'zope.contentprovider',
+ 'zope.session',
+ 'zope.publisher',
+ 'z3c.autoinclude',
+ ],
+ extras_require = dict(test=['zope.app.testing',
+ 'zope.testing',
+ ]),
+ include_package_data = True,
+ zip_safe = False
+ )
Property changes on: z3ext.statusmessage/trunk/setup.py
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Added: z3ext.statusmessage/trunk/src/z3ext/__init__.py
===================================================================
--- z3ext.statusmessage/trunk/src/z3ext/__init__.py (rev 0)
+++ z3ext.statusmessage/trunk/src/z3ext/__init__.py 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,6 @@
+# namespace package boilerplate
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError, e:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Property changes on: z3ext.statusmessage/trunk/src/z3ext/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.statusmessage/trunk/src/z3ext/statusmessage/README.txt
===================================================================
--- z3ext.statusmessage/trunk/src/z3ext/statusmessage/README.txt (rev 0)
+++ z3ext.statusmessage/trunk/src/z3ext/statusmessage/README.txt 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,162 @@
+=====================
+Portal status message
+=====================
+
+Instead include notification messages directly to template,
+ developer can use messaging service.
+
+Main interface is IStatusMessage, it is adapter for IBrowserRequest
+so we can have different implementations, for example cookie based or session.
+
+By default only session based service implemented.
+
+ >>> from zope import interface, component
+ >>> from zope.interface.verify import verifyClass
+
+ >>> from z3ext.statusmessage import tests
+ >>> from z3ext.statusmessage import interfaces, session, message, browser
+
+ >>> verifyClass(interfaces.IStatusMessage, session.SessionMessageService)
+ True
+
+ >>> component.provideAdapter(session.getSessionMessageService)
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+
+ >>> service = interfaces.IStatusMessage(request)
+
+ >>> service.hasMessages()
+ False
+
+ >>> service.add('Test message')
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: ...
+
+ >>> service.clear()
+ ()
+
+
+Before we can use message service we need register message type.
+
+ >>> verifyClass(interfaces.IMessage, message.InformationMessage)
+ True
+
+ >>> component.provideUtility(message.InformationMessage,
+ ... interfaces.IMessageFactory, 'info')
+
+Now we can add messages.
+
+ >>> service.add('Test message')
+
+ >>> service.hasMessages()
+ True
+
+ >>> service.list()
+ [<z3ext.statusmessage.message.InformationMessage ...>]
+
+
+Let's register another message type.
+
+ >>> verifyClass(interfaces.IMessage, message.WarningMessage)
+ True
+
+ >>> component.provideUtility(message.WarningMessage,
+ ... interfaces.IMessageFactory, 'warning')
+
+ >>> service.add('Warning message', 'warning')
+
+ >>> service.list()
+ [<...InformationMessage ...>, <...WarningMessage ...>]
+
+Also we can add message directly
+
+ >>> verifyClass(interfaces.IMessage, message.ErrorMessage)
+ True
+
+Error message, we can add exception object
+
+ >>> service.addMessage(message.ErrorMessage(Exception('Error message')))
+
+or text message
+
+ >>> service.addMessage(message.ErrorMessage('Error message'))
+
+ >>> service.list()
+ [<...InformationMessage ...>, <...WarningMessage ...>, <...ErrorMessage ...>, <...ErrorMessage ...>]
+
+
+Message renderes
+----------------
+
+We should provider IMesasgeView adater for each message type.
+
+ >>> msg = service.list()[0]
+ >>> renderer = component.getMultiAdapter((msg, request), interfaces.IMessageView)
+ >>> renderer.render()
+ '<div class="statusMessage">Test message</div>'
+
+Same for other mesages
+
+ >>> msg = service.list()[1]
+ >>> renderer = component.getMultiAdapter((msg, request), interfaces.IMessageView)
+ >>> renderer.render()
+ '<div class="statusWarningMessage">Warning message</div>'
+
+ >>> msg = service.list()[2]
+ >>> renderer = component.getMultiAdapter((msg, request), interfaces.IMessageView)
+ >>> renderer.render()
+ '<div class="statusStopMessage">Exception: Error message</div>'
+
+To render all messages, we can use 'statusMessage' content provider.
+Also 'statusMessage' provider clears service
+
+ >>> from zope.contentprovider.interfaces import IContentProvider
+ >>> renderer = component.getMultiAdapter(
+ ... (None, request, None), IContentProvider, 'statusMessage')
+ >>> renderer.update()
+ >>> print renderer.render()
+ <div class="statusMessage">Test message</div>
+ <div class="statusWarningMessage">Warning message</div>
+ <div class="statusStopMessage">Exception: Error message</div>
+ <div class="statusStopMessage">Error message</div>
+
+ >>> service.hasMessages()
+ False
+
+It is possible to add new messages to service with 'statusMessages' provider
+
+ >>> renderer.add('Test message')
+ >>> service.list()
+ [<...InformationMessage ...>]
+
+With different type:
+
+ >>> renderer.add('Warning message', 'warning')
+ >>> service.list()
+ [<...InformationMessage ...>, <...WarningMessage ...>]
+
+ >>> renderer.addIf('')
+ >>> len(service.list())
+ 2
+
+ >>> renderer.addIf('test')
+ >>> len(service.list())
+ 3
+
+ >>> t = service.clear()
+
+
+Clearing service
+----------------
+
+clear() method return all messages and clear service.
+
+ >>> service.addMessage(message.ErrorMessage('Error message'))
+
+ >>> service.clear()
+ [<...ErrorMessage ...>]
+
+ >>> service.hasMessages()
+ False
Added: z3ext.statusmessage/trunk/src/z3ext/statusmessage/__init__.py
===================================================================
--- z3ext.statusmessage/trunk/src/z3ext/statusmessage/__init__.py (rev 0)
+++ z3ext.statusmessage/trunk/src/z3ext/statusmessage/__init__.py 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1 @@
+# This file is necessary to make this directory a package.
Property changes on: z3ext.statusmessage/trunk/src/z3ext/statusmessage/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.statusmessage/trunk/src/z3ext/statusmessage/browser.py
===================================================================
--- z3ext.statusmessage/trunk/src/z3ext/statusmessage/browser.py (rev 0)
+++ z3ext.statusmessage/trunk/src/z3ext/statusmessage/browser.py 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,109 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+from zope import interface, component
+from zope.component import getMultiAdapter
+from zope.contentprovider.interfaces import IContentProvider
+
+import interfaces
+from interfaces import IMessageView, IStatusMessage
+
+
+class StatusMessage(object):
+ interface.implements(IContentProvider)
+ component.adapts(
+ interface.Interface,
+ interface.Interface,
+ interface.Interface)
+
+ def __init__(self, context, request, view):
+ self.context, self.request, self.view = context, request, view
+
+ def add(self, text, type='info'):
+ service = IStatusMessage(self.request, None)
+ if service is not None:
+ service.add(text, type)
+
+ def addIf(self, text, type='info'):
+ if bool(text):
+ self.add(text, type)
+
+ def update(self):
+ pass
+
+ def render(self):
+ request = self.request
+
+ service = IStatusMessage(self.request, None)
+ if service is not None:
+ try:
+ messages = service.clear()
+ except:
+ return u''
+
+ views = []
+ for message in messages:
+ view = getMultiAdapter((message, request), IMessageView)
+ views.append(view.render())
+
+ return u'\n'.join(views)
+
+ return u''
+
+
+
+class BaseView(object):
+ interface.implements(IMessageView)
+
+ def __init__(self, context, request):
+ self.context = context
+ self.request = request
+
+ def render(self):
+ return self.template%self.context.message
+
+
+class Message(BaseView):
+ component.adapts(
+ interfaces.IMessage,
+ interface.Interface)
+
+ template = '<div class="statusMessage">%s</div>'
+
+
+class InformationMessage(BaseView):
+ component.adapts(
+ interfaces.IInformationMessage,
+ interface.Interface)
+
+ template = '<div class="statusMessage">%s</div>'
+
+
+class ErrorMessage(BaseView):
+ component.adapts(
+ interfaces.IErrorMessage,
+ interface.Interface)
+
+ template = '<div class="statusStopMessage">%s</div>'
+
+
+class WarningMessage(BaseView):
+ component.adapts(
+ interfaces.IWarningMessage,
+ interface.Interface)
+
+ template = '<div class="statusWarningMessage">%s</div>'
Property changes on: z3ext.statusmessage/trunk/src/z3ext/statusmessage/browser.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.statusmessage/trunk/src/z3ext/statusmessage/browser.zcml
===================================================================
--- z3ext.statusmessage/trunk/src/z3ext/statusmessage/browser.zcml (rev 0)
+++ z3ext.statusmessage/trunk/src/z3ext/statusmessage/browser.zcml 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,12 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <adapter
+ name="statusMessage"
+ factory=".browser.StatusMessage" />
+
+ <adapter factory=".browser.Message" />
+ <adapter factory=".browser.InformationMessage" />
+ <adapter factory=".browser.WarningMessage" />
+ <adapter factory=".browser.ErrorMessage" />
+
+</configure>
Added: z3ext.statusmessage/trunk/src/z3ext/statusmessage/configure.zcml
===================================================================
--- z3ext.statusmessage/trunk/src/z3ext/statusmessage/configure.zcml (rev 0)
+++ z3ext.statusmessage/trunk/src/z3ext/statusmessage/configure.zcml 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,43 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <autoinclude package="z3ext.statusmessage" />
+
+ <utility
+ name="info"
+ provides=".interfaces.IMessageFactory"
+ component=".message.InformationMessage" />
+
+ <class class=".message.InformationMessage">
+ <allow interface=".interfaces.IMessage" />
+ </class>
+
+ <utility
+ name="warning"
+ provides=".interfaces.IMessageFactory"
+ component=".message.WarningMessage" />
+
+ <class class=".message.WarningMessage">
+ <allow interface=".interfaces.IMessage" />
+ </class>
+
+ <utility
+ name="error"
+ provides=".interfaces.IMessageFactory"
+ component=".message.ErrorMessage" />
+
+ <class class=".message.ErrorMessage">
+ <allow interface=".interfaces.IMessage" />
+ </class>
+
+ <class class=".session.SessionMessageService">
+ <allow interface=".interfaces.IStatusMessage" />
+ </class>
+
+ <adapter
+ for="zope.publisher.interfaces.browser.IHTTPRequest"
+ provides=".interfaces.IStatusMessage"
+ factory=".session.getSessionMessageService" />
+
+ <include file="browser.zcml" />
+
+</configure>
Added: z3ext.statusmessage/trunk/src/z3ext/statusmessage/interfaces.py
===================================================================
--- z3ext.statusmessage/trunk/src/z3ext/statusmessage/interfaces.py (rev 0)
+++ z3ext.statusmessage/trunk/src/z3ext/statusmessage/interfaces.py 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,72 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+from zope import interface
+
+SESSIONKEY = 'z3ext.statusmessage'
+
+
+class StatusMessageError(Exception):
+ """ general message service error """
+
+
+class IMessage(interface.Interface):
+ """ message """
+
+ message = interface.Attribute('Message text')
+
+
+class IMessageFactory(interface.Interface):
+ """ message factory """
+
+ def __call__(message):
+ """ create IMessage with message """
+
+
+class IInformationMessage(IMessage):
+ """ information message """
+
+
+class IWarningMessage(IMessage):
+ """ wranning message """
+
+
+class IErrorMessage(IMessage):
+ """ error message """
+
+
+class IStatusMessage(interface.Interface):
+ """ message service """
+
+ def add(text, type='info'):
+ """ add message text as message to service """
+
+ def addMessage(message):
+ """ add IMessage object to service """
+
+ def list():
+ """ list all messages """
+
+ def clear():
+ """ return all messages and clear service """
+
+ def hasMessages():
+ """ check is service has messages """
+
+
+class IMessageView(interface.Interface):
+ """ message view interface """
Property changes on: z3ext.statusmessage/trunk/src/z3ext/statusmessage/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.statusmessage/trunk/src/z3ext/statusmessage/message.py
===================================================================
--- z3ext.statusmessage/trunk/src/z3ext/statusmessage/message.py (rev 0)
+++ z3ext.statusmessage/trunk/src/z3ext/statusmessage/message.py 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,45 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+import cgi
+import interfaces
+from zope import interface
+
+
+class Message(object):
+ interface.classProvides(interfaces.IMessageFactory)
+
+ def __init__(self, message):
+ self.message = message
+
+
+class InformationMessage(Message):
+ interface.implements(interfaces.IInformationMessage)
+
+
+class WarningMessage(Message):
+ interface.implements(interfaces.IWarningMessage)
+
+
+class ErrorMessage(Message):
+ interface.implements(interfaces.IErrorMessage)
+
+ def __init__(self, e):
+ if isinstance(e, Exception):
+ self.message = '%s: %s'%(e.__class__.__name__, cgi.escape(str(e), True))
+ else:
+ self.message = e
Property changes on: z3ext.statusmessage/trunk/src/z3ext/statusmessage/message.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.statusmessage/trunk/src/z3ext/statusmessage/session.py
===================================================================
--- z3ext.statusmessage/trunk/src/z3ext/statusmessage/session.py (rev 0)
+++ z3ext.statusmessage/trunk/src/z3ext/statusmessage/session.py 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,86 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+import logging, sys
+
+from zope import interface, component
+from zope.component import getUtility
+from zope.session.interfaces import ISession
+from zope.publisher.interfaces.browser import IBrowserRequest
+
+from interfaces import SESSIONKEY, IMessageFactory, IStatusMessage
+
+
+def log_exc(msg='', subsystem='z3ext.statusmessage'):
+ log = logging.getLogger(subsystem)
+ log.log(logging.ERROR, msg, exc_info=sys.exc_info())
+
+
+ at component.adapter(IBrowserRequest)
+ at interface.implementer(IStatusMessage)
+def getSessionMessageService(request):
+ try:
+ session = ISession(request, None)
+ if session is not None:
+ return SessionMessageService(session)
+ except:
+ pass
+
+
+class SessionMessageService(object):
+ """ message service that store messages in session """
+ interface.implements(IStatusMessage)
+
+ def __init__(self, session):
+ self.session = session
+
+ def add(self, text, type='info'):
+ factory = getUtility(IMessageFactory, type)
+ self.addMessage(factory(text))
+
+ def addMessage(self, message):
+ data = self.session[SESSIONKEY]
+
+ try:
+ messages = data.get('messages', [])
+ messages.append(message)
+ data['messages'] = messages
+ except Exception, e:
+ log_exc(str(e))
+
+ def list(self):
+ data = self.session[SESSIONKEY]
+ return data.get('messages', ())
+
+ def clear(self):
+ data = self.session[SESSIONKEY]
+
+ messages = data.get('messages')
+ if messages is not None:
+ del data['messages']
+ return messages
+ else:
+ return ()
+
+ def hasMessages(self):
+ data = self.session[SESSIONKEY]
+
+ messages = data.get('messages')
+ if messages is not None:
+ return bool(messages)
+ else:
+ return False
Property changes on: z3ext.statusmessage/trunk/src/z3ext/statusmessage/session.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: z3ext.statusmessage/trunk/src/z3ext/statusmessage/tests.py
===================================================================
--- z3ext.statusmessage/trunk/src/z3ext/statusmessage/tests.py (rev 0)
+++ z3ext.statusmessage/trunk/src/z3ext/statusmessage/tests.py 2008-03-21 08:15:27 UTC (rev 84824)
@@ -0,0 +1,69 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" z3ext.statusmessage tests
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import unittest, doctest
+from zope.app.testing import setup
+
+from zope import interface, component
+from zope.component import provideAdapter
+from zope.session.interfaces import ISession
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.component import provideUtility
+
+import browser
+
+
+class Session(dict):
+
+ def __getitem__(self, key):
+ if not self.has_key(key):
+ self[key] = {}
+
+ return super(Session, self).__getitem__(key)
+
+session = Session()
+
+ at interface.implementer(ISession)
+ at component.adapter(IBrowserRequest)
+def getSession(request):
+ return session
+
+
+def setUp(test):
+ setup.placelessSetUp()
+ provideAdapter(getSession)
+ provideAdapter(browser.StatusMessage, name='statusMessage')
+ provideAdapter(browser.Message)
+ provideAdapter(browser.InformationMessage)
+ provideAdapter(browser.ErrorMessage)
+ provideAdapter(browser.WarningMessage)
+
+
+def tearDown(test):
+ session.__init__()
+ setup.placelessTearDown()
+
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocFileSuite(
+ 'README.txt',
+ setUp=setUp, tearDown=tearDown,
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+ ))
Property changes on: z3ext.statusmessage/trunk/src/z3ext/statusmessage/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the Checkins
mailing list