Commit f18c08da authored by Michel Pelletier's avatar Michel Pelletier

Added ZCatalog.CatalogAwareness.CatalogAware class to replace that

damn Findable ZClass.  Now Zclasses that want to automagically catalog
and uncatalog themselves can just subclass CatalogAware and it will
work dandy.
parent 6fe3e53d
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
"""ZCatalog Findable class"""
import urllib, string
from Globals import HTMLFile
class CatalogAware:
meta_type='CatalogAware'
default_catalog='Catalog'
manage_editCatalogerForm=HTMLFile('editCatalogerForm', globals())
def manage_editCataloger(self, default):
""" """
self.default_catalog=default
message = "Your changes have been saved"
return self.manage_main(self, REQUEST, manage_tabs_message=message)
def manage_afterAdd(self, item, container):
self.index_object()
for object in self.objectValues():
try: s=object._p_changed
except: s=0
object.manage_afterAdd(item, container)
if s is None: object._p_deactivate()
def manage_afterClone(self, item):
self.index_object()
for object in self.objectValues():
try: s=object._p_changed
except: s=0
object.manage_afterClone(item)
if s is None: object._p_deactivate()
def manage_beforeDelete(self, item, container):
self.unindex_object()
for object in self.objectValues():
try: s=object._p_changed
except: s=0
object.manage_beforeDelete(item, container)
if s is None: object._p_deactivate()
def creator(self):
"""Return a sequence of user names who have the local
Owner role on an object. The name creator is used
for this method to conform to Dublin Core."""
parent=self.aq_parent
roles=parent.aq_acquire('__ac_local_roles__')
dict=roles or {} #parent.__ac_local_roles__ or {}
items=[]
for key, val in dict.items():
if 'Owner' in val:
items.append(key)
return string.join(items, ', ')
def onDeleteObject(self):
"""Object delete handler."""
self.unindex_object()
def url(self, ftype=urllib.splittype, fhost=urllib.splithost):
"""Return a SCRIPT_NAME-based url for an object."""
if hasattr(self, 'DestinationURL') and \
callable(self.DestinationURL):
url='%s/%s' % (self.DestinationURL(), self.id)
else: url=self.absolute_url()
type, uri=ftype(url)
host, uri=fhost(uri)
script_name=self.REQUEST['SCRIPT_NAME']
__traceback_info__=(`uri`, `script_name`)
if script_name:
uri=filter(None, string.split(uri, script_name))[0]
uri=uri or '/'
if uri[0]=='/': uri=uri[1:]
return uri
def summary(self, num=200):
"""Return a summary of the text content of the object."""
if not hasattr(self, 'text_content'):
return ''
attr=getattr(self, 'text_content')
if callable(attr):
text=attr()
else: text=attr
n=min(num, len(text))
return text[:n]
def index_object(self):
"""A common method to allow Findables to index themselves."""
if hasattr(self, self.default_catalog):
getattr(self, self.default_catalog).catalog_object(self, self.url())
def unindex_object(self):
"""A common method to allow Findables to unindex themselves."""
if hasattr(self, self.default_catalog):
getattr(self, self.default_catalog).uncatalog_object(self.url())
def aq_base(ob):
if hasattr(ob, 'aq_base'):
return ob.aq_base
return ob
def reindex_all(self, obj=None):
""" """
if obj is None: obj=self
if hasattr(aq_base(obj), 'index_object'):
obj.index_object()
if hasattr(aq_base(obj), 'objectValues'):
sub=obj.objectValues()
for item in obj.objectValues():
reindex_all(self, item)
return 'done!'
......@@ -85,7 +85,7 @@
"""ZCatalog product"""
import ZCatalog, Catalog
import ZCatalog, Catalog, CatalogAwareness
......@@ -98,3 +98,4 @@ def initialize(context):
icon='www/ZCatalog.gif',
)
context.registerBaseClass(ZCatalog.ZCatalog)
context.registerBaseClass(CatalogAwareness.CatalogAware)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment