See also: other Zope FAQs.
1 Frequently Asked Questions about Zope 2
- 1 Frequently Asked Questions about Zope 2
- 1.1 General
- 1.2 Installing Zope 2
- 1.3 Using Zope 2
- 1.4 Troubleshooting Zope 2
- 1.5 Zope 2 Tips
- 1.5.1 How do I enable gzip encoding in Zope 2?
- 1.5.2 How do I checks for the existences of a named object?
- 1.5.3 Why is hasattr(container,'id') bad?
- 1.5.4 How do I find the class of a particular object in ZODB ?
- 1.5.5 How to get root object in ZODB ?
- 1.5.6 How do I add role from code ?
- 1.5.7 How to get all objects indexed in a certain catalog?
- 1.5.8 How do I get search result count?
- 1.5.9 how can I check if a object with id X exists in the same folder ?
1.1 General
1.1.1 What is Zope 2?
Zope is an open source web application server primarily written in the Python programming language. It features a transactional object database which can store not only content and custom data, but also dynamic HTML templates, scripts, a search engine, and relational database (RDBMS) connections and code. It features a strong through-the-web development model, allowing you to update your web site from anywhere in the world. To allow for this, Zope also features a tightly integrated security model. Built around the concept of "safe delegation of control", Zope's security architecture also allows you to turn control over parts of a web site to other organizations or individuals. The transactional model applies not only to Zope's object database, but to many relational database connectors as well, allowing for strong data integrity. This transaction model happens automatically, ensuring that all data is successfully stored in connected data sources by the time a response is returned to a web browser or other client.
There are numerous products (plug-in Zope components) available for download to extend the basic set of site building tools. These products include new content objects; relational database and other external data source connectors; advanced content management tools; and full applications for e-commerce, content and document management, or bug and issue tracking. Zope includes its own HTTP, FTP, Zope and WebDAV, and XML-RPC serving capabilities, but can also be used with the Apache or other web servers.
1.1.2 Why Zope 2?
some other stuff here
1.2 Installing Zope 2
1.2.1 How do I install on Windows?
The ZopeBook has its chapter on installing Zope on Windows - it is based on a Zope2.7 release
Installing Zope for Windows With Binaries from Zope.org
However there is a more recent ScreenCast? done by Malaysian Zope user Bakhtiar Ahamid - it shows how to install a Zope2.9 release onto windows
Screencast (.swf file, starts automatically)
1.2.2 How do I install on Unix like OS?
There are no binary package officially supported by Zope.com or the zope community since there are way too many distributions and flavors that may entail support problem.
Having said that, there are special package done by some distributions community but usually are not the latest version.
1.2.3 How do I install from source?
Short answer:
./configure --prefix=/path/to/dir && make && make install
Zope tree will be installed at /path/to/dir/. run /path/to/dir/makezopeinstance.py and fill in the necessary.
Depending on your Unix flavors, the above will work accordingly.
However, on Solaris, try:
gunzip -c Zope-version-final.tgz | tar -Exvf - OR: /usr/sfw/bin/gtar -xzvf Zope-version-final.tgz
and then run the above commands. It should "just work".
Screencast (.swf file, starts automatically)
1.2.4 How do I install Zope Product X?
First, check the Zope Product readme for any special steps.
General installation involves these steps:
- untar Zope Product into $INSTANCE_HOME/Products
- restart Zope
- login ZMI (Zope Management Interface) and check Control_Panel/Products for the newly installed Zope Product.
1.3 Using Zope 2
1.3.1 How do I ceate new Zope objects automatically, e.g via [Zope and WebDAV]?
We need to have a PUT_factory method in the Zope instance. See PUT_factory.
1.3.2 What is PUT_factory?
PUT_factory is a Python method which handles how new objects are created inside of Zope when a file is uploaded. Zope has many types of objects, such as Images, Python Scripts, Page Templates and basic generic File objects. PUT_factory lets us control this, so that when an image is uploaded, Zope doesn't try to create a Page Template out of it. Instead, we create Image objects.
1.3.3 How do I use this _insert_your_favourite_python_library_ with Zope?
Check HowToAddModulesToRestrictedCode or the examples in $SOFTWARE_HOME/lib/python/Products/PythonScripts/module_access_examples.py
Here is an example on how to enable the 'elementtree' module in Zope2:
http://blog.d2m.at/2006/11/14/enabling-elementtree/
1.3.4 How do I setup multiple mount points in Zope?
Steps involved:
edit your INSTANCE_HOME/etc/zope.conf and add:
<zodb_db dbname> <filestorage> path /path/to/your/new/zodb </filestorage> mount-point /newzodb </zodb_db>Go to ZMI (Zope Management Interface), and add a "ZODB Mount Point" with id newzodb in the Zope root folder
1.4 Troubleshooting Zope 2
1.4.1 How do I check my Zope version ?
Look in /Control_Panel/manage in the ZMI (Zope Management Interface); the version will usually appear there. (Exceptions: older Zope versions, SVN Zope versions, some Zope 2.10 versions ? Update)
If you don't have access to the control panel: ...
1.4.2 I want to post XML content, but Zope assumes a XMLRPC request
ZPublisher assumes that if the Content-type on an HTTP POST is "text/xml", then the request contains an xmlrpc call
Back in 2004 Brian Lloyd created XMLFix?, a monkeypatch for ZPublisher (HTTPRequest?.processInputs) that turns off xmlrpc handling
http://mail.zope.org/pipermail/zope/2004-June/151497.html
From Zope2.9/Zope3.2 publishers (zope.app.publication HTTPPublicationRequestFactory?) are pluggable and can be configure through ZCML. The registration is based on the request method and mime-type.
http://mail.zope.org/pipermail/zope/2005-November/163029.html
1.5 Zope 2 Tips
1.5.1 How do I enable gzip encoding in Zope 2?
Enable HTTP Content Encoding with gzip compression if possible on a request-by-request basis:
http://www.plope.com/Books/2_7Edition/AppendixB.stx#2-205
Example python script:
## Script (Python) "force_gzip_encoding"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# method signature
# enableHTTPCompression(REQUEST={},force=0,disable=0,query=0)
container.REQUEST.RESPONSE.enableHTTPCompression(force=1)
return container.REQUEST
Check the HTTP response headers of the returned page, they should include 'Content-Encoding: gzip'
1.5.2 How do I checks for the existences of a named object?
A few ways:
if namedObject in container.objectIds(): # object exists else: # doesn't
or:
obj = context.restrictedTraverse('/path/to/object/objId', None)
if obj is None:
# object not found
else:
# object exists
1.5.3 Why is hasattr(container,'id') bad?
This is bad for two reasons [1]:
- It'll acquire id from other places
- It'll swallow any exceptions found in trying to get hold of 'id', including ConflictErrors, which is "bad"
| [1] | http://mail.zope.org/pipermail/zope/2006-December/169790.html |
1.5.4 How do I find the class of a particular object in ZODB ?
./bin/zopectl debug >>> app['temp_folder']['session_data'].__class__ <class 'Products.Transience.Transience.TransientObjectContainer'>
1.5.5 How to get root object in ZODB ?
context.restrictedTravers('/')
context.getPhysicalRoot()
Using restrictedTravers you can get object at a particular URL.
1.5.6 How do I add role from code ?
context._addRole('role_name')
1.5.7 How to get all objects indexed in a certain catalog?
catalog() #"catalog" being your catalog object and then just catalog() it's callable
1.5.8 How do I get search result count?
If you want the count, instead of using len(result), there is an optimized way:
results = zcatalog(query) count = results and results.actual_result_count or 0
1.5.9 how can I check if a object with id X exists in the same folder ?
if X in context.aq_parent.objectIds() #or if container.hasObject(yourid) #or if getattr(container.aq_explicit, id, None) is not None