[Zope] searching ZCatalog from Python Script
Sandy Britain
a.britain@bangor.ac.uk
Wed, 14 Feb 2001 15:16:45 +0000
This is a multi-part message in MIME format.
--------------FE8DAEA745315F10F6E0651C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi all,
I am relatively new to Zope and Python, so there is probably a short way
to describe my problem, but trying to be clear from the top so that you
can see if I've done something daft:
I am trying to create a little web app component called 'TeamJournal'.
The component should allow an authenticated user in my work team (from
a web interface of my creation) to:
1. add an an entry to their journal and 2. to view their own or
everyones entries for the last week.
TheTeamJournal I have implemented as a ZClass with indexes and metadata
both containing the items -
'author' and 'date' which map to properties in a propertysheet in the
ZClass called entryInfo.
Additionally I have a folder called 'Journals' in the Zope Root which
contains:
1. a ZCatalog called 'Catalog'
2. a bunch of DTMLmethod objects and my offending python script that is
the point of my question
3. a folder called entries where the journal entry objects get stored
when they are created.
As it stands I can add an entry from a web form, view all the journal
entries in a web page by calling a DTML method in Journals and search on
'author' through the web via the forms generated by the
ZSearchInterface.
But reading the ZOPE book chapter 9, there is suggested a cool way to
query a ZCatalog from a python script (the relevantSectionNews example).
Using this approach I tried to get just my own entries by writing a
python script called getMyEntries that looks like this:
user = context.REQUEST.AUTHENTICATED_USER
return context.Catalog({'author' : user} )
So to get to the point:
The problem is this script doesn't seem to return anything, although it
appears to run when I test it. I have three catalogued entry items in
the Journals.entries folder.
So I tried:
return context.Catalog()
which produced the following output:
[<mybrains instance at 013281D0>, <mybrains
instance at 01328650>, <mybrains instance at 013286C0>]
well its 3 objects, but where 'mybrains' comes from I don't know. So
then I wrote the following DTML method also in the Journals folder to
try and get to the content of the objects:
<ul>
<dtml-in getMyEntries>
<li><a href=&dtml-absolute_url;"><dtml-var date></a></li>
</dtml-in>
</ul>
This method correctly displays a list of hyperlinks displaying as text
the date property of my journal entries. So I assume it can find them.
But then when I click on the hyperlink I get the following Zope error
message:
**Note that the URL below correctly specifies the ID [982120208] of an
entry in Journals.entries, but I don't know what %22 is!
----------------------------------------------------------------------------------------------------------------
Zope Error
Zope has encountered an error while publishing this resource.
Debugging Notice
Zope has encountered a problem publishing your object.
Cannot locate object at:
http://localhost:8080/Journals/entries/982120208%22
Troubleshooting Suggestions
The URL may be incorrect.
The parameters passed to this resource may be incorrect.
A resource that this resource relies on may be
encountering an error.
For more detailed information about the error, please refer
to the HTML source for this page.
If the error persists please contact the site maintainer.
Thank you for your patience.
Traceback (innermost last):
File C:\ZopeComantle\lib\python\ZPublisher\Publish.py, line 222, in
publish_module
File C:\ZopeComantle\lib\python\ZPublisher\Publish.py, line 187, in
publish
File C:\ZopeComantle\lib\python\Zope\__init__.py, line 221, in
zpublisher_exception_hook
(Object: Traversable)
File C:\ZopeComantle\lib\python\ZPublisher\Publish.py, line 162, in
publish
File C:\ZopeComantle\lib\python\ZPublisher\BaseRequest.py, line 367,
in traverse
File C:\ZopeComantle\lib\python\ZPublisher\HTTPResponse.py, line 558,
in debugError
NotFound: (see above)
-------------------------------------------------------------------------------------------------------------
Please help if you can! I'm using Zope 2.3 by the way, if that helps
cheers Sandy
--------------FE8DAEA745315F10F6E0651C
Content-Type: text/x-vcard; charset=us-ascii;
name="a.britain.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Sandy Britain
Content-Disposition: attachment;
filename="a.britain.vcf"
begin:vcard
n:Britain;Sandy
tel;fax:+44 (1248) 361429
tel;work:+44 (1248) 383645
x-mozilla-html:FALSE
org:University of Wales - Bangor;Centre for Learning Technology (CeLT)
version:2.1
email;internet:a.britain@bangor.ac.uk
title:Dr
adr;quoted-printable:;;Seecs,=0D=0ADean St.;Bangor;Gwynedd;LL57 2UT;UK
x-mozilla-cpt:;-11920
fn:Sandy Britain
end:vcard
--------------FE8DAEA745315F10F6E0651C--