Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions | Private Attributes
kupu.plone.librarytool.KupuLibraryTool Class Reference

List of all members.

Public Member Functions

def __init__
def addLibrary
def getLibraries
def deleteLibraries
def updateLibraries
def moveUp
def moveDown
def getNewTypeHandler
def setNewTypeHandler
def checkNewResourceTypes
def getPortalTypesForResourceType
def queryPortalTypesForResourceType
def invertTypeList
def addResourceType
def updateResourceTypes
def updatePreviewActions
def deleteResourceTypes
def deletePreviewActions
def getPreviewUrl
def getNormalUrl
def getToolbarFilters
def spellcheck

Private Member Functions

def _getExpressionContext
def _addNewTypesToResources
def _validate_portal_types
def _setToolbarFilters
def _getToolbarFilterOptions

Private Attributes

 _libraries
 _res_types
 _res_newtype
 _last_known_types
 _preview_actions
 _toolbar_filters
 _global_toolbar_filter

Detailed Description

A tool to aid Kupu libraries

Definition at line 30 of file librarytool.py.


Constructor & Destructor Documentation

Definition at line 35 of file librarytool.py.

00035 
00036     def __init__(self):
00037         self._libraries = []
00038         self._res_types = {}


Member Function Documentation

This method is called when the list of types in the system has changed.
It updates all current resource types to include or exclude new types as
appropriate.

Definition at line 174 of file librarytool.py.

00174 
00175     def _addNewTypesToResources(self):
00176         """This method is called when the list of types in the system has changed.
00177         It updates all current resource types to include or exclude new types as
00178         appropriate.
00179         """
00180         typetool = getToolByName(self, 'portal_types')
00181         alltypes = typetool.listTypeInfo()
00182         lastknown = self._last_known_types
00183         newtypes = dict.fromkeys([ t.id for t in alltypes if t.id not in lastknown])
00184 
00185         for resource_type in self._res_types.keys():
00186             handle_new = self.getNewTypeHandler(resource_type)
00187             if handle_new==NEWTYPE_ADD:
00188                 types = dict.fromkeys(self._res_types[resource_type])
00189                 types.update(newtypes)
00190                 self._res_types[resource_type] = types.keys()
00191         self._res_types = self._res_types
        

Here is the call graph for this function:

def kupu.plone.librarytool.KupuLibraryTool._getExpressionContext (   self,
  object 
) [private]

Definition at line 39 of file librarytool.py.

00039 
00040     def _getExpressionContext(self, object):
00041         portal = aq_parent(aq_inner(self))
00042         if object is None or not hasattr(object, 'aq_base'):
00043             folder = portal
00044         else:
00045             folder = object
00046             # Search up the containment hierarchy until we find an
00047             # object that claims it's a folder.
00048             while folder is not None:
00049                 if getattr(aq_base(folder), 'isPrincipiaFolderish', 0):
00050                     # found it.
00051                     break
00052                 else:
00053                     folder = aq_parent(aq_inner(folder))
00054         ec = createExprContext(folder, portal, object)
00055         return ec

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 364 of file librarytool.py.

00364 
00365     def _getToolbarFilterOptions(self):
00366         return getattr(self, '_toolbar_filters', {})

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool._setToolbarFilters (   self,
  filters,
  globalfilter 
) [private]
Set the toolbar filtering
filter is a list of records with: id, visible, override

Definition at line 320 of file librarytool.py.

00320 
00321     def _setToolbarFilters(self, filters, globalfilter):
00322         """Set the toolbar filtering
00323         filter is a list of records with: id, visible, override"""
00324         clean = {}
00325         for f in filters:
00326             id = f['id']
00327             visible = bool(f.get('visible', False))
00328             expr = f.get('override', None)
00329 
00330             if not id:
00331                 continue
00332 
00333             if expr:
00334                 expr = Expression(expr)
00335             else:
00336                 expr = None
00337             clean[id] = dict(id=id, visible=visible, override=expr)
00338 
00339         self._toolbar_filters = clean
00340         if globalfilter:
00341             self._global_toolbar_filter = Expression(globalfilter)
00342         else:
00343             self._global_toolbar_filter = None

Here is the call graph for this function:

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool._validate_portal_types (   self,
  resource_type,
  portal_types 
) [private]

Definition at line 204 of file librarytool.py.

00204 
00205     def _validate_portal_types(self, resource_type, portal_types):
00206         typetool = getToolByName(self, 'portal_types')
00207         all_portal_types = dict([ (t.id, 1) for t in typetool.listTypeInfo()])
00208 
00209         portal_types = [ptype.strip() for ptype in portal_types if ptype]
00210         for p in portal_types:
00211             if p not in all_portal_types:
00212                 raise KupuError, "Resource type: %s, invalid type: %s" % (resource_type, p)
00213         return portal_types

Here is the call graph for this function:

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.addLibrary (   self,
  id,
  title,
  uri,
  src,
  icon 
)
See ILibraryManager

Definition at line 56 of file librarytool.py.

00056 
00057     def addLibrary(self, id, title, uri, src, icon):
00058         """See ILibraryManager"""
00059         lib = dict(id=id, title=title, uri=uri, src=src, icon=icon)
00060         for key, value in lib.items():
00061             if key=='id':
00062                 lib[key] = value
00063             else:
00064                 if not(value.startswith('string:') or value.startswith('python:')):
00065                     value = 'string:' + value
00066                 lib[key] = Expression(value)
00067         self._libraries.append(lib)

Here is the call graph for this function:

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.addResourceType (   self,
  resource_type,
  portal_types,
  mode = 'whitelist' 
)
See IResourceTypeMapper

Definition at line 222 of file librarytool.py.

00222 
00223     def addResourceType(self, resource_type, portal_types, mode='whitelist'):
00224         """See IResourceTypeMapper"""
00225         newtype = NEWTYPE_IGNORE
00226         if mode != 'whitelist':
00227             portal_types = self.invertTypeList(portal_types)
00228             newtype = NEWTYPE_ADD
00229         portal_types = self._validate_portal_types(resource_type, portal_types)
00230         self._res_types[resource_type] = tuple(portal_types)
00231         self.setNewTypeHandler(resource_type, newtype)

Here is the call graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.checkNewResourceTypes (   self,
  resource_type = None 
)

Definition at line 153 of file librarytool.py.

00153 
00154     def checkNewResourceTypes(self, resource_type=None):
00155         # Check for new types added. It would be nice if this
00156         # was called automatically but not every time we query a
00157         # resource.
00158         if resource_type != None:
00159             handle_new = self.getNewTypeHandler(resource_type)
00160             if handle_new == NEWTYPE_IGNORE:
00161                 return
00162                 
00163         typetool = getToolByName(self, 'portal_types')
00164         new_portal_types = dict([ (t.id, 1) for t in typetool.listTypeInfo()])
00165         if getattr(self, '_last_known_types', None) is None:
00166             # Migrate from old version
00167             self._last_known_types = new_portal_types
00168         else:
00169             for t in self._last_known_types:
00170                 if t in new_portal_types:
00171                     del new_portal_types[t]
00172             if new_portal_types:
00173                 self._addNewTypesToResources()

Here is the call graph for this function:

Here is the caller graph for this function:

See ILibraryManager

Definition at line 86 of file librarytool.py.

00086 
00087     def deleteLibraries(self, indices):
00088         """See ILibraryManager"""
00089         indices.sort()
00090         indices.reverse()
00091         for index in indices:
00092             del self._libraries[index]

Here is the caller graph for this function:

See IResourceTypeMapper

Definition at line 285 of file librarytool.py.

00285 
00286     def deletePreviewActions(self, preview_types):
00287         """See IResourceTypeMapper"""
00288         action_map = getattr(self, '_preview_actions', {})
00289         for type in preview_types:
00290             del action_map[type]
00291         self._preview_actions = action_map

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.deleteResourceTypes (   self,
  resource_types 
)
See IResourceTypeMapper

Definition at line 278 of file librarytool.py.

00278 
00279     def deleteResourceTypes(self, resource_types):
00280         """See IResourceTypeMapper"""
00281         existing = self._res_types
00282         for type in resource_types:
00283             if existing.has_key(type):
00284                 del existing[type]

Here is the caller graph for this function:

See ILibraryManager

Definition at line 68 of file librarytool.py.

00068 
00069     def getLibraries(self, context):
00070         """See ILibraryManager"""
00071         expr_context = self._getExpressionContext(context)
00072         libraries = []
00073         for library in self._libraries:
00074             lib = {}
00075             for key in library.keys():
00076                 if isinstance(library[key], str):
00077                     lib[key] = library[key]
00078                 else:
00079                     # Automatic migration from old version.
00080                     if key=='id':
00081                         lib[key] = library[key] = library[key].text
00082                     else:
00083                         lib[key] = library[key](expr_context)
00084             libraries.append(lib)
00085         return tuple(libraries)

Here is the call graph for this function:

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.getNewTypeHandler (   self,
  resource_type 
)
Should unknown portal types be added to the list or ignored

Definition at line 133 of file librarytool.py.

00133 
00134     def getNewTypeHandler(self, resource_type):
00135         """Should unknown portal types be added to the list or ignored"""
00136         _res_newtype = getattr(self, '_res_newtype', None)
00137         if _res_newtype is None:
00138             self._res_newtype = _res_newtype = {}
00139             for k in self._res_types:
00140                 if k in ('linkable', 'containsanchors', 'composable'):
00141                     _res_newtype[k] = NEWTYPE_ADD
00142                 else:
00143                     _res_newtype[k] = NEWTYPE_IGNORE
00144             self._res_newtype = _res_newtype
00145 
00146         return _res_newtype.get(resource_type, NEWTYPE_IGNORE)

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.getNormalUrl (   self,
  portal_type,
  url 
)

Definition at line 306 of file librarytool.py.

00306 
00307     def getNormalUrl(self, portal_type, url):
00308         action_map = getattr(self, '_preview_actions', {})
00309         if portal_type in action_map:
00310             expr = action_map[portal_type].get('normal', None)
00311             if expr:
00312                 data = {
00313                     'object_url':   url,
00314                     'portal_type':  portal_type,
00315                     'modules':      SecureModuleImporter,
00316                 }
00317                 context = getEngine().getContext(data)
00318                 return expr(context)
00319         return url

Here is the call graph for this function:

See IResourceTypeMapper

Definition at line 192 of file librarytool.py.

00192 
00193     def getPortalTypesForResourceType(self, resource_type):
00194         """See IResourceTypeMapper"""
00195         self.checkNewResourceTypes()
00196         types = self._res_types[resource_type]
00197         return types[:]

Here is the call graph for this function:

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.getPreviewUrl (   self,
  portal_type,
  url 
)

Definition at line 292 of file librarytool.py.

00292 
00293     def getPreviewUrl(self, portal_type, url):
00294         action_map = getattr(self, '_preview_actions', {})
00295         if portal_type in action_map:
00296             expr = action_map[portal_type]['expression']
00297             if expr:
00298                 data = {
00299                     'object_url':   url,
00300                     'portal_type':  portal_type,
00301                     'modules':      SecureModuleImporter,
00302                 }
00303                 context = getEngine().getContext(data)
00304                 return expr(context)
00305         return None

Here is the call graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.getToolbarFilters (   self,
  context,
  field = None 
)

Definition at line 344 of file librarytool.py.

00344 
00345     def getToolbarFilters(self, context, field=None):
00346         expr_context = self._getExpressionContext(context)
00347         expr_context.setGlobal('field', field)
00348         filters = getattr(self, '_toolbar_filters', {})
00349         gfilter = getattr(self, '_global_toolbar_filter', None)
00350         if gfilter:
00351             gvisible = gfilter(expr_context)
00352         else:
00353             gvisible = None
00354 
00355         visible = {}
00356         for k in filters:
00357             f = filters[k]
00358             override = f.get('override', None)
00359             if override:
00360                 visible[k] = bool(override(expr_context))
00361             else:
00362                 visible[k] = f['visible']
00363         return visible, gvisible

Here is the call graph for this function:

Convert a list of portal_types to a list of all the types not in the list

Definition at line 214 of file librarytool.py.

00214 
00215     def invertTypeList(self, types):
00216         """Convert a list of portal_types to a list of all the types not in the list"""
00217         typetool = getToolByName(self, 'portal_types')
00218         portal_types = dict([ (t.id, 1) for t in typetool.listTypeInfo()])
00219         res = [ name for name in portal_types if name not in types ]
00220         res.sort()
00221         return res

Here is the call graph for this function:

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.moveDown (   self,
  indices 
)
See ILibraryManager

Definition at line 119 of file librarytool.py.

00119 
00120     def moveDown(self, indices):
00121         """See ILibraryManager"""
00122         indices.sort()
00123         indices.reverse()
00124         libraries = self._libraries[:]
00125         for index in indices:
00126             new_index = index + 1
00127             if new_index >= len(libraries):
00128                 new_index = 0
00129                 #new_index = ((index + 1) % len(libraries)) - 1
00130             libraries[index], libraries[new_index] = \
00131                               libraries[new_index], libraries[index]
00132         self._libraries = libraries

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.moveUp (   self,
  indices 
)
See ILibraryManager

Definition at line 109 of file librarytool.py.

00109 
00110     def moveUp(self, indices):
00111         """See ILibraryManager"""
00112         indices.sort()
00113         libraries = self._libraries[:]
00114         for index in indices:
00115             new_index = index - 1
00116             libraries[index], libraries[new_index] = \
00117                               libraries[new_index], libraries[index]
00118         self._libraries = libraries

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.queryPortalTypesForResourceType (   self,
  resource_type,
  default = None 
)
See IResourceTypeMapper

Definition at line 198 of file librarytool.py.

00198 
00199     def queryPortalTypesForResourceType(self, resource_type, default=None):
00200         """See IResourceTypeMapper"""
00201         if not self._res_types.has_key(resource_type):
00202             return default
00203         return self.getPortalTypesForResourceType(resource_type)

Here is the call graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.setNewTypeHandler (   self,
  resource_type,
  mode 
)
Update how unknown types are handled.

Definition at line 147 of file librarytool.py.

00147 
00148     def setNewTypeHandler(self, resource_type, mode):
00149         """Update how unknown types are handled."""
00150         if self.getNewTypeHandler(resource_type) != mode:
00151             self._res_newtype[resource_type] = mode
00152             self._res_newtype = self._res_newtype # Flag ourselves as modified.

Here is the call graph for this function:

Here is the caller graph for this function:

Call spellchecker: WARNING this functionality may not work,
it is not part of the standard Plone+kupu implementation.
Some user assembly required.

Definition at line 367 of file librarytool.py.

00367 
00368     def spellcheck(self, REQUEST):
00369         """Call spellchecker: WARNING this functionality may not work,
00370         it is not part of the standard Plone+kupu implementation.
00371         Some user assembly required."""
00372         from Products.kupu.python.spellcheck import SpellChecker, format_result
00373         data = REQUEST["text"]
00374         c = SpellChecker()
00375         result = c.check(data)
00376         if result == None:
00377             result = ""
00378         else:
00379             result = format_result(result)
00380         REQUEST.RESPONSE.setHeader("Content-Type","text/xml, charset=utf-8")
00381         REQUEST.RESPONSE.setHeader("Content-Length",str(len(result)))
00382         return result

Here is the call graph for this function:

See ILibraryManager

Definition at line 93 of file librarytool.py.

00093 
00094     def updateLibraries(self, libraries):
00095         """See ILibraryManager"""
00096         for index, lib in enumerate(self._libraries):
00097             dic = libraries[index]
00098             for key in lib.keys():
00099                 if dic.has_key(key):
00100                     value = dic[key]
00101                     if key=='id':
00102                         lib[key] = value
00103                     else:
00104                         if not(value.startswith('string:') or
00105                                value.startswith('python:')):
00106                             value = 'string:' + value
00107                         lib[key] = Expression(value)
00108             self._libraries[index] = lib

Here is the caller graph for this function:

def kupu.plone.librarytool.KupuLibraryTool.updatePreviewActions (   self,
  preview_actions 
)
Now a misnomer: actually updates preview, normal, and scaling data

Definition at line 249 of file librarytool.py.

00249 
00250     def updatePreviewActions(self, preview_actions):
00251         """Now a misnomer: actually updates preview, normal, and scaling data"""
00252         action_map = {}
00253 
00254         for a in preview_actions:
00255             portal_type = a.get('portal_type', '')
00256             preview = a.get('expression', '')
00257             normal = a.get('normal', None)
00258             if normal:
00259                 normal = Expression(normal)
00260             scalefield = a.get('scalefield', 'image')
00261             defscale = a.get('defscale', 'image_preview')
00262             classes = a.get('classes', '')
00263             if isinstance(classes, basestring):
00264                 classes = classes.split('\n')
00265             classes = tuple(classes)
00266             mediatype = a.get('mediatype', 'image')
00267             if not portal_type:
00268                 continue
00269             action_map[portal_type] = {
00270                 'expression': Expression(preview),
00271                 'normal': normal,
00272                 'scalefield': scalefield,
00273                 'defscale': defscale,
00274                 'classes': classes,
00275                 'mediatype': mediatype,
00276             }
00277         self._preview_actions = action_map

Here is the caller graph for this function:

See IResourceTypeMapper

Definition at line 232 of file librarytool.py.

00232 
00233     def updateResourceTypes(self, type_info):
00234         """See IResourceTypeMapper"""
00235         type_map = self._res_types
00236         
00237         for type in type_info:
00238             resource_type = type['resource_type']
00239             if not resource_type:
00240                 continue
00241             portal_types = self._validate_portal_types(resource_type, type.get('portal_types', ()))
00242             old_type = type.get('old_type', None)
00243             if old_type:
00244                 del type_map[old_type]
00245             type_map[resource_type] = tuple(portal_types)
00246             nt = type.get('newtypes', None)
00247             if nt is not None:
00248                 self.setNewTypeHandler(resource_type, nt)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 340 of file librarytool.py.

Definition at line 166 of file librarytool.py.

Definition at line 36 of file librarytool.py.

Definition at line 276 of file librarytool.py.

Definition at line 137 of file librarytool.py.

Definition at line 37 of file librarytool.py.

Definition at line 338 of file librarytool.py.


The documentation for this class was generated from the following file: