Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
kupu.plone.plonedrawers.InfoAdaptor Class Reference

List of all members.

Public Member Functions

def __init__
def wfTitles
def icon
def media
def classes
def sizes
def get_image_sizes
def getState
def info_object
def info

Public Attributes

 url_tool
 uid_catalog
 portal_interface
 workflow_tool
 workflow_states
 linkbyuid
 coll_types
 anchor_types
 portal_base
 prefix_length
 resource_type
 ttool
 srctail
 showimagesize
 base
 security
 tool

Detailed Description

Convert either an object or a brain into an information dictionary.

Definition at line 172 of file plonedrawers.py.


Constructor & Destructor Documentation

def kupu.plone.plonedrawers.InfoAdaptor.__init__ (   self,
  tool,
  resource_type,
  portal 
)

Definition at line 174 of file plonedrawers.py.

00174 
00175     def __init__(self, tool, resource_type, portal):
00176         self.url_tool = getToolByName(portal, 'portal_url')
00177         self.uid_catalog = getToolByName(portal, 'uid_catalog', None)
00178         self.portal_interface = getToolByName(portal, 'portal_interface')
00179         self.workflow_tool = getToolByName(portal, 'portal_workflow')
00180         self.workflow_states = self.wfTitles()
00181         self.linkbyuid = tool.getLinkbyuid()
00182         self.coll_types = tool.getResourceType('collection').portal_types
00183         self.anchor_types =  tool.getResourceType('containsanchors').portal_types
00184         self.portal_base = self.url_tool.getPortalPath()
00185         self.prefix_length = len(self.portal_base)+1
00186         self.resource_type = resource_type
00187         self.ttool = getToolByName(portal, 'portal_types')
00188         
00189         instance = tool.REQUEST.get('instance', '')
00190         if instance:
00191             instance = 'instance=%s&' % tool.REQUEST.instance
00192 
00193         self.srctail = 'kupucollection.xml?'+instance+'resource_type=' + resource_type.name
00194         self.showimagesize = resource_type.name=='mediaobject'
00195 
00196         # The redirecting url must be absolute otherwise it won't work for
00197         # preview when the page is using portal_factory
00198         # The absolute to relative conversion when the document is saved
00199         # should strip the url right back down to resolveuid/whatever.
00200         self.base = self.url_tool()
00201         self.security = getSecurityManager()
00202         self.tool = tool


Member Function Documentation

def kupu.plone.plonedrawers.InfoAdaptor.classes (   self,
  portal_type 
)

Definition at line 235 of file plonedrawers.py.

00235 
00236     def classes(self, portal_type):
00237         stored = self.tool.getClassesForType(portal_type)
00238         classes = []
00239         for c in stored:
00240             c = c.strip()
00241             if not c:
00242                 continue
00243             if '|' in c:
00244                 title, classname = c.split('|', 1)
00245                 classes.append({'title': title, 'classname': classname})
00246             else:
00247                 classes.append({'title': c, 'classname': c})
00248         return classes

Here is the caller graph for this function:

def kupu.plone.plonedrawers.InfoAdaptor.get_image_sizes (   self,
  obj,
  portal_type,
  url 
)

Definition at line 266 of file plonedrawers.py.

00266 
00267     def get_image_sizes(self, obj, portal_type, url):
00268         cache_key = (get_ident(), self.portal_base, portal_type)
00269         if not IMAGE_SIZES_CACHE.has_key(cache_key):
00270             IMAGE_SIZES_CACHE[cache_key] = {}
00271             imagefield = self.tool.getScaleFieldForType(portal_type)
00272             # if getId is not callable, we assume that we have a brain and
00273             # need to get the object
00274             if not callable(obj.getId):
00275                 if getattr(obj, 'getObject', None) is None:
00276                     return
00277                 try:
00278                     obj = obj.getObject()
00279                 except:
00280                     return 
00281                 
00282             if getattr(obj, 'getField', None) is None:
00283                 return
00284             image_field = obj.getWrappedField(imagefield)
00285             if image_field is None:
00286                 return
00287             if getattr(image_field, 'getAvailableSizes', None) is None:
00288                 return
00289             image_sizes = image_field.getAvailableSizes(obj)
00290             sizes = [(v[0], v[1], k, '%s_%s' % (imagefield,k)) for k,v in image_sizes.items()]
00291             sizes.sort()
00292             sizes.reverse()
00293             IMAGE_SIZES_CACHE[cache_key] = sizes
00294         else:
00295             sizes = IMAGE_SIZES_CACHE[cache_key]
00296         results = []
00297         for width, height, key, action in sizes:
00298             results.append({'label':"%s (%s, %s)" % (key.capitalize(), width, height),
00299                             'uri':"%s/%s" % (url, action),
00300                             'action': action},)
00301         return results
    

Here is the caller graph for this function:

def kupu.plone.plonedrawers.InfoAdaptor.getState (   self,
  review_state 
)

Definition at line 302 of file plonedrawers.py.

00302 
00303     def getState(self, review_state):
00304         if review_state:
00305             className = 'state-'+review_state
00306             review_state = self.workflow_states.get(review_state, review_state)
00307         else:
00308             className = None
00309         return review_state, className

Here is the caller graph for this function:

def kupu.plone.plonedrawers.InfoAdaptor.icon (   self,
  portal_type 
)

Definition at line 221 of file plonedrawers.py.

00221 
00222     def icon(self, portal_type):
00223         type = self.ttool.getTypeInfo(portal_type)
00224         if type is None:
00225             return None
00226         return "%s/%s" % (self.base, type.getIcon())

Here is the caller graph for this function:

def kupu.plone.plonedrawers.InfoAdaptor.info (   self,
  brain,
  allowLink = True 
)
Get information from a brain

Definition at line 398 of file plonedrawers.py.

00398 
00399     def info(self, brain, allowLink=True):
00400         '''Get information from a brain'''
00401         __traceback_info__ = (brain, allowLink)
00402         id = brain.getId
00403         url = brain.getURL()
00404         portal_type = brain.portal_type
00405         collection = portal_type in self.coll_types
00406         tool = self.tool
00407         preview = tool.getPreviewUrl(portal_type, url)
00408 
00409         # Path for the uid catalog doesn't have the leading '/'
00410         path = brain.getPath()
00411         UID = None
00412         if path and self.uid_catalog:
00413             try:
00414                 metadata = self.uid_catalog.getMetadataForUID(path[self.prefix_length:])
00415             except KeyError:
00416                 metadata = None
00417             if metadata:
00418                 UID = metadata.get('UID', None)
00419 
00420         if UID:
00421             id = UID
00422 
00423         if collection and self.resource_type.allow_browse:
00424             src = brain.getURL()
00425             if not src.endswith('/'): src += '/'
00426             src += self.srctail
00427         else:
00428             src = None
00429 
00430         if UID and self.linkbyuid:
00431             url = self.base+'/resolveuid/%s' % UID
00432 
00433         if self.showimagesize:
00434             normal = tool.getNormalUrl(portal_type, url)
00435         else:
00436             normal = url
00437 
00438         sizes = self.get_image_sizes(brain, portal_type, url)
00439         defscale = self.tool.getDefaultScaleForType(portal_type)
00440         media = self.media(portal_type)
00441         classes = self.classes(portal_type)
00442 
00443         icon = self.icon(portal_type)
00444         size, width, height = self.sizes(brain)
00445 
00446         title = filterControlChars(brain.Title or brain.getId)
00447         description = newline_to_br(html_quote(brain.Description))
00448         linkable = None
00449         if allowLink:
00450             linkable = True
00451             collection = False
00452 
00453         anchor = portal_type in self.anchor_types
00454         review_state, className = self.getState(brain.review_state)
00455 
00456         return {
00457             'id': id,
00458             'url': normal,
00459             'portal_type': portal_type,
00460             'collection':  collection,
00461             'icon': icon,
00462             'size': size,
00463             'width': width,
00464             'height': height,
00465             'preview': preview,
00466             'sizes': sizes,
00467             'defscale': defscale,
00468             'media': media,
00469             'classes': classes,
00470             'title': title,
00471             'description': description,
00472             'linkable': linkable,
00473             'src': src,
00474             'anchor': anchor,
00475             'state': review_state,
00476             'class': className,
00477             }
00478 

Here is the call graph for this function:

Here is the caller graph for this function:

def kupu.plone.plonedrawers.InfoAdaptor.info_object (   self,
  obj,
  allowLink = True 
)
Get information from a content object

Definition at line 310 of file plonedrawers.py.

00310 
00311     def info_object(self, obj, allowLink=True):
00312         '''Get information from a content object'''
00313 
00314         # Parent folder might not be accessible if we came here from a
00315         # search.
00316         if not self.security.checkPermission('View', obj):
00317             return None
00318 
00319         __traceback_info__ = (obj, allowLink)
00320         id = None
00321         UID = None
00322         try:
00323             if self.portal_interface.objectImplements(obj,
00324                 'Products.Archetypes.interfaces.referenceable.IReferenceable'):
00325                 UID = getattr(obj.aq_explicit, 'UID', None)
00326                 if UID:
00327                     UID = UID()
00328                     id = UID
00329 
00330             if not id:
00331                 id = obj.absolute_url(relative=1)
00332 
00333             portal_type = getattr(obj, 'portal_type','')
00334             collection = portal_type in self.coll_types
00335             tool = self.tool
00336             url = obj.absolute_url()
00337             preview = tool.getPreviewUrl(portal_type, url)
00338 
00339             if collection and self.resource_type.allow_browse:
00340                 src = obj.absolute_url()
00341                 if not src.endswith('/'): src += '/'
00342                 src += self.srctail
00343             else:
00344                 src = None
00345 
00346             if UID and self.linkbyuid:
00347                 url = self.base+'/resolveuid/%s' % UID
00348 
00349             if self.showimagesize:
00350                 normal = tool.getNormalUrl(portal_type, url)
00351             else:
00352                 normal = url
00353 
00354             sizes = self.get_image_sizes(obj, portal_type, url)
00355             defscale = self.tool.getDefaultScaleForType(portal_type)
00356 
00357             media = self.media(portal_type)
00358             classes = self.classes(portal_type)
00359 
00360             icon = self.icon(portal_type)
00361             size, width, height = self.sizes(obj)
00362 
00363             title = filterControlChars(obj.Title() or obj.getId())
00364             description = newline_to_br(html_quote(obj.Description()))
00365 
00366             linkable = None
00367             if allowLink:
00368                 linkable = True
00369                 collection = False
00370 
00371             anchor = portal_type in self.anchor_types
00372             review_state, className = self.getState(self.workflow_tool.getInfoFor(obj, 'review_state', None))
00373 
00374             return {
00375                 'id': id,
00376                 'url': normal,
00377                 'portal_type': portal_type,
00378                 'collection':  collection,
00379                 'icon': icon,
00380                 'size': size,
00381                 'width': width,
00382                 'height': height,
00383                 'preview': preview,
00384                 'sizes': sizes,
00385                 'defscale': defscale,
00386                 'media': media,
00387                 'classes': classes,
00388                 'title': title,
00389                 'description': description,
00390                 'linkable': linkable,
00391                 'src': src,
00392                 'anchor': anchor,
00393                 'state': review_state,
00394                 'class': className,
00395                 }
00396         except Unauthorized:
00397             return None

Here is the call graph for this function:

def kupu.plone.plonedrawers.InfoAdaptor.media (   self,
  portal_type 
)
Get the media type to be included in the xml.
Since 'image' is the default we can omit it.

Definition at line 227 of file plonedrawers.py.

00227 
00228     def media(self, portal_type):
00229         """Get the media type to be included in the xml.
00230         Since 'image' is the default we can omit it."""
00231         media = self.tool.getMediaForType(portal_type)
00232         if media=='image':
00233             return None
00234         return media

Here is the caller graph for this function:

def kupu.plone.plonedrawers.InfoAdaptor.sizes (   self,
  obj 
)
Returns size, width, height

Definition at line 249 of file plonedrawers.py.

00249 
00250     def sizes(self, obj):
00251         """Returns size, width, height"""
00252         if not self.showimagesize:
00253             return None, None, None
00254         try:
00255             if not callable(obj.getId):
00256                 obj = obj.getObject() # Must be a brain
00257             size = self.tool.getObjSize(obj)
00258         except:
00259             size = None
00260 
00261         width = getattr(obj, 'width', None)
00262         height = getattr(obj, 'height', None)
00263         if callable(width): width = width()
00264         if callable(height): height = height()
00265         return size, width, height

Here is the caller graph for this function:

Definition at line 203 of file plonedrawers.py.

00203 
00204     def wfTitles(self):
00205         wt = self.workflow_tool
00206         try:
00207             states = wt.listWFStatesByTitle()
00208         except AttributeError:
00209             # Older Plone versions
00210             states = {}
00211             for wf in wt.objectValues():
00212                 state_folder = getattr(wf, 'states', None)
00213                 if state_folder is not None:
00214                     for s in state_folder.objectValues():
00215                         title, id = s.title, s.getId()
00216                         if title:
00217                             states[id] = title
00218             return states
00219 
00220         return dict([(id,title) for (title,id) in states])

Here is the call graph for this function:


Member Data Documentation

Definition at line 182 of file plonedrawers.py.

Definition at line 199 of file plonedrawers.py.

Definition at line 181 of file plonedrawers.py.

Definition at line 180 of file plonedrawers.py.

Definition at line 183 of file plonedrawers.py.

Definition at line 177 of file plonedrawers.py.

Definition at line 184 of file plonedrawers.py.

Definition at line 185 of file plonedrawers.py.

Definition at line 200 of file plonedrawers.py.

Definition at line 193 of file plonedrawers.py.

Definition at line 192 of file plonedrawers.py.

Definition at line 201 of file plonedrawers.py.

Definition at line 186 of file plonedrawers.py.

Definition at line 176 of file plonedrawers.py.

Definition at line 175 of file plonedrawers.py.

Definition at line 179 of file plonedrawers.py.

Definition at line 178 of file plonedrawers.py.


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