Commit ee6c5127 authored by 's avatar

Added find in all subfolders option

parent a06f83ef
__doc__="""Principia Find support"""
__version__='$Revision: 1.1 $'[11:-2]
__version__='$Revision: 1.2 $'[11:-2]
import sys, os, string, time, Globals
......@@ -11,18 +11,13 @@ from string import find
class FindSupport:
"""Find support for Principia Folders"""
def PrincipiaFind(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=''):
"""Principia Find interface"""
......@@ -38,6 +33,9 @@ class FindSupport:
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()
......@@ -83,11 +81,6 @@ class FindSupport:
(not obj_expr or expr_match(ob, obj_expr))
and
(not obj_mtime or mtime_match(ob, obj_mtime, obj_mspec))
# (obj_modspec=='<' and hasattr(ob, '_p_mtime') and \
# ob._p_mtime < obj_modtime) or
# (obj_modspec=='>' and hasattr(ob, '_p_mtime') and \
# ob._p_mtime > obj_modtime)
# )
and
( (not obj_permission or not obj_roles) or \
role_match(ob, obj_permission, obj_roles)
......@@ -96,11 +89,12 @@ class FindSupport:
add_result((p, ob))
dflag=0
if hasattr(bs, 'objectItems'):
if search_sub and hasattr(bs, 'objectItems'):
self.PrincipiaFind(ob, obj_ids, obj_metatypes,
obj_searchterm, obj_expr,
obj_mtime, obj_mspec,
obj_permission, obj_roles,
search_sub,
REQUEST, result, p)
if dflag: ob._p_deactivate()
......@@ -130,7 +124,6 @@ def mtime_match(ob, t, q, fn=hasattr):
def role_match(ob, permission, roles, lt=type([]), tt=type(())):
# ob=obj
pr=[]
fn=pr.append
......@@ -149,7 +142,7 @@ def role_match(ob, permission, roles, lt=type([]), tt=type(())):
if p is None:
map(fn, ('Manager', 'Anonymous'))
break
if hasattr(ob, 'aq_parent'):
ob=ob.aq_parent
continue
......@@ -176,88 +169,9 @@ def p_name(name):
## def oldpermission_match(obj, permission, roles):
## # if not hasattr(obj, '__ac_permissions__'):
## # return 0
## r=proles(obj, permission)
## for role in roles:
## if not (role in r):
## return 0
## return 1
## def pldproles(obj, permission):
## for p in obj.__ac_permissions__:
## name, value = p[:2]
## if name==permission:
## p=Permission(name,value,obj)
## r=p.getRoles()
## if r is None: r=['Anonymous']
## if type(r) is type(()):
## r=list(r)
## if hasattr(obj, 'aq_parent'):
## o=obj.aq_parent
## n=p._p
## while 1:
## if hasattr(o, n):
## roles=getattr(o, n)
## if roles is None:
## if not ('Anonymous' in r):
## r.append('Anonymous')
## return r
## if type(roles) is type(()):
## return r+list(roles)
## r=r+list(roles)
## if hasattr(o, 'aq_parent'):
## o=o.aq_parent
## else: break
## return r
## return []
## def PrincipiaFind1(self, start, _initial=None, prefix='',
## type=None, substring=None, name=None,
## ):
## if _initial is None: _initial=[]
## if hasattr(start,'aq_base'): start=start.aq_base
## if not hasattr(start, 'objectItems'): return _initial
## try: items=start.objectItems()
## except: return _initial
## for oname, o in items:
## if prefix: p="%s/%s" % (prefix, oname)
## else: p=oname
## if hasattr(o,'aq_base'): o=o.aq_base
## if (
## (type is None or not hasattr(o,'meta_type') or
## type==o.meta_type)
## and
## (name is None or oname==name)
## and
## (substring is None or
## (hasattr(o,'PrincipiaSearchSource') and
## find(o.PrincipiaSearchSource(),substring) >= 0
## ))
## ):
## _initial.append(p)
## if hasattr(o, 'objectItems'):
## self.PrincipiaFind(o,_initial,p,type,substring,name)
## return _initial
##############################################################################
#
# $Log: FindSupport.py,v $
# Revision 1.2 1998/08/13 13:48:16 brian
# Added find in all subfolders option
#
......@@ -106,6 +106,18 @@ function show_opt()
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP">
</TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="RADIO" NAME="search_sub:int" VALUE="0">
Search only in this folder
<BR>
<INPUT TYPE="RADIO" NAME="search_sub:int" VALUE="1" CHECKED>
Search all subfolders
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP">
</TD>
......
......@@ -71,6 +71,18 @@ function show_opt()
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP">
</TD>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="RADIO" NAME="search_sub:int" VALUE="0">
Search only in this folder
<BR>
<INPUT TYPE="RADIO" NAME="search_sub:int" VALUE="1" CHECKED>
Search all subfolders
</TD>
</TR>
<TR>
<TD ALIGN="LEFT" VALIGN="TOP">
</TD>
......
......@@ -12,14 +12,24 @@ function new_wnd()
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
<P>
<!--#in expr="('obj_ids', 'obj_metatypes', 'obj_searchterm', 'obj_expr', 'obj_mtime', 'obj_mspec', 'obj_permission', 'obj_roles')"-->
<!--#in expr="('obj_ids', 'obj_metatypes', 'obj_searchterm', 'obj_expr', 'obj_mtime', 'obj_mspec', 'obj_permission', 'obj_roles', 'search_sub')"-->
<!--#else expr="_.hasattr(REQUEST, _['sequence-item'])"-->
<!--#call expr="REQUEST.set(_['sequence-item'], _.None)"-->
<!--#/else-->
<!--#/in-->
<!--#if btn_submit-->
<!--#call expr="REQUEST.set('results', PrincipiaFind(this(), obj_ids=obj_ids, obj_metatypes=obj_metatypes, obj_searchterm=obj_searchterm, obj_expr=obj_expr, obj_mtime=obj_mtime, obj_mspec=obj_mspec, obj_permission=obj_permission, obj_roles=obj_roles, REQUEST=REQUEST))"-->
<!--#call expr="REQUEST.set('results', PrincipiaFind(this(),
obj_ids=obj_ids,
obj_metatypes=obj_metatypes,
obj_searchterm=obj_searchterm,
obj_expr=obj_expr,
obj_mtime=obj_mtime,
obj_mspec=obj_mspec,
obj_permission=obj_permission,
obj_roles=obj_roles,
search_sub=search_sub,
REQUEST=REQUEST))"-->
<!--#call expr="REQUEST.set('result_len', _.len(results))"-->
<!--#if results-->
......
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