Back to index

plone3  3.1.7
Classes | Functions | Variables
CMFPlone.CatalogTool Namespace Reference

Classes

class  ExtensibleIndexableObjectRegistry
class  ExtensibleIndexableObjectWrapper
class  CatalogTool

Functions

def allowedRolesAndUsers
def object_provides
def zero_fill
def sortable_title
def getObjPositionInParent
def getObjSize
def is_folderish
def syndication_enabled
def is_default_page
def getIcon

Variables

tuple _marker = object()
tuple _eioRegistry = ExtensibleIndexableObjectRegistry()
 registerIndexableAttribute = _eioRegistry.register
tuple num_sort_regex = re.compile('\d+')
dictionary SIZE_CONST = {'kB': 1024, 'MB': 1024*1024, 'GB': 1024*1024*1024}
tuple SIZE_ORDER = ('GB', 'MB', 'kB')

Function Documentation

def CMFPlone.CatalogTool.allowedRolesAndUsers (   obj,
  portal,
  kwargs 
)
Return a list of roles and users with View permission.

Used by PortalCatalog to filter out items you're not allowed to see.

Definition at line 118 of file CatalogTool.py.

00118 
00119 def allowedRolesAndUsers(obj, portal, **kwargs):
00120     """Return a list of roles and users with View permission.
00121 
00122     Used by PortalCatalog to filter out items you're not allowed to see.
00123     """
00124     allowed = {}
00125     for r in rolesForPermissionOn('View', obj):
00126         allowed[r] = 1
00127     try:
00128         localroles = portal.acl_users._getAllLocalRoles(obj)
00129     except AttributeError:
00130         localroles = _mergedLocalRoles(obj)
00131     for user, roles in localroles.items():
00132         for role in roles:
00133             if allowed.has_key(role):
00134                 allowed['user:' + user] = 1
00135     if allowed.has_key('Owner'):
00136         del allowed['Owner']
00137     return list(allowed.keys())
00138 
00139 registerIndexableAttribute('allowedRolesAndUsers', allowedRolesAndUsers)
00140 

Here is the call graph for this function:

def CMFPlone.CatalogTool.getIcon (   obj,
  kwargs 
)
Make sure we index icon relative to portal

Definition at line 316 of file CatalogTool.py.

00316 
00317 def getIcon(obj, **kwargs):
00318     """Make sure we index icon relative to portal"""
00319     return obj.getIcon(True)
00320 
00321 registerIndexableAttribute('getIcon', getIcon)
00322 

Here is the caller graph for this function:

def CMFPlone.CatalogTool.getObjPositionInParent (   obj,
  kwargs 
)
Helper method for catalog based folder contents.

>>> from Products.CMFPlone.CatalogTool import getObjPositionInParent

>>> getObjPositionInParent(self.folder)
0

Definition at line 178 of file CatalogTool.py.

00178 
00179 def getObjPositionInParent(obj, **kwargs):
00180     """ Helper method for catalog based folder contents.
00181 
00182     >>> from Products.CMFPlone.CatalogTool import getObjPositionInParent
00183 
00184     >>> getObjPositionInParent(self.folder)
00185     0
00186     """
00187     parent = aq_parent(aq_inner(obj))
00188     if IOrderedContainer.isImplementedBy(parent):
00189         try:
00190             return parent.getObjectPosition(obj.getId())
00191         except ConflictError:
00192             raise
00193         except:
00194             pass
00195             # XXX log
00196     return 0
00197 
00198 registerIndexableAttribute('getObjPositionInParent', getObjPositionInParent)
00199 

def CMFPlone.CatalogTool.getObjSize (   obj,
  kwargs 
)
Helper method for catalog based folder contents.

>>> from Products.CMFPlone.CatalogTool import getObjSize

>>> getObjSize(self.folder)
'1 kB'

Definition at line 203 of file CatalogTool.py.

00203 
00204 def getObjSize(obj, **kwargs):
00205     """ Helper method for catalog based folder contents.
00206 
00207     >>> from Products.CMFPlone.CatalogTool import getObjSize
00208 
00209     >>> getObjSize(self.folder)
00210     '1 kB'
00211     """
00212     smaller = SIZE_ORDER[-1]
00213 
00214     if base_hasattr(obj, 'get_size'):
00215         size = obj.get_size()
00216     else:
00217         size = 0
00218 
00219     # if the size is a float, then make it an int
00220     # happens for large files
00221     try:
00222         size = int(size)
00223     except (ValueError, TypeError):
00224         pass
00225 
00226     if not size:
00227         return '0 %s' % smaller
00228 
00229     if isinstance(size, (int, long)):
00230         if size < SIZE_CONST[smaller]:
00231             return '1 %s' % smaller
00232         for c in SIZE_ORDER:
00233             if size/SIZE_CONST[c] > 0:
00234                 break
00235         return '%.1f %s' % (float(size/float(SIZE_CONST[c])), c)
00236     return size
00237 
00238 registerIndexableAttribute('getObjSize', getObjSize)
00239 

Here is the call graph for this function:

def CMFPlone.CatalogTool.is_default_page (   obj,
  portal,
  kwargs 
)
Is this the default page in its folder

Definition at line 307 of file CatalogTool.py.

00307 
00308 def is_default_page(obj, portal, **kwargs):
00309     """Is this the default page in its folder
00310     """
00311     ptool = getToolByName(portal, 'plone_utils')
00312     return ptool.isDefaultPage(obj)
00313 
00314 registerIndexableAttribute('is_default_page', is_default_page)
00315 

Here is the call graph for this function:

def CMFPlone.CatalogTool.is_folderish (   obj,
  kwargs 
)
Should this item be treated as a folder?

Checks isPrincipiaFolderish, as well as the INonStructuralFolder
interfaces.

  >>> from Products.CMFPlone.CatalogTool import is_folderish
  >>> from Products.CMFPlone.interfaces import INonStructuralFolder
  >>> from Products.CMFPlone.interfaces.NonStructuralFolder import INonStructuralFolder as z2INonStructuralFolder
  >>> from zope.interface import directlyProvidedBy, directlyProvides

A Folder is folderish generally::
  >>> is_folderish(self.folder)
  True

But if we make it an INonStructuralFolder it is not::
  >>> base_implements = directlyProvidedBy(self.folder)
  >>> directlyProvides(self.folder, INonStructuralFolder, directlyProvidedBy(self.folder))
  >>> is_folderish(self.folder)
  False
  
Now we revert our interface change and apply the z2 no-folderish interface::
  >>> directlyProvides(self.folder, base_implements)
  >>> is_folderish(self.folder)
  True
  >>> z2base_implements = self.folder.__implements__
  >>> self.folder.__implements__ = z2base_implements + (z2INonStructuralFolder,)
  >>> is_folderish(self.folder)
  False

We again revert the interface change and check to make sure that
PrincipiaFolderish is respected::
  >>> self.folder.__implements__ = z2base_implements
  >>> is_folderish(self.folder)
  True
  >>> self.folder.isPrincipiaFolderish = False
  >>> is_folderish(self.folder)
  False

Definition at line 240 of file CatalogTool.py.

00240 
00241 def is_folderish(obj, **kwargs):
00242     """Should this item be treated as a folder?
00243 
00244     Checks isPrincipiaFolderish, as well as the INonStructuralFolder
00245     interfaces.
00246 
00247       >>> from Products.CMFPlone.CatalogTool import is_folderish
00248       >>> from Products.CMFPlone.interfaces import INonStructuralFolder
00249       >>> from Products.CMFPlone.interfaces.NonStructuralFolder import INonStructuralFolder as z2INonStructuralFolder
00250       >>> from zope.interface import directlyProvidedBy, directlyProvides
00251 
00252     A Folder is folderish generally::
00253       >>> is_folderish(self.folder)
00254       True
00255 
00256     But if we make it an INonStructuralFolder it is not::
00257       >>> base_implements = directlyProvidedBy(self.folder)
00258       >>> directlyProvides(self.folder, INonStructuralFolder, directlyProvidedBy(self.folder))
00259       >>> is_folderish(self.folder)
00260       False
00261       
00262     Now we revert our interface change and apply the z2 no-folderish interface::
00263       >>> directlyProvides(self.folder, base_implements)
00264       >>> is_folderish(self.folder)
00265       True
00266       >>> z2base_implements = self.folder.__implements__
00267       >>> self.folder.__implements__ = z2base_implements + (z2INonStructuralFolder,)
00268       >>> is_folderish(self.folder)
00269       False
00270 
00271     We again revert the interface change and check to make sure that
00272     PrincipiaFolderish is respected::
00273       >>> self.folder.__implements__ = z2base_implements
00274       >>> is_folderish(self.folder)
00275       True
00276       >>> self.folder.isPrincipiaFolderish = False
00277       >>> is_folderish(self.folder)
00278       False
00279 
00280     """
00281     # If the object explicitly states it doesn't want to be treated as a
00282     # structural folder, don't argue with it.
00283     folderish = bool(getattr(aq_base(obj), 'isPrincipiaFolderish', False))
00284     if not folderish:
00285         return False
00286     elif INonStructuralFolder.providedBy(obj):
00287         return False
00288     elif z2INonStructuralFolder.isImplementedBy(obj):
00289         # BBB: for z2 interface compat
00290         return False
00291     else:
00292         return folderish
00293 
00294 registerIndexableAttribute('is_folderish', is_folderish)
00295 

def CMFPlone.CatalogTool.object_provides (   object,
  portal,
  kw 
)

Definition at line 141 of file CatalogTool.py.

00141 
00142 def object_provides(object, portal, **kw):
00143     return [i.__identifier__ for i in providedBy(object).flattened()]
00144 
00145 registerIndexableAttribute('object_provides', object_provides)
00146 

Here is the caller graph for this function:

def CMFPlone.CatalogTool.sortable_title (   obj,
  portal,
  kwargs 
)
Helper method for to provide FieldIndex for Title.

>>> from Products.CMFPlone.CatalogTool import sortable_title

>>> self.folder.setTitle('Plone42 _foo')
>>> sortable_title(self.folder, self.portal)
'plone00000042 _foo'

Definition at line 153 of file CatalogTool.py.

00153 
00154 def sortable_title(obj, portal, **kwargs):
00155     """ Helper method for to provide FieldIndex for Title.
00156 
00157     >>> from Products.CMFPlone.CatalogTool import sortable_title
00158 
00159     >>> self.folder.setTitle('Plone42 _foo')
00160     >>> sortable_title(self.folder, self.portal)
00161     'plone00000042 _foo'
00162     """
00163     title = getattr(obj, 'Title', None)
00164     if title is not None:
00165         if safe_callable(title):
00166             title = title()
00167         if isinstance(title, basestring):
00168             sortabletitle = title.lower().strip()
00169             # Replace numbers with zero filled numbers
00170             sortabletitle = num_sort_regex.sub(zero_fill, sortabletitle)
00171             # Truncate to prevent bloat
00172             sortabletitle = safe_unicode(sortabletitle)[:30].encode('utf-8')
00173             return sortabletitle
00174     return ''
00175 
00176 registerIndexableAttribute('sortable_title', sortable_title)
00177 

Here is the call graph for this function:

def CMFPlone.CatalogTool.syndication_enabled (   obj,
  kwargs 
)
Get state of syndication.

Definition at line 296 of file CatalogTool.py.

00296 
00297 def syndication_enabled(obj, **kwargs):
00298     """Get state of syndication.
00299     """
00300     syn = getattr(aq_base(obj), 'syndication_information', _marker)
00301     if syn is not _marker:
00302         return True
00303     return False
00304 
00305 registerIndexableAttribute('syndication_enabled', syndication_enabled)
00306 

def CMFPlone.CatalogTool.zero_fill (   matchobj)

Definition at line 147 of file CatalogTool.py.

00147 
00148 def zero_fill(matchobj):
00149     return matchobj.group().zfill(8)


Variable Documentation

Definition at line 67 of file CatalogTool.py.

tuple CMFPlone.CatalogTool._marker = object()

Definition at line 49 of file CatalogTool.py.

tuple CMFPlone.CatalogTool.num_sort_regex = re.compile('\d+')

Definition at line 150 of file CatalogTool.py.

Definition at line 68 of file CatalogTool.py.

dictionary CMFPlone.CatalogTool.SIZE_CONST = {'kB': 1024, 'MB': 1024*1024, 'GB': 1024*1024*1024}

Definition at line 200 of file CatalogTool.py.

tuple CMFPlone.CatalogTool.SIZE_ORDER = ('GB', 'MB', 'kB')

Definition at line 201 of file CatalogTool.py.