FAQ - Configuration and Setup

Return to FAQ index

1   How do I create a ZServer instance (instead of the default twisted instance) ?

Ref: http://mail.zope.org/pipermail/zope3-dev/2007-February/021678.html

>>> Is there a non-twisted main.py or does zope.app.twisted.main get used
>>> for all Zope 3 instances?
>>
>> zope.app.server.main
>
> How do you switch between the two?
mkzopeinstance creates a twisted instance (default)
mkzopeinstance --zserver creates a zope.server instance

2   How do I disable the url selection of the skin?

FIXME: override the ++skin++ namespace traversal?

3   How do I set up z3c.traverser and zope.contentprovider?

z3c.traverser and zope.contentprovider are helpful packages with good and clear doctests. It takes not too much time to get up and running with them. However the packages do not include an example of how to configure your new useful code into your project. It is clear from the doctests (and from your own doctests writen while making and testing your own code) what needs to be configured. But if you are like me and it all isn't yet quite second-nature, it isn't clear how it can be configured. So, for z3c.traverser:

<!-- register traverser for app -->
<view
  for=".IMallApplication"
  type="zope.publisher.interfaces.browser.IBrowserRequest"
  provides="zope.publisher.interfaces.browser.IBrowserPublisher"
  factory="z3c.traverser.browser.PluggableBrowserTraverser"
  permission="zope.Public"
  />

<!-- register traverser plugins -->
<!-- my own plugin -->
<subscriber
  for=".IMallApplication
       zope.publisher.interfaces.browser.IBrowserRequest"
  provides="z3c.traverser.interfaces.ITraverserPlugin"
  factory=".traverser.MallTraverserPlugin"
/>
<!-- and traverser package container traverser -->
<subscriber
  for=".IMallApplication
       zope.publisher.interfaces.browser.IBrowserRequest"
  provides="z3c.traverser.interfaces.ITraverserPlugin"
  factory="z3c.traverser.traverser.ContainerTraverserPlugin"
/>

And for zope.contentprovider:

<!-- register named adapter for menu provider -->
<adapter
  provides="zope.contentprovider.interfaces.IContentProvider"
  factory="tfws.menu.provider.MenuProvider"
  name="tfws.menu"
  />

<!-- this does the directlyProvides -->
<interface
  interface="tfws.menu.provider.IMenu"
  type="zope.contentprovider.interfaces.ITALNamespaceData"
  />

4   How do I declare global constants in ZCML?

Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004381.html

You could just use the <utility> directive, and group your constants into logical chunks.

interfaces.py:

class IDatabaseLoginOptions(Interface):
     username = Attribute()
     password = Attribute()

config.py:

class DatabaseLoginOptions(object):
     implements(IDatabaseLoginOptions)
     username = 'foo'
     password = 'bar'

configure.zcml:

<utility factory=".config.DatabaseLoginOptions" />

used:

opts = getUtility(IDatabaseLoginOptions)

Obviously, this is a bit more work than just declaring some constants in ZCML, but global constants suffer the same problems whether they're defined in Python or XML. Parts of your application are making assumptions that they are there, with very specific names, which are not type checked.

5   How can I register a content provider without using viewlet managers?

You need to create and register simple adapter for object, request and view that implements the IContentProvider? interface:

class LatestNews(object):

    implements(IContentProvider)
    adapts(Interface, IDefaultBrowserLayer, Interface)

    def __init__(self, context, request, view):
        self.context = context
        self.request = request
        self.__parent__ = view

    def update(self):
        pass

    def render(self):
        return 'Latest news'

In the ZCML:

<adapter name="latestNews"
         for="* zope.publisher.interfaces.browser.IDefaultBrowserLayer *"
         provides="zope.contentprovider.interfaces.IContentProvider"
         factory=".LatestNews" />

Then you can use it in your TAL templates just like this:

<div tal:content="provider latestNews" />

Also, you may want to pass some parameters via TAL. For info on how to do this, read documentation in the zope.contentprovider. If you want to bind some content provider to some skin, change IDefaultBrowserLayer? to your skin interface.

6   How do I use the Zope 3 WSGI application object?

Ref: http://blog.d2m.at/2006/09/23/zope3-and-wsgi-integration/

for an example of integrating the Zope3 WSGI application with a standard WSGI server

7   How do I serve out static content in zope3?

Ref: http://zope3.pov.lt/irclogs/%23zope3-dev.2006-10-02.log.html

See the ZCML directives <resource> and <resourceDirectory> they let you publish static files through Zope

11   How do I make my project (or a third party project) appear in the APIDOC?

Add the following in your apidoc.zcml or configure.zcml:

<apidoc:rootModule module="myproject" />

If it does not show up, add the following:

<apidoc:moduleImport allow="true" />

12   How can I determine (in code) if the instance is running in devmode or not?

from zope.app.appsetup.appsetup import getConfigContext

   def is_devmode_enabled():
       """Is devmode enabled in zope.conf?"""
       config_context = getConfigContext()
       return config_context.hasFeature('devmode')



( 97 subscribers )