FAQ2007
Frequently Asked Questions about Zope 3
- 1 What is Zope 3?
- 2 Why Zope 3?
- 3 What is Zope Foundation?
- 4 Which Python version is required?
- 5 What version of ZODB does Zope 3 use?
- 6 What is the license of Zope 3?
- 7 What is the component architecture?
- 8 How can I help?
- 9 Is there a tutorial?
- 10 Is there API available online?
- 11 Is Zope 3 stable enough to be used in production enviroment?
- 12 Any pointers to resources?
- 13 How do I check out a project/package from Zope subversion repository?
- 14 How to upgrade from one minor release to another?
- 15 How to validate two or more fields simultaneously?
- 16 How to run a particular test from a package?
- 17 What's the deal with the '/@@' syntax?
- 18 How to test file upload using zope.testbrowser?
- 19 How to create RSS feeds?
- 20 How to record a session?
- 21 Should I use __docformat___ = 'restructuredtext' in Zope3?
- 22 How to get the parent of location?
- 23 How to disable the url selection of the skin?
- 24 How to set content type header for a HTTP request?
- 25 How to make AddForms with formlib?
- 26 How to load a form without resetting values in formlib?
- 27 How to give unique name for an object within a container?
- 28 How to add catalog through program, using API?
- 29 What is ForbiddenAttribute exception/error?
- 30 How to know if a principal has the right permissions?
- 31 Which psycopg works with Zope3?
- 32 Are ContainerTypesConstraint & ItemTypePrecondition deprecated?
- 33 Where is zope.app.workflow?
- 34 "order" attribute not in browser:menuItem directive:
- 35 utf-8 error in i18nfile
- 36 TALES root variable
- 37 Configuring z3c.traverser and zope.contentprovider
- 38 nextUrl(), passing state in formlib
- 39 How to use ZCML for defining global constants?
- 40 How to use multiple schema in forms using formlib with some fields have the same name?
- 41 Is there any viewlet demos available?
- 42 How to register a content provider without viewlet managers ?
- 43 When I modify one class in my source code, I need always to restart zope server?
- 44 A CRUD (create/read/update/delete) example?
- 45 How to use ZPT macros dynamically?
- 46 How to use the Zope 3 WSGI application object
- 47 How do dotted package names (like dotted.name) work?
- 48 How to use different skins for users?
- 49 Is there a function with which I can get the url of a zope object?
- 50 How to sort BTreeContainer objects?
- 51 How to get parameters in a request?
- 52 How to use Reportlab threadsafely?
- 53 Why isn't my object getting added to the catalog?
- 54 How to handle static content in zope3?
- 55 I added a constrain with 'contains()' and now my forms don't work
- 56 When running $instance/bin/runzope zlib import error appears?
- 57 Is webdav source server available in Zope 3?
- 58 How do I logout from Zope 3 Management Interface (ZMI) ?
- 59 How to get more details about system errors in the browser itself?
- 60 How to add custom interfaces to prexisting components/classes?
- 61 How can I use MultiSelectWidget with formlib?
- 62 Will Zope 3 be compatible with Zope 2 products?
- 63 What's this Five thing I've heard of?
- 64 Will I have to rewrite my Zope 2 Product?
- 65 What will be the roadmap for RDBMS support? Will it be similar to Zope2.x?
- 66 What changes will be done to the PropertyManager?
- 67 Will the class 'Folder' store the content in BTrees?
- 68 Which changes will be done to ZCatalog?
- 69 Will the UserManagement be changed so that a role can include another role?
- 70 Will the request and response be written with capital letters?
- 71 What about ZSQL Methods? Can't it support standard SQL like other scripting languages?
- 72 Will Zope 3 support DTML?
- 73 Will Zope 3 support Python scripts?
- 74 Will Zope 3 be compatible with CMF?
- 75 Is my good friend Acquisition going away?
- 76 Can I still whip up a presentation template TTW and view my content object with it?
- 77 Can I allow for the possibility of somebody overriding my filesystem based product's presentation templates TTW?
- 78 Can I change the default lookup order for methods/attributes/whatever?
- 79 What's the difference between service and utility?
- 80 Will methods and attributes with underscores be reachable TTW in Zope 3?
- 81 Do I still define a method as public using doc string? (I find this cumbersome.)
- 82 Having defined and registered a PAU in the root of the site, I cannot log in as a user with zope.Manager permission anymore! Help!
- 83 How to setup authentication with users and permissions ?
- 84 How to setup authentication with users and permissions through ldap?
- 85 I get a Server Error page when doing something that should work. How do I debug this?
- 86 I cannot see source when debugging eggified code
- 87 How to make a form field display only?
- 88 How to create a ZServer instance (instead of the default twisted instance) ?
- 89 How to avoid warning to replace: <include package="zope.app" /> with: <include package="zope.app.zcmlfiles" /> ?
- 90 How to get IRequest object in event handler ?
- 91 Is there any single formlib widget for several fields ?
- 92 How to define attributes in a schema that reference other interfaces ?
- 93 How to use ZCML overrides in buildout in site.zcml for zc.zope3recipes:app recipe ?
- 94 What is the difference between browser:view and browser:page ?
- 95 Is there any tool to monitor ZODB activity ?
- 96 Any easy method to configure several classes with same permission ?
- 97 How to call a view in a doc test and test the rendering ?
- 98 How to create/customize a skin?
- 99 How write custom traversal in Zope 3 ?
- 100 How do I render a plaintext description without having the newlines removed ?
- 101 How to use ZODB blob ?
- 102 How do I automatically create some needed object at application startup?
General -------ZODB
1 What is Zope 3?
Zope 3 is a production ready free/open source web application framework written in the Python programming language. Zope 3 provides a component architecture, transactional object database, tightly integrated security model and many other features.
Zope 3 is coming from the Zope community which is started around 1998. Initially Zope's core technologies were designed by Zope Corporation. The development of Zope 3 started in late 2001. In November 2004, Zope 3 was released. Zope 3 is a complete rewrite that only preserves the original ZODB object database. The design of Zope 3 is driven by the needs of large companies. It is directly intended for enterprise web application development using the newest development paradigms. Extreme programming development process has a real influence in Zope 3 development. Automated testing is a major strength of Zope 3. Sprints were introduced to help accelerate Zope 3 development. In 2006 Zope foundation was formed to help organize and formalize the relationships with the Zope community.
2 Why Zope 3?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-August/004205.html
Zope 3 has:
- WSGI-compatible object publisher (zope.publisher)
- WSGI-enabled web server (zope.server) and twisted.web2 for server backend
- Object datbase (ZODB) for transparently persisting objects; comes with load-balancing support (ZEO).
- Component Architecture for making things pluggable very easily (zope.component)
- XML-configuration language for registering components (zope.configuration), not mandatory but pretty much standard
- Flexible security architecture with pluggable security policies (zope.security)
- Good unit, integration and functional testing frameworks (zope.testing, zope.testbrowser)
- XHTML-compliant templating language (zope.pagetemplate)
- Schema engine and automatic form generation machinery (zope.formlib)
- many more core and third-party packages that may already solve some of your problems. See http://svn.zope.org, for instance.
Zope 3 is:
- ZPL (BSD-ish license)
- soon to be owned by Zope Foundation
- written mostly by contributors, not just Zope Corporation.
- usable in pieces or in whole
3 What is Zope Foundation?
From http://foundation.zope.org:
The Zope Foundation has the goal to promote, maintain, and develop the Zope platform. It does this by supporting the Zope community. Our community includes the open source community of contributors to the Zope software, contributors to the documentation and web infrastructure, as well as the community of businesses and organizations that use Zope.
The Zope Foundation is the copyright holder of the Zope software and many extensions and associated software. The Zope Foundation also manages the zope.org website, and manages the infrastructure for open source collaboration.
For more details: http://foundation.zope.org/about.html
4 Which Python version is required?
Currently (for Zope 3.3 and 3.4) Python 2.4 is required, Python 2.5 is not supported yet. Even though Python 2.5 is not supported, you can run Zope 3 packages using Python 2.5. Python 2.5 will be officially supported when Zope 2 also run under that version.
5 What version of ZODB does Zope 3 use?
Right now Zope 3 is using ZODB 3. Zope 3.4 is using ZODB 3.8 .
ZODB 4 development has halted indefinitely because of lack of resources to support both versions. Even though many ZODB 4 features has back-ported to ZODB 3.
6 What is the license of Zope 3?
Zope 3 is licensed under Zope Public License, Version 2.1 (ZPL).
Since we also use some contributions from other projects, some parts of Zope 3 will have other licenses. See LICENSES.txt for more details.
7 What is the component architecture?
It's similar to other component architectures in that it lets you fit small pieces of functionality together. While Zope 2 has many parts welded together with inheritance, Zope 3 will let you take things apart and put them together like LEGO bricks(TM). See the Vision Statement, [Components]?, [Interfaces]?, and the Glossary.
8 How can I help?
If you're interested in helping and you have time, educate yourself on the component architecture and Zope 3 then volunteer to assist in your particular area of expertise. See HowToContribute for details.
11 Is Zope 3 stable enough to be used in production enviroment?
Zope 3 is used in several larger production sites already. Public applications include Launchpad, SchoolTool, Tiks and SIP. But there are several custom solutions written too. But the development of Zope 3 will probably never be done, it will continue untill our all needs meets :)
12 Any pointers to resources?
- This wiki
- http://apidoc.zope.org/++apidoc++/
- Zope 3 Base : http://codespeak.net/z3/
- IRC : #zope3-dev at irc.freenode.net , logs at : http://zope3.pov.lt/irclogs
- Users list (for development with Zope 3): zope3-users@zope.org, archives at : http://mail.zope.org/pipermail/zope3-users/
- Developers list (for development of Zope 3 itself) : zope3-dev@zope.org, archives at : http://mail.zope.org/pipermail/zope3-dev/
- Zope 3 book by Philipp von Weitershausen : http://worldcookery.com/
- Planet : http://planetzope.org/
- News letter : http://blog.planetzope.org/
- Zope Cookbook : http://zope-cookbook.org/
- http://del.icio.us/tag/zope3
- https://wiki.ubuntu.com/LearningZope3
- ZopeGuide
13 How do I check out a project/package from Zope subversion repository?
Ref: SettingUpAZope?3Sandbox
You can browse available projects here: http://svn.zope.org (in the package names, "zc" stands for "Zope Corporation", "z3c" stands for "Zope 3 Community")
Then, to check out Zope3 trunk anonymously:
svn co svn://svn.zope.org/repos/main/Zope3/trunk Zope3
Stable branches are available from : http://svn.zope.org/Zope3/branches (online) . And release tags from: http://svn.zope.org/Zope3/tags (online)
To check out Zope 3.3 stable branch:
svn co svn://svn.zope.org/repos/main/Zope3/branches/3.3 Zope33
14 How to upgrade from one minor release to another?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-August/004025.html
You can have more than one Zope 3 installed, e.g. you can install Zope 3.2.1 in parallel to 3.2.0 and switch your instance over to 3.2.1 (by editing the start scripts in $INSTANCE/bin). You can also install Zope 3.2.1 into the place where 3.2.0 was installed; your instance should continue to work. Such a thing isn't recommended when upgrading between major versions, though (3.2 to 3.3).
15 How to validate two or more fields simultaneously?
Consider a simple example, there is a person object. A person object has name, email and phone attributes. How do we implement a validation rule that says either email or phone have to exist, but not necissarily both.
First we have to make a callable object, either a simple function or callable instance of a class:
>>> def contacts_invariant(obj):
... if not (obj.email or obj.phone):
... raise Exception("At least one contact info is rquired")
Then define the person object's interface like this. Use the interface.invariant function to set the invariant:
>>> class IPerson(interface.Interface):
...
... name = interface.Attribute("Name")
... email = interface.Attribute("Email Address")
... phone = interface.Attribute("Phone Number")
...
... interface.invariant(contacts_invariant)
Now use validateInvariants method of the interface to validate:
>>> class Person(object): ... interface.implements(IPerson) ... ... name = None ... email = None ... phone = None >>> jack = Person() >>> jack.email = u"jack@some.address.com" >>> IPerson.validateInvariants(jack) >>> jill = Person() >>> IPerson.validateInvariants(jill) Traceback (most recent call last): ... Exception: At least one contact info is rquired
16 How to run a particular test from a package?
Go to your $ZOPE3INSTANCE/etc, then:
$ cd $HOME/myzope/etc $ ../bin/test.py -vpu --dir package/tests test_this_module
Here I assumed $HOME/myzope is your Zope3 instance directory. Replace 'package' with your package name.
17 What's the deal with the '/@@' syntax?
@@ is a shortcut for ++view++. (Mnemonically, it kinda looks like a pair of goggle-eyes)
To specify that you want to traverse to a view named "bar" of content object "foo", you could (compactly) say .../foo/@@bar instead of .../foo/++view++bar.
Note that even the '@@' is not necessary if container "foo" has no element named "bar" - it only serves to disambiguate between views of an object and things contained within the object.
18 How to test file upload using zope.testbrowser?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-July/003830.html
eg:-
>>> import StringIO
>>> myPhoto = StringIO.StringIO('my photo')
>>> control = user.getControl(name='photoForm.photo')
>>> fileControl = control.mech_control
>>> fileControl.add_file(myPhoto, filename='myPhoto.gif')
>>> user.getControl(name='photoForm.actions.add').click()
>>> imgTag =
'src="http://localhost/++skin++Application/000001/0001/1/photo"'
>>> imgTag in user.contents
True
19 How to create RSS feeds?
Refer http://kpug.zwiki.org/ZopeCreatingRSS (Taken from old zope-cookbook.org)
21 Should I use __docformat___ = 'restructuredtext' in Zope3?
Yes, if you are using ReStructuredText? in docstrings, the default is still structured text.
22 How to get the parent of location?
To get the parent of an object use zope.traversing.api.getParent(obj). To get a list of the parents above an object use zope.traversing.api.getParents(obj).
23 How to disable the url selection of the skin?
FIXME: override the ++skin++ namespace traversal?
24 How to set content type header for a HTTP request?
From IRC (http://zope3.pov.lt/irclogs/%23zope3-dev.2006-06-20.log.html):
Is there any way using the browser:page directive, that I can specify that the Type of a page rendered is not "text/html" but rather "application/vnd.mozilla.xul+xml"?
Use request.response.setHeader('content-type', ...)
25 How to make AddForms with formlib?
The view class:
# This is the mypackage.browser module
from zope.formlib import form
from mypackage.interfaces import IFruit
from mypackage.fruit import Fruit
class FruitAdd(form.AddForm):
form_fields = form.Fields(IFruit)
def create(self, data):
# applyChanges applies all changed fields named in form_fields
# to the object, taking the field values from data.
# In a new object, that's *all* fields.
fruit = Fruit()
form.applyChanges(fruit, self.form_fields, data)
return fruit
The zcml:
<browser:page
for="zope.app.container.interfaces.IAdding"
name="mypackage.Fruit"
class="mypackage.browser.FruitAdd"
permission="zope.ManageContent"
/>
<browser:addMenuItem
title="Fruit"
class="mypackage.fruit.Fruit"
view="mypackage.Fruit"
permission="zope.ManageContent"
/>
Ref: http://mg.pov.lt/blog/formlib-adding.html Ref: http://www.advogato.org/article/892.html
26 How to load a form without resetting values in formlib?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-July/003904.html
In 'create' or 'createAndAdd' method add 'self.form_reset = False' before the return. This suppresses resetting the form data.
27 How to give unique name for an object within a container?
first:
from zope.app.container.interfaces import INameChooser
Name will be assigned from 'create' or 'createAndAdd' methods, here is an eg:
def create(self, data):
mycontainer = MyObject()
mycontainer.value1 = data['value1']
anotherobj = AnotherObject()
anotherobj.anothervalue1 = data['anothervalue1']
namechooser = INameChooser(mycontainer)
name = chooser.chooseName('AnotherObj', anotherobj)
mycontainer[name] = anotherobj
return mycontainer
28 How to add catalog through program, using API?
Ref: http://zopetic.googlecode.com/svn/trunk/src/browser/collectorform.py
see this eg:
from zopetic.interfaces import ITicket
from zopetic.interfaces import ICollector
from zopetic.ticketcollector import Collector
from zope.app.intid.interfaces import IIntIds
from zope.app.intid import IntIds
from zope.component import getSiteManager
from zope.app.catalog.interfaces import ICatalog
from zope.app.catalog.catalog import Catalog
from zope.security.proxy import removeSecurityProxy
from zope.app.catalog.text import TextIndex
...
def create(self, data):
collector = Collector()
collector.description = data['description']
return collector
def add(self, object):
ob = self.context.add(object)
sm = getSiteManager(ob)
rootfolder = ob.__parent__
cat = Catalog()
rootfolder['cat'] = cat
if sm.queryUtility(IIntIds) is None:
uid = IntIds()
rootfolder['uid'] = uid
sm.registerUtility(removeSecurityProxy(uid), IIntIds, '')
pass
sm.registerUtility(removeSecurityProxy(cat), ICatalog, 'cat')
cat['description'] = TextIndex('description', ITicket)
self._finished_add = True
return ob
29 What is ForbiddenAttribute exception/error?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-August/004027.html
ForbiddenAttribute? are always (ALWAYS!!!) a lack of missing security declarations or code accessing stuff it shouldn't. Since accessing updateOrder seems reasonable to do, you're most definitely lacking a security declaration for it.
Zope will not allow anything if you don't declare it.
30 How to know if a principal has the right permissions?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-August/004201.html
The question is: how do I know if the current principal has permission for a specific view? Something like:
def canEdit(self):
ppal = self.request.principal
return canView('edit', INewsItem, ppal)
Use zope.security.canAccess and/or zope.security.canWrite
31 Which psycopg works with Zope3?
Zope 3.1 and 3.2 works with Psycopg v1.0.
FIXME: What about Psycopg v2.0 support in 3.3?
32 Are ContainerTypesConstraint & ItemTypePrecondition deprecated?
These two are not deprecated, but contains and containers functions are recommended.
33 Where is zope.app.workflow?
It has never been released with Zope 3, just as an add-on package. People are now encouraged to use zope.wfmc and zope.app.wfmc. There is also a z3lab extension specifically for document workflows.
34 "order" attribute not in browser:menuItem directive:
Q. I want to add a new view tab in the ZMI to be able to edit object attributes of some objects. So I'm adding a new menuItem in the zmi_views menu via ZCML with:
<browser:menuItem action="properties.html" for=".mymodule.IMyClass" title="properties" menu="zmi_views" permission="zope.ManageContent" order="2" />(MyClass? is just a derived Folder with custom attributes) The problem is: the new tab always appear in the first place. I would like to put it just after the "content" tab, not before. The "order" directive does not work for that. How can I reorder the tabs so that my new tab appears in the 2nd position?
The default implementation of menus sorts by interface first, and this item is most specific. See zope.app.publisher.browser.menu. If you do not like this behavior, you have to implement your own menu code.
35 utf-8 error in i18nfile
Q. Why do I always get an error when I try to add some utf-8 text into an i18nfile? I just add an i18nfile in the ZMI, then I chose a name and I set the contentType to "text/plain;charset=utf-8". If I enter some text with accents like "éà îî", I get a system error which says : UnicodeDecodeError?: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128). I don't get any error with a simple File object.
Okay, I18n file is a demo that is probably not well-developed. Don't use it. I will propose to not distribute it anymore. Noone is using it, so you are on your own finding the problem and providing a patch.
36 TALES root variable
Q. In a tales expression, where has the "root" context variable gone? In zope2, we could use "path:root/path/to/object" or "path:/path/to/object", but it doesn't work with Zope 3. How can we access some object with an absolute path?
Right, there is not root namespace by default. I actually have never needed this feature. However, you can write your own TALES namespace adapter, so that you can say: mynamespace:root. We sometimes write our own namespace adapters to this sort of thing.
37 Configuring 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" />
38 nextUrl(), passing state in formlib
Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004376.html
Question:
I have an add form (and later, an edit form) that may be invoked from a particular view among a few choices. That is, the user can be at @@foo or @@bar, click "add X" or "edit Y". When the form is successfully submitted (i.e. validated) I want to send the user back to @@foo or @@bar depending on where they originally came from.
The Edit Form implementation
class AddClub(zope.formlib.form.AddForm):
base_template =zope.formlib.form.AddForm.template
template = ViewPageTemplateFile('club_add.pt')
...
def referer(self):
return self.request.form.get('referer')\
or self.request.getHeader('HTTP_REFERER')
def nextURL(self):
return self.request.form.get('referer','..')
The template ('club_add.pt')
<div metal:use-macro="view/base_template/macros/main" >
<div metal:fill-slot="extra_info">
<input type="hidden" name="referer" value="" tal:attributes="value
view/referer" />
</div>
</div>
39 How to use ZCML for defining global constants?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004381.html
You could just use <utility>, and thereby 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.
40 How to use multiple schema in forms using formlib with some fields have the same name?
Use prefix argument:
form_fields = form.Fields(IFoo, prefix='foo') + form.Fields(IBar, prefix='bar')
41 Is there any viewlet demos available?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004395.html
See this : http://code.google.com/p/zope3demos/
42 How to register a content provider without 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.
43 When I modify one class in my source code, I need always to restart zope server?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004531.html
- Yes, you have to restart the server, though we recommend writing unit tests that take a lot less time than starting Zope)
- This probably isn't going to be implemented (it's very much non-trivial)
- No, you don't have to restart for changes in resources or Page Templates.
44 A CRUD (create/read/update/delete) example?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004248.html
Zope Object DataBase? (ZODB) is used in Zope, so it is simple Python:
Create: >>> from recipe import MyFolder, Recipe >>> folder = MyFolder() >>> recipe = Recipe() >>> folder['dead_chicken'] = recipe Read: >>> folder['dead_chicken'] <worldcookery.recipe.Recipe object at XXX> Update: >>> recipe = folder['dead_chicken'] >>> recipe.title = u'Dead chicken' >>> recipe.description = u'Beat it to death' Delete: >>> del recipe['dead_chicken']
45 How to use ZPT macros dynamically?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004259.html
First of all, don't use macros that much.
Use zope.contentprovider and zope.viewlet package that provides a lot more flexibility and is much more Zope-3-ish. See this question for examples: Is there any viewlet demos available?
Also look at the z3c.viewtemplate package. The viewtemplate package adds a template declaration in zcml. Effectively separating the page from the template. In the template declaration you can specify a macro to use for your viewlet very easily.:
<!-- This is a typical main content viewlet that actually implements
functionality for the blog page. -->
<browser:viewlet
name="bloglist"
for="myproject.interfaces.IBlog"
manager="myproject.browser.interfaces.IContent"
view="myproject.browser.blog.BlogPage"
class="myproject.browser.blog.BlogList"
layer="myproject.browser.IProjectLayer"
permission="zope.Public"
/>
<!-- This is the template is registered for the blog list viewlet. -->
<browser:template
template="blog.pt"
macro="bloglist"
layer="myproject.browser.skin.IProjectSkin"
for="myproject.browser.blog.BlogList"
/>
See Stephen Richters Blog for more details.
46 How to use the Zope 3 WSGI application object
Ref: http://blog.d2m.at/2006/09/23/zope3-and-wsgi-integration/
Example of integrating the Zope3 WSGI applicaton with a standard WSGI server
47 How do dotted package names (like dotted.name) work?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004538.html
- In /zopeinstance/lib/python, is the package actually in /zopeinstance/lib/python/dotted.name, or is it in /zopeinstance/lib/python/dotted/name?
The latter.
- What is the purpose of using the dotted name?
Short answer: package namespaces.
Long answer: Say you're creating a widget library. You could call your package simply "widget". But then if I create a widget library and called it "widget", too, we'd have a conflict and couldn't use them at the same time. That's why you call your package "george.widget" and I'll call my package "philikon.widget".
48 How to use different skins for users?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004315.html
Use layer attribute of browser:page tag, something like:
<browser:page
name="details.html"
permission="zope.AdminView"
layer="admin_layer"
template="admin_details.pt"/>
<browser:page
name="details.html"
permission="zope.UserView"
layer="user_layer"
template="user_details.pt"/>
49 Is there a function with which I can get the url of a zope object?
Ref: http://zope3.pov.lt/irclogs/%23zope3-dev.2006-09-25.log.html
Use:
zope.component.getMultiAdapter((the_object, the_request),
name='absolute_url')
or:
zope.traversing.browser.absoluteURL
50 How to sort BTreeContainer objects?
| Q: | Is there a way to sort the objects returned by values() from a zope.app.container.btree.BTreeContainer instance? |
|---|
Ref: http://zope3.pov.lt/irclogs/%23zope3-dev.2006-09-25.log.html
Use sorted builtin function (available from Python 2.4 onwards)
sorted(my_btree.values())
51 How to get parameters in a request?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-July/003876.html
Q. How to get parameter values in ttp://www.mysite.com/mypage?myOperation¶m1=vaue1¶m2=value2
class MyPageView(BrowserView):
def __call__(self):
if 'myOperation' in self.request.form:
param1 = self.request.form['param1']
param2 = self.request.form['param2']
do_something(param1, param2)
MyPageView? has to be either the default view asociated to the 'mypage' object or a view called 'mypage' associated to the RootFolder? object.
52 How to use Reportlab threadsafely?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004583.html
Use a mutex (a recursive lock makes things easier too):
lock = threading.RLock() lock.acquire() try: ... finally: lock.release()
53 Why isn't my object getting added to the catalog?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-May/003392.html
Is it adaptable to IKeyReference?? If you're using the ZODB, deriving from Persistent is enough.
54 How to handle 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
55 I added a constrain with 'contains()' and now my forms don't work
When using the function zope.app.container.constraints.containers inside your Interface definition you are adding a __parent__ Field to it. There is no registered widget for the IField? interface because it is too general.
That's the reason your forms have stopped working. You probably haven't omit the '__parent__' field from the form. If you are using formlib this can be easily done by using the FormFields?.omit() method.
If you are using ZCML to create a form you need to specify all the fields that need to be used in the form using the 'fields' attribute of the addform or editform directives
56 When running $instance/bin/runzope zlib import error appears?
Ref: http://mail.zope.org/pipermail/zope/2004-November/154739.html
When you compile Python, make sure you have installed zlib development library. In Debian 3.1 (Sarge) it is zlib1g-dev.
57 Is webdav source server available in Zope 3?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-September/004648.html
Yes, see this: http://svn.zope.org/zope.webdav/trunk
58 How do I logout from Zope 3 Management Interface (ZMI) ?
Ref: http://mail.zope.org/pipermail/zope3-users/2005-October/001112.html
Ref: http://svn.zope.org/*checkout*/Zope3/branches/3.3/src/zope/app/security/browser/loginlogout.txt
Logout is available from 3.3 onwards, but it is disabled by default. To enable add this line to $instance/etc/overrides.zcml:
<adapter factory="zope.app.security.LogoutSupported" />
59 How to get more details about system errors in the browser itself?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-November/004881.html
Use the Debug skin via ++skin++Debug or via ++debug++errors (the latter is better if you still want to see your own skin).
60 How to add custom interfaces to prexisting components/classes?
Ref: http://mail.zope.org/pipermail/zope3-users/2006-November/004918.html
You can do so with a little zcml:
<class class="zope.app.file.Image">
<implements interface=".interfaces.IBloggable" />
</class>
61 How can I use MultiSelectWidget with formlib?
from zope import interface, schema
class IPizzaToppings(interface.Interface):
toppings = schema.List(title=u'Toppings', required=False,
value_type=schema.Choice(__name__='topping', title=u'Topping',
vocabulary=schema.vocabulary.SimpleVocabulary.fromValues(['pepperoni',
'mushrooms', 'anchovies']) )
from zope.app.form.browser import MultiSelectWidget
class MyMultiSelectWidget(MultiSelectWidget):
def __init__(self, field, request):
super(MyMultiSelectWidget, self).__init__(
field, field.value_type.vocabulary, request)
class EditView(form.EditForm):
form_fields = formFields( IPizzaToppings )
form_fields['toppings'].custom_widget = MyMultiSelectWidget
Can also be used with MultiCheckboxWidget.
62 Will Zope 3 be compatible with Zope 2 products?
No, but since Zope 2.8.0, all Zope 2 releases contain most of Zope 3, so you can start using its benefits today. Zope 2 products can be written more and more like Zope 3 packages (which is to say, like regular Python packages).
At some point, Zope 2 may be nothing more than a particular configuration of Zope 3.
63 What's this Five thing I've heard of?
Five is the project that integrated Zope 3 into Zope 2. It is part of Zope 2 since Zope 2.8.0.
The name is a bit of a joke: Zope 2 + Zope 3 = Five.
More information can be found at the Five project website
Throgh Five almost all functionalities of Zope 3 are available in Zope 2.
64 Will I have to rewrite my Zope 2 Product?
You will not need to rewrite your product, just refactor it a bit (and throw out a lot of boilerplate in the process).
65 What will be the roadmap for RDBMS support? Will it be similar to Zope2.x?
RDBMS systems are already fully supported and are very similar to the RDB support in Zope 2. For connection objects however you now have a standardized connection URI, so you do not need to remember how to connect with every different database adapter.
The following database adapters have been implemented already: MySQLdbDA?, psycopgda (PostGreSQL?), pypgsqlda (PostGreSQL?), db2DA, informixDA, odbcDA, oracleDA, sapdbDA, sqliteDA, and sybaseDA. To write your own database adapter, see the NewREDBAdapter? recipe.
66 What changes will be done to the PropertyManager?
The concept of the PropertyManager? is replaced by Annotations. If an object is annotatable, then one can add any sort of data to the object and the AnnotationAdapter? knows how to store it.
I could imagine that someone will implement something similar to the PropertyManager?'s functionality on top of the basic Annotation support.
67 Will the class 'Folder' store the content in BTrees?
Yes, Folders already use BTrees? to store their subobjects.
68 Which changes will be done to ZCatalog?
There will be a new and shiny version of the catalog. But it makes use of a new utility called Integer Id, which can assign an integer to any object. Some interesting Indices have been implemented as well.
69 Will the UserManagement be changed so that a role can include another role?
Zope 3 has a much more flexible security model. Zope 3's security model knows only about Principals and does not care whether these principles are users, groups or even security certificates.
70 Will the request and response be written with capital letters?
No, in Zope 3 'request' and 'response' will be all lower case. There are now a couple of other interesting objects around, such as view and locale.
71 What about ZSQL Methods? Can't it support standard SQL like other scripting languages?
ZSQL methods have almost been ported one to one from Zope 2.
ZSQL Methods are not responsible for the SQL they contain, they merely forward the rendered SQL to the server. BTW, SQL Methods still support DTML for dynamic content.
72 Will Zope 3 support DTML?
Yes, there is a new version available in Zope 3. See DocumentTemplateMarkupLanguage2.
FIXME: what is the current status ? (October 16 2006)
73 Will Zope 3 support Python scripts?
Probably, although as of 2006-02-15 it hasn't been implemented yet. According to Jim:
They may be a little different than Zope 2 Python scripts...(they will be) used like Python functions, as you will generally want them to return things. The thinking is that Python scripts will be used for creating simple dynamic content. In addition ... there will *also* be (persistent TTW) Python modules used for creating software components. The details still need to be fleshed out and are open for debate.
74 Will Zope 3 be compatible with CMF?
No, but there will be many conversion scripts available to ensure a smooth transition. Also a lot of the CMF ideas will be folded directly into Zope 3.
dgeorgieff points out: You'll not need CMF in Z3 because all the core CMF features will be part of Z3.
75 Is my good friend Acquisition going away?
I expect implicit acquisition to fade from usage. Acquisition will still be important, but will be more explicit, more predictable, and ultimately, more useful.
76 Can I still whip up a presentation template TTW and view my content object with it?
Yes, the prefered model will be very similar to that used for CMF skins today. You'll be able to create presentation components TTW and register them for object interface (kinds of object) and associate them with skins.
You will also have the option of creating templates in the content space if you want, although, if the content you use doesn't do implicit acquisition, then the templates will only be usable in the folders that contain them.
77 Can I allow for the possibility of somebody overriding my filesystem based product's presentation templates TTW?
Absolutely, there will be TTW presentation services and you'll be able to override file-system-based view components with TTW components. There will also be services for managing components through the web. When you lookup a component, the lookup will be done in a "place-full" way, where place is expressed via an access context that is effectively the same as an acquisition context.
78 Can I change the default lookup order for methods/attributes/whatever?
Yes, there are components that are responsible for URL traversal. Simply find or write a component that implements the policy you want and register it in the configuration file or TTW.
79 What's the difference between service and utility?
Mainly, Services have been deprecated and no longer exist ;-) Existing services have been rewritten as Utilities.
For historical information, see DifferencesBetweenServicesAndUtilities. Originally, a utility was thought of a one-off thing, while a service was something that's carefully designed into the infrastructure. As an analogy, "mapping", "sequence" and "file-like object" are generic interfaces in Python, and could be considered somewhat like Zope services, while other things (e.g. frame objects, mmap objects, curses screen objects etc.) are one-off types/classes, similar to Zope utilities.
80 Will methods and attributes with underscores be reachable TTW in Zope 3?
In Zope 3, the standard Zope security policy probably won't look at names. So, for example, names with underscores aren't treated any differently than names without. In contrast to Zope 2, where names with leading underscores have security restrictions (they can't be called through the web, and they can't be called in Python Scripts).
81 Do I still define a method as public using doc string? (I find this cumbersome.)
No, the presence or length of doc strings won't be meaningful either, unless someone writes a component that makes them meaningful for an application.
82 Having defined and registered a PAU in the root of the site, I cannot log in as a user with zope.Manager permission anymore! Help!
Start zopedebug then unregister the utility. This will then let you log in as a user defined in principals.zcml.
Example (execute the following with zopedebug):
import transaction from zope.component import getSiteManager from zope.app.security.interfaces import IAuthentication lsm = getSiteManager(root) lsm.unregisterUtility(lsm.getUtility(IAuthentication), IAuthentication) transaction.commit()
When you exit zopedebug and start the server, you should be able to log in again using the user defined in principals.zcml. This should have the zope.Manager permission.
To avoid this happening, either assign a role to a user defined in the PAU or set up a folder beneath the root, make it a site and add and register the PAU there. Then you will still be able to log in to the root of the site and have full permissions.
83 How to setup authentication with users and permissions ?
Via the ZMI:
- go to the site manager (in the root, or in your folder/site)
- add a Pluggable Authentication Utility (name as you want, prefix empty)
- enter it and activate "no challenge if auth" and "session credentials" in this order
- add a Principal Folder (name and prefix as you want)
- return back to the PAU, and activate your Principal Folder
- Now, register both the PAU and the Principal Folder
- Then you can add users in your Principal Folder (aka Principals)
Via the API:
site = getSite() sm = site.getSiteManager() pau = PluggableAuthentication() sm['authentication'] = pau sm.registerUtility(pau, IAuthentication) users = PrincipalFolder() sm['authentication']['Users'] = users sm.registerUtility(users, IAuthenticatorPlugin, name="Users") pau.authenticatorPlugins = (users.__name__, ) pau.credentialsPlugins = ( "No Challenge if Authenticated", "Session Credentials" )
84 How to setup authentication with users and permissions through ldap?
Install ldapadapter and ldappas.
Via the ZMI:
- go to the site manager (in the root, or in your folder/site)
- add a ldapadapter and configure it for your ldapserver, test it
- Now, register it with some custom name (examle, ldapadapter.interfaces.ILDAPAdapter? utility named 'myldap')
- add a Pluggable Authentication Utility (name as you want, prefix empty)
- enter it and activate "no challenge if auth" and "session credentials" in this order
- add a LDAP Authentication plugin
- return back to the PAU, and activate your ldap plugin
- Now, register both the PAU and the ldap plugin
- Then you can see your ldap-users in Grant action
85 I get a Server Error page when doing something that should work. How do I debug this?
Here's a nicely formatted IRC log detailing how Steve Alexander found a particular bug; it gives lots of good advice on tracking bugs:
http://dev.zope.org/Members/spascoe/HowOneZope3BugWasFixed (Scott Pascoe)
Ken Manheimer wrote up an in-depth account of interactive Zope debugging using the python prompt - it was written for Zope 2, but many of the principles and some of the actual techniques should translate to Zope 3. It's at:
http://www.zope.org/Members/klm/ZopeDebugging
Here is 'Using the Zope Debugger' from the Zope3 docs:
86 I cannot see source when debugging eggified code
When you try to step into eggified code (libraries), you find that the source file referenced is invalid. Closer inspection reveals that the source path referenced has an invalid member like 'tmpXXXXX'.
The fix is easy, but first the reason why this happens:
When you install eggs with easy_install, it creates a temp directory, and byte compiles the python code. Hence, the .pyc files that are generated reference this (working, but temporary) path. Easy_install then copies the entire package into the right place, and so the .pyc files are stuck with invalid references to source files.
To solve this, simply remove all the ".pyc" files from any .egg paths that you have. On Unix, something like:
find . -name "*.pyc" | xargs rm
should do the trick.
87 How to make a form field display only?
Ref: http://zope3.pov.lt/irclogs/%23zope3-dev.2007-02-01.log.html
form_fields = form.FormFields(IPage).omit('__parent__','field_not_required_for_display')
form_fields['field_only_for_display'].for_display = True
88 How to 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
89 How to avoid warning to replace: <include package="zope.app" /> with: <include package="zope.app.zcmlfiles" /> ?
Ref: http://mail.zope.org/pipermail/checkins/2007-February/006572.html
This will work with 3.3 and trunk (3.4) but not with 3.2 .
<include
zcml:condition="installed zope.app.zcmlfiles"
package="zope.app.zcmlfiles"
/>
<include
zcml:condition="not-installed zope.app.zcmlfiles"
package="zope.app"
/>
90 How to get IRequest object in event handler ?
| Q: | How I can get IRequest in my event handler (I have only context)? |
|---|
Ref: http://mail.zope.org/pipermail/zope3-users/2007-April/006051.html
from zope.security.management import getInteraction request = getInteraction().participations[0]
91 Is there any single formlib widget for several fields ?
Ref: http://mail.zope.org/pipermail/zope3-users/2007-April/006098.html
92 How to define attributes in a schema that reference other interfaces ?
Ref: http://mail.zope.org/pipermail/zope3-users/2007-April/006061.html
You can use zope.schema.Object for this purpose.
Here is an example:
from zope.interface import Interface
from zope.schema import TextLine
from zope.schema import Object
class IWheel(Interface):
type = TextLine()
class ICar(Interface):
wheel = Object(schema=IWheel)
93 How to use ZCML overrides in buildout in site.zcml for zc.zope3recipes:app recipe ?
Ref: http://mail.zope.org/pipermail/zope3-users/2007-April/006106.html
<includeOverrides package="myapp" file="overrides.zcml" />
94 What is the difference between browser:view and browser:page ?
The intended use of <browser:page> is to define views that are accessible to browsers by using URLs?.
The intended use of <browser:view> is to define helper views that are accessible to page templates in TALES expressions like tal:attributes="href context/@@absolute_url".
A view is a general component that takes a context and a request. Not all views have to be publishable as browser pages.
95 Is there any tool to monitor ZODB activity ?
Ref: http://zope3.pov.lt/irclogs/%23zope3-dev.2007-05-15.log.html
There are some packages under development:
96 Any easy method to configure several classes with same permission ?
Ref: http://mail.zope.org/pipermail/zope3-users/2007-June/006291.html
Use like_class attribute of require tag, Here are some examples:
<class class=".MyImage"> <implements interface=".interfaces.IGalleryItemContained" /> <require like_class="zope.app.file.interfaces.IImage /> </class> <class class=".MySite"> <require like_class="zope.app.folder.Folder" /> </class>
97 How to call a view in a doc test and test the rendering ?
Ref: http://mail.zope.org/pipermail/zope3-users/2007-June/006298.html
It is recommended to use zope.testbrowser for testing views. Though, in unit test you can use zope.publisher.browser.TestRequest? to create a request and test your views.
In a unit test you can do it like this:
>>> context = ...yourcontentobject... >>> from zope.publisher.browser import TestRequest >>> request = TestRequest() >>> view = MyViewClass(context, request) >>> print view() <some xml or whatever output here>
If you want to provide, e.g., form parameters, pass them to the request:
>>> request = TestRequest(form={'foo': u'Lalala\u1234'})
If your view does anything interesting (e.g. use TALES expressions, or refer to other views like context/@@absolute_url), you will need to register a whole bunch of components in your doctest setUp methods. Don't forget to tear them down afterwards. IIRC you will need
from zope.app.testing import setup
def setUp(test):
setup.placelessSetUp()
setup.setUpTraversal()
def tearDown(test):
setup.placelessTearDown()
at the very least. Accessing other views, resources, or, god forbid, forms, will require other component registrations. At some point you have two choices: figure out this stuff once and then use copy & paste (actually, helper functions defined once in your project), or switch to testing your views with functional tests.
98 How to create/customize a skin?
Ref: http://zope3.pov.lt/irclogs/%23zope3-dev.2007-06-06.log.html Ref: http://kpug.zwiki.org/WhatIsNewInZope33
Skins are technically interfaces defined using zope.interface. To create a custom skin it is always better to inherit from a standard skin interface. It is by convention that skins will be created in sub-package named skin in your browser package of your main package. For example if your package name is foo, then foo.browser.skin will be the skin package, but this is not mandatory. Your skin interfaces can be defined in foo.browser.skin.interfaces. Here is an example interfaces.py:
from zope.app.rotterdam import Rotterdam class IShanghaiSkin(Rotterdam): """Wo zhu zai Shanghai"""
To register this, you can use interface and utility directives in zope namespace. The type of the IShanghaiSkin? skin is zope.publisher.interfaces.browser.IBrowserSkinType?. Here is a sample configure.zcml:
<interface
interface=".interfaces.IShanghaiSkin"
type="zope.publisher.interfaces.browser.IBrowserSkinType"
/>
<utility
component=".interfaces.IShanghaiSkin"
provides="zope.publisher.interfaces.browser.IBrowserSkinType"
name="ShanghaiSkin"
/>
As a shortcut, you can also use the interface directive and pass the new name parameter. The following one directive has the same effect as the two above regarding the skin registration:
<interface
interface=".interfaces.IShanghaiSkin"
type="zope.publisher.interfaces.browser.IBrowserSkinType"
name="ShanghaiSkin"
/>
You can register views and resources on the skin directly:
<browser:resource
name="zope3logo.gif"
file="shanghailogo.gif"
layer=".interfaces.IShanghaiSkin"
/>
As you can see, you need not to create an extra layer just to create a custom skin. A typical browser:page with with layer specified is like this:
<browser:page
for="*"
name="dialog_macros"
permission="zope.View"
layer=".interfaces.IShanghaiSkin"
template="dialog_macros.pt"
/>
99 How write custom traversal in Zope 3 ?
See this blog entry by Marius Gedminas : http://mg.pov.lt/blog/zope3-custom-traversal.html
100 How do I render a plaintext description without having the newlines removed ?
from zope.app.form.browser.textwidgets import escape from zope.app.renderer.plaintext import PlainTextToHTMLRenderer
In your view
def description(self):
return PlainTextToHTMLRenderer(escape(self.context.description), self.request).render()
In your template
tal:content="structure view/description"
101 How to use ZODB blob ?
Ref: http://zope3.pov.lt/irclogs/%23zope3-dev.2007-11-18.log.html
Create a directory under INSTANCE/var for storing blobs:
$ mkdir var/blobs
Then in your zope.conf change <zodb> definition like this:
<zodb>
<blobstorage>
<filestorage>
path $DATADIR/Data.fs
</filestorage>
blob-dir $DATADIR/blobs
</blobstorage>
</zodb>
The blob-dir specifies where you want to store blobs. You may use z3c.blobfile implementation for storing images and other normal files.
The next time you run your app, new .pyc files with correct references will be created, and presto - you're ok!
102 How do I automatically create some needed object at application startup?
http://mail.zope.org/pipermail/zope-dev/2007-December/030562.html
Do it by subscribing to IDatabaseOpenedWithRootEvent? (from zope.app.appsetup)
Example code:
@adapter(IDatabaseOpenedWithRootEvent)
def CreateMyContainer(event):
db, connection, root, root_folder = getInformationFromEvent(event)
if 'mycontainer' not in root_folder:
root_folder['mycontainer'] = MyContainer()
transaction.commit()
conn.close()
Then register this subscriber in your configure.zcml:
<subscriber handler="myapp.CreateMyContainer" />
