Commit e705f174 authored by Michel Pelletier's avatar Michel Pelletier

had duplicate __class_init__

parent 4f0f1ed8
......@@ -83,7 +83,7 @@
#
##############################################################################
__doc__="""Principia Find support"""
__version__='$Revision: 1.12 $'[11:-2]
__version__='$Revision: 1.13 $'[11:-2]
import sys, os, string, time, Globals, ExtensionClass
......@@ -199,8 +199,104 @@ class FindSupport(ExtensionClass.Base):
return result
PrincipiaFind=ZopeFind
def ZopeFindAndApply(self, obj, obj_ids=None, obj_metatypes=None,
obj_searchterm=None, obj_expr=None,
obj_mtime=None, obj_mspec=None,
obj_permission=None, obj_roles=None,
search_sub=0,
REQUEST=None, result=None, pre='',
apply_func=None, apply_path=''):
"""Zope Find interface and apply"""
if result is None:
result=[]
if obj_metatypes and 'all' in obj_metatypes:
obj_metatypes=None
if obj_mtime and type(obj_mtime)==type('s'):
obj_mtime=DateTime(obj_mtime).timeTime()
if obj_permission:
obj_permission=p_name(obj_permission)
if obj_roles and type(obj_roles) is type('s'):
obj_roles=[obj_roles]
if obj_expr:
# Setup expr machinations
md=td()
if hasattr(REQUEST, 'AUTHENTICATED_USER'):
md.AUTHENTICATED_USER=REQUEST.AUTHENTICATED_USER
obj_expr=(Eval(obj_expr, expr_globals), md, md._push, md._pop)
base=obj
if hasattr(obj, 'aq_base'):
base=obj.aq_base
if not hasattr(base, 'objectItems'):
return result
try: items=base.objectItems()
except: return result
try: add_result=result.append
except:
raise AttributeError, `result`
for id, ob in items:
if pre: p="%s/%s" % (pre, id)
else: p=id
dflag=0
if hasattr(ob, '_p_changed') and (ob._p_changed == None):
dflag=1
if hasattr(ob, 'aq_base'):
bs=ob.aq_base
else: bs=ob
if (
(not obj_ids or absattr(bs.id) in obj_ids)
and
(not obj_metatypes or (hasattr(bs, 'meta_type') and
bs.meta_type in obj_metatypes))
and
(not obj_searchterm or
(hasattr(ob, 'PrincipiaSearchSource') and
find(ob.PrincipiaSearchSource(), obj_searchterm) >= 0
))
and
(not obj_expr or expr_match(ob, obj_expr))
and
(not obj_mtime or mtime_match(ob, obj_mtime, obj_mspec))
and
( (not obj_permission or not obj_roles) or \
role_match(ob, obj_permission, obj_roles)
)
):
if apply_func:
apply_func(ob, (apply_path+'/'+p))
else:
add_result((p, ob))
dflag=0
if search_sub and hasattr(bs, 'objectItems'):
self.ZopeFindAndApply(ob, obj_ids, obj_metatypes,
obj_searchterm, obj_expr,
obj_mtime, obj_mspec,
obj_permission, obj_roles,
search_sub,
REQUEST, result, p,
apply_func, apply_path)
if dflag: ob._p_deactivate()
return result
class td(TemplateDict, cDocument):
......@@ -255,6 +351,7 @@ def role_match(ob, permission, roles, lt=type([]), tt=type(())):
return 1
Globals.default__class_init__(FindSupport)
# Helper functions
......@@ -267,5 +364,3 @@ def p_name(name):
return '_' + string.translate(name, name_trans) + '_Permission'
Globals.default__class_init__(FindSupport)
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