Zope and Persistence

R

ryankaskel

I don't know if this is the appropriate place to post a Zope question
but I figure many here are familiar with it. I'm confused about the
role of the ZMI when it comes to development. I want to write a simple
script that logs page hits. I wrote it in what was called a Script
(Python) resource in the ZMI. When I access the page it gives an error
saying that this file cannot import Persistence, etc. This makes sense
but where would I put this script and how would I invoke it? It is only
supposed to store an integer in Data.fs. Thanks.
 
T

Terry Hancock

I don't know if this is the appropriate place to post a Zope question
but I figure many here are familiar with it.

You will do much better to use the Zope users' mailing list. Go to
zope.org and follow the mailing lists link to sign up.
I'm confused about the
role of the ZMI when it comes to development. I want to write a simple
script that logs page hits. I wrote it in what was called a Script
(Python) resource in the ZMI. When I access the page it gives an error
saying that this file cannot import Persistence, etc.

Python scripts are NOT Python modules, and you should not have to
import anything to make use of persistence. Objects you manipulate
using the ZMI interface are pretty much always objects in the ZODB
database (anything that shows up as an "object" or a "property" in
the ZMI is a persistent object).

What you want to do is add an integer "property" to the folder containing
the script (i.e. "context" or "container", depending on whether you want
to maintain a count in the directory from which the script is called,
or one unique counter where the script is stored). That's your counter.

Also, be sure to follow the "help" link in the ZMI and use the online
API documentation.
This makes sense
but where would I put this script and how would I invoke it? It is only
supposed to store an integer in Data.fs. Thanks.

If you actually needed imports and access to the internal ZODB machinery,
then you would need to write a "Product", not work in the ZMI at all.

But you don't.

Cheers,
Terry
 
B

bruno modulix

I don't know if this is the appropriate place to post a Zope question

Nope. You'd better use the zope mailing-list for this.

but I figure many here are familiar with it. I'm confused about the
role of the ZMI when it comes to development.

As it's name implies, the ZMI is a *management* interface. Real Zope
developpement is better made with filesystem "Products" (Zope components).
I want to write a simple
script that logs page hits.

That's a typical case of reinventig the square wheel. Ever looked at
<you-zope-instance-folder-here>/log/Z2.log ? It's an apache-like access
log. And there are a whole lot of tools for building stats from apache
access logs.

I wrote it in what was called a Script
(Python) resource in the ZMI. When I access the page it gives an error
saying that this file cannot import Persistence, etc.

Why would you import Persistence in a Python Script ? This is already a
persistent object.
This makes sense
but where would I put this script

Whereever seems to fit - this depends on your application.
and how would I invoke it?

Like any other Zope object.
It is only
supposed to store an integer in Data.fs. Thanks.

This is another problem, and I think you'd better start with the zope book.

But for you current use case, first have a look at Zope's access log.
</OT>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top