[Zope3-Users] Re: ZopeX3 Component Architecture in comparision to MVC - general question/example

Darryl Cousins darryl at darrylcousins.net.nz
Wed Mar 1 00:02:26 EST 2006


On Tue, 2006-02-28 at 17:52 +0100, Lennart Regebro wrote:
> On 2/28/06, Reinhold Strobl <reinhold.strobl at gmx.net> wrote:
> > Thanks for the reply. But how would you implement previously described task with
> > the calculator?
> 
> I would implement it as a view on whatever object I want to view it
> on. Which may even be "*", that is any object.

Hi Reinhold,

Here's a go at answering your problem. I gather you don't even need a
component as such - just a piece of code to perform a calculation. I
borrowed a technique from SchoolBell which may help. I think it may help
because it provides a way of performing any variety of python code
within a tal template without using python in the template. Any method
added to TFWSAPI can be accessed in tal with 'tfws:mymethod'. I've not
used XMLRPC calls with Zope so I'm not sure how it will translate. Good
luck.

Best regards,
Darryl

  <!-- gives all sorts of lovely custom TAL expressions -->
  <zope:adapter
      for="*"
      name="tfws"
      provides="zope.app.traversing.interfaces.IPathAdapter"
      factory=".tfwsapi.TFWSAPI"
      />

class TFWSAPI(object):
    """TALES function namespace for TFWS specific actions.

    Borrowed from SchoolBell.

    """
    implements(IPathAdapter, ITALESFunctionNamespace)

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

# as example
    def authenticated(self):
        """Check whether context is an authenticated principal.

        Sample usage in a page template:

            <div tal:define="user request/principal">
            <span tal:condition="user/tfws:authenticated"
                  tal:replace="user/title">
              User title
            </span>
            <span tal:condition="not:user/tfws:authenticated">
              Anonymous
            </span></div>

        """
        if not IPrincipal.providedBy(self.context):
            raise TypeError("tfws:authenticated can only be applied"
                            " to a principal")
        return not IUnauthenticatedPrincipal.providedBy(self.context)
    authenticated = property(authenticated)

> 
> --
> Lennart Regebro, Nuxeo     http://www.nuxeo.com/
> CPS Content Management     http://www.cps-project.org/
> _______________________________________________
> Zope3-users mailing list
> Zope3-users at zope.org
> http://mail.zope.org/mailman/listinfo/zope3-users
-- 
Darryl Cousins
Tree Fern Web Services (NZ) Ltd
http://www.treefernwebservices.co.nz/



More information about the Zope3-users mailing list