[Checkins] SVN: z3ext.formatter/ initial import

Nikolay Kim fafhrd at datacom.kz
Tue Mar 25 08:12:42 EDT 2008


Log message for revision 84923:
  initial import

Changed:
  A   z3ext.formatter/
  A   z3ext.formatter/branches/
  A   z3ext.formatter/tags/
  A   z3ext.formatter/trunk/
  A   z3ext.formatter/trunk/AUTHOR.txt
  A   z3ext.formatter/trunk/CHANGES.txt
  A   z3ext.formatter/trunk/LICENSE.txt
  A   z3ext.formatter/trunk/bootstrap.py
  A   z3ext.formatter/trunk/buildout.cfg
  A   z3ext.formatter/trunk/setup.py
  A   z3ext.formatter/trunk/src/
  A   z3ext.formatter/trunk/src/z3ext/
  A   z3ext.formatter/trunk/src/z3ext/__init__.py
  A   z3ext.formatter/trunk/src/z3ext/formatter/
  A   z3ext.formatter/trunk/src/z3ext/formatter/README.txt
  A   z3ext.formatter/trunk/src/z3ext/formatter/__init__.py
  A   z3ext.formatter/trunk/src/z3ext/formatter/config.py
  A   z3ext.formatter/trunk/src/z3ext/formatter/config.txt
  A   z3ext.formatter/trunk/src/z3ext/formatter/configure.zcml
  A   z3ext.formatter/trunk/src/z3ext/formatter/dformatter.py
  A   z3ext.formatter/trunk/src/z3ext/formatter/dtformatter.py
  A   z3ext.formatter/trunk/src/z3ext/formatter/expression.py
  A   z3ext.formatter/trunk/src/z3ext/formatter/fancydatetime.py
  A   z3ext.formatter/trunk/src/z3ext/formatter/i18n.py
  A   z3ext.formatter/trunk/src/z3ext/formatter/interfaces.py
  A   z3ext.formatter/trunk/src/z3ext/formatter/preferences-formatter.png
  A   z3ext.formatter/trunk/src/z3ext/formatter/tests.py
  A   z3ext.formatter/trunk/src/z3ext/formatter/utils.py
  A   z3ext.formatter/trunk/src/z3ext/formatter/vocabulary.py

-=-

Property changes on: z3ext.formatter/trunk
___________________________________________________________________
Name: svn:ignore
   + bin
develop-eggs
eggs
parts
coverage
.installed.cfg


Added: z3ext.formatter/trunk/AUTHOR.txt
===================================================================
--- z3ext.formatter/trunk/AUTHOR.txt	                        (rev 0)
+++ z3ext.formatter/trunk/AUTHOR.txt	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1 @@
+Nikolay Kim (fafhrd91 <at> gmail <dot> com)

Added: z3ext.formatter/trunk/CHANGES.txt
===================================================================
--- z3ext.formatter/trunk/CHANGES.txt	                        (rev 0)
+++ z3ext.formatter/trunk/CHANGES.txt	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,36 @@
+=======
+CHANGES
+=======
+
+1.2.0 (2008-03-25)
+------------------
+
+- Use z3c.autoinclude
+
+- Code moved to svn.zope.org
+
+
+1.1.2 (2008-03-06)
+------------------
+
+- Fixed bug in fancyDatetime formatter
+
+
+1.1.1 (2008-02-05)
+------------------
+
+- Added 'Timezones' vocabulary
+
+- Cleanup code
+
+
+1.1.0 (2007-12-21)
+------------------
+
+- Added controlpanel configlet
+
+
+1.0.0 (2007-12-07)
+------------------
+
+- Initial release.

Added: z3ext.formatter/trunk/LICENSE.txt
===================================================================
--- z3ext.formatter/trunk/LICENSE.txt	                        (rev 0)
+++ z3ext.formatter/trunk/LICENSE.txt	2008-03-25 12:12:41 UTC (rev 84923)
@@ -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.formatter/trunk/bootstrap.py
===================================================================
--- z3ext.formatter/trunk/bootstrap.py	                        (rev 0)
+++ z3ext.formatter/trunk/bootstrap.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -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.formatter/trunk/bootstrap.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/buildout.cfg
===================================================================
--- z3ext.formatter/trunk/buildout.cfg	                        (rev 0)
+++ z3ext.formatter/trunk/buildout.cfg	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,20 @@
+[buildout]
+develop = .
+parts = test coverage-test coverage-report
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3ext.formatter [test]
+
+
+[coverage-test]
+recipe = zc.recipe.testrunner
+eggs = z3ext.formatter [test]
+defaults = ['--coverage', '../../coverage']
+
+
+[coverage-report]
+recipe = zc.recipe.egg
+eggs = z3c.coverage
+scripts = coverage=coverage-report
+arguments = ('coverage', 'coverage/report')

Added: z3ext.formatter/trunk/setup.py
===================================================================
--- z3ext.formatter/trunk/setup.py	                        (rev 0)
+++ z3ext.formatter/trunk/setup.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,76 @@
+##############################################################################
+#
+# 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.formatter 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.0dev'
+
+
+setup(name='z3ext.formatter',
+      version=version,
+      description="Extensible TALES fomratter expression.",
+      long_description=(
+          'Detailed Dcoumentation\n' +
+          '======================\n'
+          + '\n\n' +
+          read('src', 'z3ext', 'formatter', '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',
+      package_dir = {'':'src'},
+      packages=find_packages('src'),
+      namespace_packages=['z3ext'],
+      install_requires = ['setuptools',
+                          'pytz',
+                          'zope.component',
+                          'zope.interface',
+                          'zope.publisher',
+                          'zope.schema',
+                          'zope.proxy',
+                          'zope.tales',
+                          'zope.i18nmessageid',
+                          'zope.app.appsetup',
+                          'zope.app.pagetemplate',
+                          'zope.app.publisher',
+			  'z3c.autoinclude',
+			  'z3ext.controlpanel',
+                          ],
+      extras_require = dict(test=['zope.app.zptpage',
+                                  'zope.app.testing',
+                                  'zope.testing',
+                                  ]),
+      include_package_data = True,
+      zip_safe = False
+      )


Property changes on: z3ext.formatter/trunk/setup.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/__init__.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/__init__.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/__init__.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -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.formatter/trunk/src/z3ext/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/formatter/README.txt
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/README.txt	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/README.txt	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,398 @@
+===============
+z3ext.formatter
+===============
+
+This package adds extensible tales expression for various formatters.
+You can change formatter setting per site basis (z3ext.controlpanel).
+
+For configure default settings, add following code to zope.conf
+
+<product-config z3ext.formatter>
+  timezone UTC
+  timezoneFormat 2
+  principalTimezone true
+</product-config>
+
+Values for timezoneFormat are:
+    1: No timezone
+    2: Number of hours
+    3: Timezone name
+
+We need register controlpanel configlet
+
+  >>> from zope.configuration import xmlconfig
+  >>> context = xmlconfig.string("""
+  ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext"
+  ...      i18n_domain="z3ext.formatter">
+  ...    <include package="z3ext.controlpanel" file="meta.zcml" />
+  ...  <z3ext:configlet
+  ...     name="formatter"
+  ...     schema="z3ext.formatter.interfaces.IFormatterConfiglet"
+  ...     title="Portal formatters"
+  ...     description="Configure portal formatters."/>
+  ... </configure>""")
+
+We'll try emulate <product-config z3ext.formatter>
+
+  >>> from zope.app.appsetup import product
+  >>> product._configs['z3ext.formatter'] = {
+  ...   'timezone': u'UTC', 'timezoneFormat': '2', 'principalTimezone': 'true'}
+
+Let's check this
+
+   >>> product.getProductConfiguration('z3ext.formatter')
+   {'timezone': u'UTC', 'timezoneFormat': '2', 'principalTimezone': 'true'}
+
+
+Usually initFormatter() function is colled during IDatabaseOpenedEvent event,
+we simply call it directly:
+
+   >>> from z3ext.formatter.config import initFormatter
+   >>> initFormatter(None)
+
+Now we can get IFormatterConfiglet utility
+
+   >>> from zope.component import getUtility
+   >>> from z3ext.formatter.interfaces import IFormatterConfiglet
+
+   >>> configlet = getUtility(IFormatterConfiglet)
+
+Setup request
+
+   >>> from zope import interface
+   >>> from zope.publisher.browser import TestRequest
+   >>> from zope.annotation.interfaces import IAttributeAnnotatable
+
+   >>> request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'})
+   >>> interface.directlyProvides(request, IAttributeAnnotatable)
+
+   >>> from pytz import UTC
+   >>> from datetime import date, datetime, timedelta
+
+
+DateTime formatter
+------------------
+
+   >>> from zope.app.zptpage import ZPTPage
+   >>> page = ZPTPage()
+   >>> page.setSource(u'''
+   ... <html>
+   ...   <body>
+   ...     <tal:block tal:content="formatter:dateTime,short:options/now" />
+   ...     <tal:block tal:content="formatter:dateTime,medium:options/now" />
+   ...     <tal:block tal:content="formatter:dateTime,long:options/now" />
+   ...     <tal:block tal:content="formatter:dateTime,full:options/now" />
+   ...     <tal:block tal:content="formatter:dateTime:options/now" />
+   ...   </body>
+   ... </html>''')
+
+   >>> dt = datetime(2007, 1, 1, 0, 0, 0, tzinfo=UTC)
+   >>> dt
+   datetime.datetime(2007, 1, 1, 0, 0, tzinfo=<UTC>)
+
+By default we use UTC timezone for output:
+
+   >>> print page.render(request, now=dt)
+   <BLANKLINE>
+   <html>
+     <body>
+       1/1/07 12:00 AM
+       Jan 1, 2007 12:00:00 AM
+       January 1, 2007 12:00:00 AM +000
+       Monday, January 1, 2007 12:00:00 AM +000
+       Jan 1, 2007 12:00:00 AM
+     </body>
+   </html>
+   <BLANKLINE>
+
+If datetime object doesn't contain timezone information, UTC is used
+
+   >>> print page.render(request, now=datetime(2007, 1, 1, 0, 0))
+   <BLANKLINE>
+   <html>
+     <body>
+       1/1/07 12:00 AM
+       Jan 1, 2007 12:00:00 AM
+       January 1, 2007 12:00:00 AM +000
+       Monday, January 1, 2007 12:00:00 AM +000
+       Jan 1, 2007 12:00:00 AM
+     </body>
+   </html>
+   <BLANKLINE>
+
+
+Now let's chane timezone to US/Pacific, we change only time zone 
+not datetime value
+
+   >>> configlet.timezone = 'US/Pacific'
+
+   >>> print page.render(request, now=dt)
+   <BLANKLINE>
+   <html>
+     <body>
+       12/31/06 4:00 PM
+       Dec 31, 2006 4:00:00 PM
+       December 31, 2006 4:00:00 PM -800
+       Sunday, December 31, 2006 4:00:00 PM -800
+       Dec 31, 2006 4:00:00 PM
+     </body>
+   </html>
+   <BLANKLINE>
+
+Now we can change timezone format to 3 (Timezone name)
+
+   >>> configlet.timezoneFormat = 3
+   
+   >>> print page.render(request, now=dt)
+   <BLANKLINE>
+   <html>
+     <body>
+       12/31/06 4:00 PM
+       Dec 31, 2006 4:00:00 PM US/Pacific
+       December 31, 2006 4:00:00 PM -800
+       Sunday, December 31, 2006 4:00:00 PM US/Pacific
+       Dec 31, 2006 4:00:00 PM US/Pacific
+     </body>
+   </html>
+   <BLANKLINE>
+
+We also can redefine timezone for principal if we use principalTimezone true
+
+   >>> from pytz import timezone
+   >>> from zope import interface, component
+   >>> class IPrincipal(interface.Interface):
+   ...   pass
+
+   >>> class Principal:
+   ...     interface.implements(IPrincipal)
+   ...
+   ...     def __init__(self, id):
+   ...         self.id = id
+   ...         self.groups = []
+
+   >>> @component.adapter(IPrincipal)
+   ... @interface.implementer(interface.common.idatetime.ITZInfo)
+   ... def getTimezone(prin):
+   ...   if prin.id == 'user1':
+   ...     return timezone('Europe/Paris')
+   ...   elif prin.id == 'user2':
+   ...     return timezone('Asia/Almaty')
+   >>> component.provideAdapter(getTimezone)
+
+   >>> request.setPrincipal(Principal('user1'))
+   >>> print page.render(request, now=dt)
+   <BLANKLINE>
+   <html>
+     <body>
+       1/1/07 1:00 AM
+       Jan 1, 2007 1:00:00 AM Europe/Paris
+       January 1, 2007 1:00:00 AM +100
+       Monday, January 1, 2007 1:00:00 AM Europe/Paris
+       Jan 1, 2007 1:00:00 AM Europe/Paris
+     </body>
+   </html>
+   <BLANKLINE>
+
+   >>> request.setPrincipal(Principal('user2'))
+   >>> print page.render(request, now=dt)
+   <BLANKLINE>
+   <html>
+     <body>
+       1/1/07 6:00 AM
+       Jan 1, 2007 6:00:00 AM Asia/Almaty
+       January 1, 2007 6:00:00 AM +600
+       Monday, January 1, 2007 6:00:00 AM Asia/Almaty
+       Jan 1, 2007 6:00:00 AM Asia/Almaty
+     </body>
+   </html>
+   <BLANKLINE>
+
+   >>> request.setPrincipal(None)
+
+
+fancyDatetime formatter
+-----------------------
+
+   >>> now = datetime.now(UTC)
+
+   >>> from zope.app.zptpage import ZPTPage
+   >>> fpage = ZPTPage()
+   >>> fpage.setSource(u'''
+   ... <html>
+   ...   <body>
+   ...     <tal:block tal:content="formatter:fancyDatetime:options/now" />
+   ...     <tal:block tal:content="formatter:fancyDatetime,short:options/now" />
+   ...     <tal:block tal:content="formatter:fancyDatetime,medium:options/now" />
+   ...     <tal:block tal:content="formatter:fancyDatetime,full:options/now" />
+   ...   </body>
+   ... </html>''')
+
+Today's datetime
+
+   >>> today = now - timedelta(hours=1)
+
+   >>> print fpage.render(request, now=today)
+   <BLANKLINE>
+   <html>
+     <body>
+       Today at ...
+       Today at ...
+       Today at ...
+       Today at ... US/Pacific
+     </body>
+   </html>
+   <BLANKLINE>
+
+
+Yesterday's datetime
+
+   >>> yesterday = now - timedelta(hours=25)
+
+   >>> print fpage.render(request, now=yesterday)
+   <BLANKLINE>
+   <html>
+     <body>
+       Yesterday at ...
+       Yesterday at ...
+       Yesterday at ...
+       Yesterday at ... US/Pacific
+     </body>
+   </html>
+   <BLANKLINE>
+
+Default timezone is UTC
+
+   >>> now = datetime.now()
+   >>> print fpage.render(request, now=now)
+   <BLANKLINE>
+   <html>
+     <body>
+       Today at ...
+       Today at ...
+       Today at ...
+       Today at ... US/Pacific
+     </body>
+   </html>
+   <BLANKLINE>
+
+
+Date formatter
+--------------
+
+   >>> datepage = ZPTPage()
+   >>> datepage.setSource(u'''
+   ... <html>
+   ...   <body>
+   ...     <tal:block tal:content="formatter:date:options/today" />
+   ...     <tal:block tal:content="formatter:date,short:options/today" />
+   ...   </body>
+   ... </html>''')
+
+   >>> d = date(2007, 1, 1)
+   >>> d
+   datetime.date(2007, 1, 1)
+
+   >>> print datepage.render(request, today=d)
+   <BLANKLINE>
+   <html>
+     <body>
+       Jan 1, 2007
+       1/1/07
+     </body>
+   </html>
+   <BLANKLINE>
+
+
+Also you can get formatter from python code
+
+   >>> from z3ext.formatter.utils import getFormatter
+   >>> formatter = getFormatter(request, 'dateTime', 'full')
+   >>> formatter.format(dt)
+   u'Sunday, December 31, 2006 4:00:00 PM US/Pacific'
+
+We will get FormatterNotDefined if formatter is unknown
+
+   >>> getFormatter(request, 'unknown')
+   Traceback (most recent call last):
+   ...
+   FormatterNotDefined: ...
+
+Wrong format, we should add path expression
+
+   >>> errpage = ZPTPage()
+   >>> errpage.setSource(u'''
+   ...     <tal:block tal:content="formatter:unknown" />''')
+   >>> print errpage.render(request)
+   Traceback (most recent call last):
+   ...
+   PTRuntimeError: ...
+
+Unknown formatter
+
+   >>> errpage = ZPTPage()
+   >>> errpage.setSource(u'''
+   ...     <tal:block tal:content="formatter:unknown:opitons/now" />''')
+   >>> print errpage.render(request)
+   Traceback (most recent call last):
+   ...
+   FormatterNotDefined: unknown
+
+
+Custom formatter
+================
+
+We should define formatter factory and formatter itself
+Let's implement formatter that accept string and currency name and 
+format as currency. Format of TALES expression whould be as 
+'formatter:<formatter name>,<formatter var1>,<formatter var2>,...:<path expression>'
+<formatter name> is name of adapter that adapts IHTTPRequest to IFormatterFactory
+also expression will pass <formatter var[1-...]> as args to factory.
+
+   >>> from z3ext.formatter.interfaces import IFormatter, IFormatterFactory
+
+Here code of formatter:
+
+   >>> class MyFormatter(object):
+   ...    interface.implements(IFormatter)
+   ...
+   ...    currencies = {'usd': '$', 'euro': 'Eur'}
+   ...
+   ...    def __init__(self, request, *args):
+   ...       self.request = request
+   ...       self.currency = self.currencies[args[0]]
+   ...
+   ...    def format(self, value):
+   ...       return '%s %s'%(value, self.currency)
+
+Now we need formatter factory:
+
+   >>> class MyFormatterFactory(object):
+   ...    interface.implements(IFormatterFactory)
+   ...
+   ...    def __init__(self, request):
+   ...        self.request = request
+   ...
+   ...    def __call__(self, *args, **kw):
+   ...        return MyFormatter(self.request, *args)
+
+Now we need register factory as named adapter for IHTTPRequest
+
+   >>> from zope.component import provideAdapter
+   >>> from zope.publisher.interfaces.http import IHTTPRequest
+
+   >>> provideAdapter(MyFormatterFactory, \
+   ...   (IHTTPRequest,), IFormatterFactory, name='currency')
+
+Now we can use formatter
+
+   >>> page = ZPTPage()
+   >>> page.setSource(u'''<tal:block tal:define="value python:121.04">
+   ... <tal:block tal:content="formatter:currency,usd:value" />
+   ... <tal:block tal:content="formatter:currency,euro:value" />
+   ... </tal:block>''')
+
+   >>> print page.render(request)
+   <BLANKLINE>
+   121.04 $
+   121.04 Eur
+   <BLANKLINE>

Added: z3ext.formatter/trunk/src/z3ext/formatter/__init__.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/__init__.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/__init__.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1 @@
+# This file is necessary to make this directory a package.


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/formatter/config.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/config.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/config.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,56 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" default IFormatterConfiglet utility
+
+$Id$
+"""
+
+from zope import interface, component
+from zope.component import getGlobalSiteManager
+from zope.app.appsetup.product import getProductConfiguration
+from zope.app.appsetup.interfaces import IDatabaseOpenedEvent
+
+import vocabulary
+from interfaces import IFormatterConfiglet
+
+
+ at component.adapter(IDatabaseOpenedEvent)
+def initFormatter(event):
+    config = getProductConfiguration('z3ext.formatter')
+    if config is None:
+        config = {}
+
+    sm = getGlobalSiteManager()
+
+    try:
+        timezone = vocabulary.timezones.getTermByToken(
+            config.get('timezone', u'US/Pacific')).value
+    except LookupError:
+        timezone = u'US/Pacific'
+
+    principalTimezone = config.get('principalTimezone', u'true').lower()
+    if principalTimezone == 'true':
+        principalTimezone = True
+    else:
+        principalTimezone = False
+
+    try:
+        timezoneFormat = vocabulary.timezonesOptions.getTermByToken(
+            config.get('timezoneFormat', u'2')).value
+    except LookupError:
+        timezoneFormat = 2
+
+    IFormatterConfiglet['timezone'].default = timezone
+    IFormatterConfiglet['timezoneFormat'].default = timezoneFormat
+    IFormatterConfiglet['principalTimezone'].default = principalTimezone


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/config.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/formatter/config.txt
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/config.txt	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/config.txt	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,62 @@
+config.py - load configuration from zope.conf <product-config z3ext.formatter>
+
+By default it uses this settings
+
+<product-config z3ext.formatter>
+  timezone UTC
+  timezoneFormat 2
+  principalTimezone true
+</product-config>
+
+Usually initFormatter() function is colled during IDatabaseOpenedEvent event,
+we simply call it directly:
+
+   >>> from z3ext.formatter.config import initFormatter
+   >>> initFormatter(None)
+
+Now we can get IFormatterConfiglet utility
+
+   >>> from zope.component import getUtility
+   >>> from zope.interface.verify import verifyObject
+   >>> from z3ext.formatter.interfaces import IFormatterConfiglet
+
+   >>> IFormatterConfiglet['timezone'].default
+   u'US/Pacific'
+
+   >>> IFormatterConfiglet['timezoneFormat'].default
+   2
+
+   >>> IFormatterConfiglet['principalTimezone'].default
+   True
+
+
+Now let's emulate <product-config>
+
+   >>> from zope.app.appsetup import product
+   >>> product._configs['z3ext.formatter'] = {
+   ...   'timezone': u'UTC', 'timezoneFormat': '2', 'principalTimezone': 'false'}
+
+   >>> initFormatter(None)
+
+   >>> IFormatterConfiglet['timezone'].default
+   u'UTC'
+
+   >>> IFormatterConfiglet['timezoneFormat'].default
+   2
+
+   >>> IFormatterConfiglet['principalTimezone'].default
+   False
+
+
+If we supply wrong values config will use default values
+
+   >>> product._configs['z3ext.formatter'] = {
+   ...   'timezone': u'wrong', 'timezoneFormat': 'wrong'}
+
+   >>> initFormatter(None)
+
+   >>> IFormatterConfiglet['timezone'].default
+   u'US/Pacific'
+
+   >>> IFormatterConfiglet['timezoneFormat'].default
+   2

Added: z3ext.formatter/trunk/src/z3ext/formatter/configure.zcml
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/configure.zcml	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/configure.zcml	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,57 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   xmlns:z3ext="http://namespaces.zope.org/z3ext"
+   xmlns:tales="http://namespaces.zope.org/tales"
+   xmlns:browser="http://namespaces.zope.org/browser"
+   i18n_domain="z3ext">
+
+  <autoinclude package="z3ext.formatter" />
+
+  <!-- zope.conf configuration -->
+  <subscriber handler=".config.initFormatter" />
+
+  <!-- formatter: tales expresison -->
+  <tales:expressiontype
+     name="formatter"
+     handler=".expression.FormatterExpression" />
+
+  <!-- formatters -->
+  <adapter name="date" factory=".dformatter.DateFormatterFactory" />
+  <adapter name="dateTime" factory=".dtformatter.DatetimeFormatterFactory" />
+  <adapter name="fancyDatetime"
+	   factory=".fancydatetime.FancyDatetimeFormatterFactory" />
+
+  <!-- formatter configlet -->
+  <z3ext:configlet
+     name="system.formatter"
+     schema=".interfaces.IFormatterConfiglet"
+     title="Portal formatters"
+     description="Configure portal formatters.">
+    <allow interface=".interfaces.IFormatterConfiglet" />
+  </z3ext:configlet>
+
+  <browser:icon
+     name="zmi_icon"
+     for=".interfaces.IFormatterConfiglet"
+     file="preferences-formatter.png" />
+
+  <!-- vocabularies -->
+  <utility
+     name="Timezones"
+     factory=".vocabulary.Timezones" />
+
+  <!-- Registering documentation with API doc -->
+  <configure
+     xmlns:apidoc="http://namespaces.zope.org/apidoc"
+     xmlns:zcml="http://namespaces.zope.org/zcml"
+     zcml:condition="have apidoc">
+
+    <apidoc:bookchapter
+       id="z3ext-formatter"
+       title="z3ext.formatter - formatter TALES expression"
+       doc_path="README.txt"
+       parent="z3ext" />
+
+  </configure>
+
+</configure>

Added: z3ext.formatter/trunk/src/z3ext/formatter/dformatter.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/dformatter.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/dformatter.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,50 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" ``date`` formatter implementation
+Author: Nikolay Kim <fafhrd91 at gmail.com>
+
+$Id$
+"""
+
+from zope import interface, component
+from zope.interface.common.idatetime import ITZInfo
+from zope.publisher.interfaces.http import IHTTPRequest
+
+from interfaces import IFormatter, IFormatterFactory
+
+
+class DateFormatter(object):
+    interface.implements(IFormatter)
+
+    def __init__(self, request, *args):
+        try:
+            self.tp = args[0]
+        except:
+            self.tp = 'medium'
+
+        self.formatter = request.locale.dates.getFormatter('date', self.tp)
+
+    def format(self, value):
+        return self.formatter.format(value)
+
+
+class DateFormatterFactory(object):
+    component.adapts(IHTTPRequest)
+    interface.implements(IFormatterFactory)
+
+    def __init__(self, request):
+        self.request = request
+        
+    def __call__(self, *args, **kw):
+        return DateFormatter(self.request, *args)


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/dformatter.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/formatter/dtformatter.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/dtformatter.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/dtformatter.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,77 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" ``dateTime`` formatter implementation
+Author: Nikolay Kim <fafhrd91 at gmail.com>
+
+$Id$
+"""
+from pytz import utc, timezone
+from datetime import datetime
+
+from zope import interface, component
+from zope.component import getUtility
+from zope.interface.common.idatetime import ITZInfo
+from zope.publisher.interfaces.http import IHTTPRequest
+
+from interfaces import IFormatter, IFormatterFactory, IFormatterConfiglet
+
+
+class DatetimeFormatter(object):
+    interface.implements(IFormatter)
+
+    def __init__(self, request, *args):
+        try:
+            self.tp = args[0]
+        except:
+            self.tp = 'medium'
+
+        self.request = request
+        self.formatter = request.locale.dates.getFormatter('dateTime', self.tp)
+
+    def format(self, value):
+        formatter = self.formatter
+
+        configlet = getUtility(IFormatterConfiglet)
+        tz = None
+        if configlet.principalTimezone:
+            tz = ITZInfo(self.request.principal, None)
+
+        if tz is None:
+            tz = timezone(configlet.timezone)
+
+        if value.tzinfo is None:
+            value = datetime(value.year, value.month, value.day, value.hour,
+                             value.minute, value.second, value.microsecond, utc)
+
+        value = value.astimezone(tz)
+
+        if configlet.timezoneFormat == 3:
+            if self.tp in ('medium', 'full'):
+                formatter.setPattern(
+                    formatter.getPattern().replace('z', '').strip())
+                formatted = formatter.format(value)
+                return u'%s %s'%(formatted, tz.zone)
+
+        return formatter.format(value)
+
+
+class DatetimeFormatterFactory(object):
+    component.adapts(IHTTPRequest)
+    interface.implements(IFormatterFactory)
+
+    def __init__(self, request):
+        self.request = request
+        
+    def __call__(self, *args, **kw):
+        return DatetimeFormatter(self.request, *args)


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/dtformatter.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/formatter/expression.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/expression.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/expression.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,58 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" ``formatter`` TALES expression
+Author: Nikolay Kim <fafhrd91 at gmail.com>
+
+$Id$
+"""
+
+from zope.component import queryAdapter
+from zope.proxy import removeAllProxies
+from zope.tales.expressions import PathExpr, simpleTraverse
+
+from interfaces import IFormatterFactory
+from interfaces import FormatterNotDefined, FormatterExpressionError
+
+
+class FormatterExpression(PathExpr):
+    """ formatter sytax:
+       formatter:<formatterName>,<formatterVar1>,<formatterVar2>,...:pathExpr """
+
+    def __init__(self, name, expr, engine, traverser=simpleTraverse):
+        parts = expr.split(':', 1)
+        try:
+            formatterName, pathExpr = parts[0], parts[1]
+        except IndexError:
+            raise FormatterExpressionError(expr)
+
+        args = formatterName.split(',')
+        self.formatterName = args[0]
+        self.formatterArgs = args[1:]
+
+        super(FormatterExpression, self).__init__(
+            name, pathExpr, engine, traverser=simpleTraverse)
+    
+    def __call__(self, econtext):
+        request = removeAllProxies(econtext.request)
+
+        factory = queryAdapter(
+            request, IFormatterFactory, name=self.formatterName)
+
+        if factory is None:
+            raise FormatterNotDefined(self.formatterName)
+
+        formatter = factory(*self.formatterArgs)
+
+        value = super(FormatterExpression, self).__call__(econtext)
+        return formatter.format(value)


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/expression.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/formatter/fancydatetime.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/fancydatetime.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/fancydatetime.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,100 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" ``fancyDatetime`` formatter implementation
+
+$Id$
+"""
+
+from pytz import utc, timezone
+from datetime import datetime
+from zope import interface, component
+from zope.component import getUtility
+from zope.interface.common.idatetime import ITZInfo
+from zope.publisher.interfaces.http import IHTTPRequest
+
+from i18n import _
+from interfaces import IFormatter, IFormatterFactory, IFormatterConfiglet
+
+
+class FancyDatetimeFormatter(object):
+    interface.implements(IFormatter)
+
+    def __init__(self, request, *args):
+        try:
+            self.tp = args[0]
+        except:
+            self.tp = 'medium'
+
+        self.request = request
+        self.formatter = request.locale.dates.getFormatter('dateTime', self.tp)
+
+    def format(self, value):
+        formatter = self.formatter
+
+        configlet = getUtility(IFormatterConfiglet)
+        tz = None
+        if configlet.principalTimezone:
+            tz = ITZInfo(self.request.principal, None)
+
+        if tz is None:
+            tz = timezone(configlet.timezone)
+
+        if value.tzinfo is None:
+            value = datetime(value.year, value.month, value.day, value.hour,
+                             value.minute, value.second, value.microsecond, utc)
+
+        value = value.astimezone(tz)
+
+        timezoneFormat = configlet.timezoneFormat
+
+        d1 = datetime.now(utc).date()
+        d2 = value.astimezone(utc).date()
+
+        delta = d1 - d2
+
+        if delta.days == 0:
+            pattern = formatter.getPattern()
+            pos = pattern.find('h')
+            if pos < 0:
+                pos = pattern.find('H')
+
+            formatter.setPattern("'%s '"%_(u'Today at') + pattern[pos:])
+
+        if delta.days == 1:
+            pattern = formatter.getPattern()
+            pos = pattern.find('h')
+            if pos < 0:
+                pos = pattern.find('H')
+
+            formatter.setPattern("'%s '"%_(u'Yesterday at') + pattern[pos:])
+
+        if timezoneFormat == 3:
+            if self.tp in ('full',):
+                formatter.setPattern(
+                    formatter.getPattern().replace('z', '').strip())
+                formatted = formatter.format(value)
+                return u'%s %s'%(formatted, tz.zone)
+
+        return formatter.format(value)
+
+
+class FancyDatetimeFormatterFactory(object):
+    component.adapts(IHTTPRequest)
+    interface.implements(IFormatterFactory)
+
+    def __init__(self, request):
+        self.request = request
+        
+    def __call__(self, *args, **kw):
+        return FancyDatetimeFormatter(self.request, *args)


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/fancydatetime.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/formatter/i18n.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/i18n.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/i18n.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,19 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" i18n
+
+$Id$
+"""
+from zope.i18nmessageid import MessageFactory
+_ = MessageFactory('z3ext')


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/i18n.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/formatter/interfaces.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/interfaces.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/interfaces.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,65 @@
+##############################################################################
+#
+# 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.formatter interfaces
+
+$Id$
+"""
+import vocabulary
+from zope import schema, interface
+
+from i18n import _
+
+
+class FormatterNotDefined(Exception):
+    """ """
+
+class FormatterExpressionError(Exception):
+    """ """
+
+
+class IFormatterConfiglet(interface.Interface):
+
+    timezone = schema.Choice(
+        title = _(u'Timezone'),
+        description = _(u'Portal timezone.'),
+        default = 'US/Pacific',
+        vocabulary = vocabulary.timezones,
+        required = False)
+
+    timezoneFormat = schema.Choice(
+        title = _(u'Timezone format'),
+        description = _(u'Timezone format'),
+        default = 3,
+        vocabulary = vocabulary.timezonesOptions,
+        required = False)
+
+    principalTimezone = schema.Bool(
+        title = _(u'Use principal timezone'),
+        description = _(u'Render datetime with user selected timezone.'),
+        default = True,
+        required = False)
+
+
+class IFormatterFactory(interface.Interface):
+    """ formatter factory """
+
+    def __call__(*args):
+        """ create formatter """
+
+
+class IFormatter(interface.Interface):
+    """ locale formatter """
+
+    def format(value):
+        """ format value """


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/interfaces.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/formatter/preferences-formatter.png
===================================================================
(Binary files differ)


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/preferences-formatter.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: z3ext.formatter/trunk/src/z3ext/formatter/tests.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/tests.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/tests.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,62 @@
+##############################################################################
+#
+# 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.formatter tests
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import unittest, doctest
+from zope import interface, schema
+from zope.component import provideAdapter
+from zope.testing.cleanup import cleanUp
+from zope.app.testing import setup
+
+from zope.app.pagetemplate.engine import Engine, TrustedEngine
+from zope.app.pagetemplate.metaconfigure import clear
+
+from z3ext.controlpanel.testing import setUpControlPanel
+
+from z3ext.formatter import dformatter, dtformatter, fancydatetime
+from z3ext.formatter.expression import FormatterExpression
+
+
+def setUp(test):
+    setup.placelessSetUp(True)
+    setup.setUpTraversal()
+    setUpControlPanel()
+
+    Engine.registerType(u'formatter', FormatterExpression)
+    TrustedEngine.registerType(u'formatter', FormatterExpression)
+
+    provideAdapter(dformatter.DateFormatterFactory, name='date')
+    provideAdapter(dtformatter.DatetimeFormatterFactory, name='dateTime')
+    provideAdapter(
+        fancydatetime.FancyDatetimeFormatterFactory, name='fancyDatetime')
+
+
+def tearDown(test):
+    setup.placelessTearDown()
+    clear()
+
+
+def test_suite():
+    return unittest.TestSuite((
+            doctest.DocFileSuite(
+                'README.txt',
+                setUp=setUp, tearDown=tearDown,
+                optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+            doctest.DocFileSuite(
+                'config.txt', setUp=setUp, tearDown=tearDown),
+            ))


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/tests.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/formatter/utils.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/utils.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/utils.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# 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.component import queryAdapter
+from interfaces import IFormatterFactory, FormatterNotDefined
+
+def getFormatter(request, name, *args):
+    factory = queryAdapter(request, IFormatterFactory, name=name)
+    if factory is None:
+        raise FormatterNotDefined(name)
+
+    return factory(*args)


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/utils.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3ext.formatter/trunk/src/z3ext/formatter/vocabulary.py
===================================================================
--- z3ext.formatter/trunk/src/z3ext/formatter/vocabulary.py	                        (rev 0)
+++ z3ext.formatter/trunk/src/z3ext/formatter/vocabulary.py	2008-03-25 12:12:41 UTC (rev 84923)
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" vocabularies
+
+$Id$
+"""
+import pytz
+from zope import interface
+from zope.schema.interfaces import IVocabularyFactory
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
+
+from i18n import _
+
+
+timezonesOptions = SimpleVocabulary(
+    [SimpleTerm(1, '1', _(u'No timezone')),
+     SimpleTerm(2, '2', _(u'Number of hours')),
+     SimpleTerm(3, '3', _(u'Timezone name'))])
+
+timezones = SimpleVocabulary(
+    [SimpleTerm(unicode(tz), tz, unicode(tz)) for tz in pytz.common_timezones])
+
+
+class Timezones(object):
+    interface.implements(IVocabularyFactory)
+
+    def __call__(self, context):
+        return timezones


Property changes on: z3ext.formatter/trunk/src/z3ext/formatter/vocabulary.py
___________________________________________________________________
Name: svn:keywords
   + Id



More information about the Checkins mailing list