On Fri, 16 Jun 2000, Charlie Derr wrote:

> Jeff wrote:
> ~ As explained above, this advantage is shared by Python Products also. You
> ~ do *not* want to write application logic with DTML. At a minimum, use
> ~ Python Methods. Otherwise, use Python.
> ~
> Let me apologize in advance because i think this is going to turn out to be
> a really stupid question.  I'm never gonna know the answer if i don't ask it
> though. :-\
> I've seen this mentioned a lot (advice not to write application logic in
> DTML).  If one wants to use pure python (and not Products and not external
> methods) to create complex actions/relationships, then where does one place
> this code?  Obviously i can litter my DTML with python expressions, but this
> seems to be what is being  recommended against strongly.  Is there a way to
> use python "correctly" without writing a product and without encapsulating
> it in an external method?

You have two choices:

  1) Use PythonMethods, found at:


     These work like DTML Methods, only you write them in Python. They are
     relatively safe, also.

  2) Create a base class in Python, register it with Zope as a ZClass
     Base, and specify it as a parent class to your ZClass.


       FILE: TestBase.py
       class TestBase:

           """My ZClass Base class."""
           def __init__(self):
               self.foo = 'Foo'

           def getFoo(self):
               return self.foo

           def setFoo(self, value):
               self.foo = value

       def initialize(context):

       FILE: __init__.py
       import TestBase
       def initialize(context):

     Put these two files in your lib/python/Products/TestBase directory.
     Then, restart your Zope.

     Now, add a new product called Test. Inside it, create a ZClass called
     'Test' with a meta-type of 'Test'. Specify TestBase as the base

     Inside the Test ZClass, create a DTML Method called index_html. Give
     it the following contents:

       <dtml-var standard_html_header>

       Initial foo: <dtml-var getFoo>

       <dtml-call expr="setFoo('Hello, world.')
       New foo: <dtml-var getFoo>

       <dtml-var standard_html_footer>

     Create an instance of the Test ZClass, and view its index_html.


Hope this helps,

>       tesmia,
>               ~c


Jeff K. Hoffman                               704.849.0731 x108
Chief Technology Officer                      mailto:[EMAIL PROTECTED]
Going Virtual, L.L.C.                         http://www.goingv.com/

Zope maillist  -  [EMAIL PROTECTED]
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-dev )

Reply via email to