Skip to content

Commit

Permalink
ZClasses have been deprecated for two major releases. They have been …
Browse files Browse the repository at this point in the history
…removed in this version of Zope.
  • Loading branch information
hannosch committed Jan 23, 2009
1 parent 35a33c5 commit 0754a77
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 335 deletions.
4 changes: 2 additions & 2 deletions CatalogAwareness.py
Expand Up @@ -23,8 +23,8 @@
class CatalogAware:
""" This is a Mix-In class to make objects automaticly catalog and
uncatalog themselves in Zope, and to provide some other basic
attributes that are useful to catalog. Note that if your class or
ZClass subclasses CatalogAware, it will only catalog itself when
attributes that are useful to catalog. Note that if your class
subclasses CatalogAware, it will only catalog itself when
it is added or copied in Zope. If you make changes to your own
object, you are responsible for calling your object's index_object
method. """
Expand Down
17 changes: 2 additions & 15 deletions CatalogPathAwareness.py
Expand Up @@ -19,8 +19,8 @@
class CatalogAware:
""" This is a Mix-In class to make objects automaticly catalog and
uncatalog themselves in Zope, and to provide some other basic
attributes that are useful to catalog. Note that if your class or
ZClass subclasses CatalogAware, it will only catalog itself when
attributes that are useful to catalog. Note that if your class
subclasses CatalogAware, it will only catalog itself when
it is added or copied in Zope. If you make changes to your own
object, you are responsible for calling your object's index_object
method. """
Expand Down Expand Up @@ -119,16 +119,3 @@ def reindex_all(self, obj=None):
for item in obj.objectValues():
self.reindex_all(item)
return 'done!'

class CatalogPathAware(CatalogAware):
"""
This is a stub class that gets registered in __init__.py as a
ZClass base class. Its reason for existance is to make the name
that shows up in the ZClass Product list different than 'ZCatalog:
CatalogAware', which is the name registered by
CatalogAwareness.CatalogAware. The fix should *really* be to
change the product registry to keep the whole module/class path
and to make the ZClass add UI show the whole path, but this is
nontrivial, we don't want to spend a lot of time on ZClasses, and
this works.
"""
301 changes: 3 additions & 298 deletions ZCatalog.txt
Expand Up @@ -99,10 +99,9 @@ ZCatalog Tutorial
Most the work is done in the first step, which is getting objects
into the index. This is done in two ways. First, if your objects
are ZCatalog-aware they automatically update the index when they
are added, edited or directly deleted. A ZCatalog-aware object is
one that is an instance of a 'Z Class' that informs the 'ZCatalog'
of changes. *Directly deleted* means the object was deleted from
a Folder, not the deletion of a containing Folder.
are added, edited or directly deleted. *Directly deleted* means
the object was deleted from a Folder, not the deletion of a
containing Folder.

The second way that site contents get updated is by "finding"
information "into" the 'ZCatalog'. An operation based on Zope's
Expand Down Expand Up @@ -136,300 +135,6 @@ ZCatalog Tutorial
ZCatalogs can also be queried directly from DTML, as shown in the
example below.

Example using Z Classes

The first example shows how to give your Zope site a long-desired
feature: full text-searches of your content. The example assumes
you already have a number of DTML Methods/Documents to catalog.

o Install 'ZCatalog' as instructed above

o In the root folder of your Zope server, add a 'ZCatalog'.

o Type in the id 'catalog' and hit 'Add'.

You now have a brand new 'ZCatalog' named 'catalog' in your root
folder.

o Click on it.

Now you are looking at the 'ZCatalog' 'Contents' view. It says
the catalog is empty. We'll catalog some objects in a moment, but
first we have to tell it what portions of objects we are
specifically interested in.

o Click on 'Indexes'.

This management view is where the attributes to be indexed are
defined.

o In the 'Add index' field, type 'raw'.

o Click 'Add'.

Now that the indexes are defined, a set of objects can be selected
for cataloging.

o Click on 'Find items to ZCatalog'.

For this example, we are only interested in DTML Documents and
Methods.

o Deselect 'All type'.

o Select 'DTML Method' and 'DTML Document'.

o Click 'Find'.

ZCatalog will report how many items it found, and then present an
interface for excluding specific objects.

o Click 'Catalog Items'.

Great, now that the catalog is stocked, we can create a user
interface to it.

o Return to the root folder's management view.

o Add a 'Z Search Interface'.

'ZCatalog' participates in the Zope Search architecture. You
simply have to fill in this form, and a basic user interface will
be created.

o Select 'catalog' in the list beside 'Select one or more searchable
objects'.

o Beside 'Report Id', type 'report'.

o Beside 'Search Input Id', type 'search'.

'report' and 'search' are the Ids of two DTML Methods which will
be created in your root folder.

o Click 'Add'.

Congratulations, if all has gone well, you can now find references
to any word in your DTML pages. Try it by viewing 'search'. Type
a common word in the 'Raw' field, and you should be presented with
a list of hits. However, none of the results returned can be
clicked on. To fix this, go to the management view of 'report'.
'report' is called by 'search' to display the results from
'catalog'. 'report' is just a simple '<!--#in catalog-->' loop
with a few refinements. 'catalog' knows which results to return
by looking at the REQUEST variable, which contains the input from
the 'search' form.

o In the source of 'report', find the following line::

<tr><!--#var title--></tr>

o Replace it with this::

<tr>
<a href="<!--#var "catalog.getpath(data_record_id_)"-->">
<!--#var title-->
</a>
</tr>

This is a little confusing at first. Keep in mind that ZCatalog
does not return a list of your database objects. What it returns
are actually fairly unintelligent instances of a Record subclass.
These record objects contain copies of data from attributes of
catalog objects. The 'ZCatalog' 'MetaData Table' view defines
which attributes are copied.

(By default, these record objects are just SLIGHTLY more
intelligent than a raw tuple. 'Catalog' can be told to use a
custom, intelligent class for results. Please see the 'Catalog'
__init__ method in 'lib/python/Products/ZCatalog/Catalog.py' for
more information.)

Fortunately, ZCatalog provides a utility function for going from
result objects to the object's path. It is called, aptly enough,
'getpath'. 'getpath' expects to be passed the unique integer
identifier of the cataloged object. Results store that id as
'data_record_id_'.

Commit this change, and perform another search. Now the title can
be clicked on to take you to the full page.

Example cataloging custom objects

As if full-text searches of your entire site weren't good enough,
ZCatalog can also catalog Z Classes, Products, and in fact any
Python object you can put in a ZODB. Here is an example using a Z
Class, but the principles apply to any kind of object.

First, we're going to need something to catalog. Follow the 'Z
Class' tutorial to create the CD 'Z Class'. Back? Good.

o Create a folder, 'CDs', and create a number of instances of
the CD Z Class in it.

'cd1' through 'cd5' should be plenty. Remember to fill each of
them in from their Properties view.

Now we want to create a searchable catalog of CDs.

o Go to the 'CDs' folder and create a 'ZCatalog' with an ID 'cd_cat'.

o Click on the objects Indexes view.

This screen shows that, by default, 'ZCatalog' is interested in an
object's 'id','title', 'meta_type', and
'bobobase_modification_time'. You will almost always want to
index additional information. In this case, we would also like to
index the artist and description of CDs.

o Type 'artist' into the 'Add Index' field.

For the sake of example, we're going to use a FieldIndex index for
artist. This will give us the option of putting an HTML SELECT
box for artists on the search form.

o Select FieldIndex from the Index type drop down, and click
'Add'.

o Also add an index for 'description', but leave TextIndex
selected.

This will allow us to search for individual words within the
description.

o Click on 'MetaData Table'.

This is where we tell the 'ZCatalog' what attributes of cataloged
objects to cache. These cached values are available from search
results without having to look up the actual indexed object. The
tradeoff for the speed is extra memory, as information from the
content is duplicated in the 'ZCatalog'.

You will probably want to keep the schema light-weight, so we're
not going to add 'description' to it. Type 'artist' in the 'Add
column' field and click 'Add'.

o Click on the 'Find Items to Catalog' view.

This is the interface you use to tell the 'ZCatalog' which items
to index. Right now, beside 'Find objects of type:', 'All types'
is selected.

o Deselect 'All types'.

O Scroll down and select CD.

You could use the rest of the form to be more specific, but since
we want to catalog all the CDs,

o Click 'Find'.

'ZCatalog' will report 'Found 5 items.' It is now giving you an
opportunity to exclude some of the matched items from the index.
Again, we want all of them, so,

o Click 'Catalog Items'.

You should at this point see a list of the indexed objects. Also
of note is the 'Update Catalog' button. You have to use it
whenever you want your 'ZCatalog' to notice changes you've made to
the objects it's indexed.

Creating Search Forms And Result Reports

This catalog isn't much good without some way of querying it.

o Go back to your 'CDs' folder's management screen and add a Z
Search Interface.

The search add form will automatically detect your cd_cat
'ZCatalog' and offer it as a searchable document. Make sure it is
selected.

o Fill in 'cd_report' for 'Report ID' and 'cd_search' for
'Search Input ID'.

Those are the ids of two DTML methods that will be generated in
the 'CDs' folder.

o Click 'Add'.

o View the 'cd_search' Catalog (at, for example,
http://localhost:9673/CDs/cd_search).

You will see a basic search interface, with fields for searching
on 'title', modification date, 'id', 'artist', 'meta type' and
'description'. If you fill in one more more of the fields and
click 'Submit Query', cd_report will be displayed. It is passed
the search criteria and uses it to get a list from cd_cat to
iterate over. It is merely displaying the information from the
ZCatalog's MetaData table, but of course it can be enriched.

Try a few more searches. You'll find that you can type any single
word from the title or description and get a match, but for artist
you must type the exact string. That's because artist was indexed
as a FieldIndex, which gives us an opportunity to present a more
convenient interface.

Go back to the 'cd_search' management interface, and change
it's source to look like this::

<xmp>
<!--#var standard_html_header-->
<form action="cd_report" method="get">
<h2><!--#var document_title--></h2>
Enter query parameters:<br><table>
<tr><th>Title</th>
<td><input name="title"
width=30 value=""></td></tr>
<tr><th>Artist</th>
<td>
<select name="artist">
<option value="">All</option>
<!--#in expr="cd_cat.uniqueValuesFor('artist')"-->
<option value="<!--#var sequence-item-->">
<!--#var sequence-item-->
</option>
<!--#/in-->
</select>
</td>
</tr>
<tr><th>Description</th>
<td><input name="description"
width=30 value=""></td></tr>
<tr><td colspan=2 align=center>
<input type="SUBMIT" name="SUBMIT" value="Submit Query">
</td></tr>
</table>
</form>
<!--#var standard_html_footer-->
</xmp>

This is a search form somewhat more appropriate for the CD 'Z
Class'. Unrelated fields have been removed, and the 'artist'
field has been changed to a drop-down menu. Let's augment the
output of 'cd_report' to make the title a link to the actual CD
object.

Taking a look at 'cd_report', note that the search results are
obtained with a simple '<!--#in cd_cat ...-->' tag. The search
criteria is automatically obtained by the 'ZCatalog' from the form
input. The line we're interested in is this one::

<td><!--#var title--></td>

Change it to read::

<td>
<a href="<!--#var "cd_cat.getpath(data_record_id_)"-->">
<!--#var title-->
</a>
</td>

Now, assuming you have added the index_html document template to
your CD 'Z Class', clicking on a search result will take you to
the CD's detailed display.

Using 'ZCatalog' In A Zope Site

The 'ZCatalog' provides high-speed access to what is on your site.
Expand Down
21 changes: 1 addition & 20 deletions __init__.py
Expand Up @@ -13,26 +13,7 @@

"""ZCatalog product"""

import ZCatalog, CatalogAwareness, CatalogPathAwareness

# BBB: ZClasses are deprecated but we don't want the warning to appear here
import warnings
warnings.filterwarnings('ignore', message='^ZClasses', append=1)
try:
from ZClasses import createZClassForBase
finally:
del warnings.filters[-1]
try:
del __warningregistry__
except NameError:
pass

createZClassForBase( ZCatalog.ZCatalog , globals()
, 'ZCatalogBase', 'ZCatalog' )
createZClassForBase( CatalogAwareness.CatalogAware, globals()
, 'CatalogAwareBase', 'CatalogAware' )
createZClassForBase( CatalogPathAwareness.CatalogPathAware, globals()
, 'CatalogPathAwareBase', 'CatalogPathAware' )
import ZCatalog

def initialize(context):
context.registerClass(
Expand Down

0 comments on commit 0754a77

Please sign in to comment.