[Zope3-checkins] CVS: Products3/demo/formatns - __init__.py:1.1 configure.zcml:1.1 interfaces.py:1.1

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Sep 16 18:18:56 EDT 2003


Update of /cvs-repository/Products3/demo/formatns
In directory cvs.zope.org:/tmp/cvs-serv14796

Added Files:
	__init__.py configure.zcml interfaces.py 
Log Message:
This is a demo product on how to develop your own TALES namespaces, which 
I imagine will be extremly useful. Furthermore, I think it is currently 
also the easiest way to extend Zope 3 in a very powerful way.

But please, do not misuse this feature!


=== Added File Products3/demo/formatns/__init__.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""'format' TALES Namespace Adapter implementation

$Id: __init__.py,v 1.1 2003/09/16 22:18:56 srichter Exp $
"""
from zopeproducts.demo.formatns.interfaces import IFormatTalesAPI
from zope.interface import implements
from zope.security.proxy import trustedRemoveSecurityProxy
from zope.tales.interfaces import ITALESFunctionNamespace


class FormatTalesAPI(object):

    implements(IFormatTalesAPI, ITALESFunctionNamespace)

    def __init__(self, context):
        self.context = context

    def setEngine(self, engine):
        self._engine = engine
        self.locale = trustedRemoveSecurityProxy(engine.vars['request']).locale

    def shortDate(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getDateFormatter('short').format(self.context)
        
    def mediumDate(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getDateFormatter('medium').format(self.context)
        
    def longDate(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getDateFormatter('long').format(self.context)

    def fullDate(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getDateFormatter('full').format(self.context)

    def shortTime(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getTimeFormatter('short').format(self.context)

    def mediumTime(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getTimeFormatter('medium').format(self.context)

    def longTime(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getTimeFormatter('long').format(self.context)

    def fullTime(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getTimeFormatter('full').format(self.context)

    def shortDateTime(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getDateTimeFormatter('short').format(self.context)

    def mediumDateTime(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getDateTimeFormatter('medium').format(self.context)

    def longDateTime(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getDateTimeFormatter('long').format(self.context)

    def fullDateTime(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getDateTimeFormatter('full').format(self.context)

    def decimal(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getNumberFormatter('decimal').format(self.context)

    def percent(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getNumberFormatter('percent').format(self.context)

    def scientific(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getNumberFormatter('scientific').format(self.context)

    def currency(self):
        """See zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"""
        return self.locale.getCurrencyFormatter().format(self.context)


=== Added File Products3/demo/formatns/configure.zcml ===
<configure 
    xmlns="http://namespaces.zope.org/zope"
    xmlns:tales="http://namespaces.zope.org/tales">

  <adapter
      for="*"
      provides="zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"
      factory=".FormatTalesAPI" />

  <tales:namespace 
      prefix="format"
      interface="zopeproducts.demo.formatns.interfaces.IFormatTalesAPI"/>

</configure>


=== Added File Products3/demo/formatns/interfaces.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""'format' TALES Namespace Interfaces

$Id: interfaces.py,v 1.1 2003/09/16 22:18:56 srichter Exp $
"""
from zope.interface import Interface


class IFormatTalesAPI(Interface):

    def shortDate(self):
        """Returns the short date using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def mediumDate(self):
        """Returns the medium date using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """
        
    def longDate(self):
        """Returns the long date using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def fullDate(self):
        """Returns the full date using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def shortTime(self):
        """Returns the short time using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def mediumTime(self):
        """Returns the medium time using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def longTime(self):
        """Returns the long time using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def fullTime(self):
        """Returns the full time using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def shortDateTime(self):
        """Returns the short datetime using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def mediumDateTime(self):
        """Returns the  datetime using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def longDateTime(self):
        """Returns the long datetime using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def fullDateTime(self):
        """Returns the full datetime using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def decimal(self):
        """Returns the full datetime using the user's locale.

        The context of this namespace must be a datetime object, otherwise an
        exception is raised.
        """

    def percent(self):
        """Returns the floating point as percentage using the user's locale.

        The context of this namespace must be a floating point object,
        otherwise an exception is raised.
        """

    def scientific(self):
        """Returns the floating point in scientific notation using the user's
        locale.

        The context of this namespace must be a floating point object,
        otherwise an exception is raised.
        """

    def currency(self):
        """Returns the floating point as currency using the user's locale.

        The context of this namespace must be a floating point object,
        otherwise an exception is raised.
        """

    




More information about the Zope3-Checkins mailing list