Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions
kupu.plone.plonedrawers.PloneDrawers Class Reference
Inheritance diagram for kupu.plone.plonedrawers.PloneDrawers:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def getPreviewable
def getResourceType
def getFolderItems
def getSingleObjectInfo
def getBreadCrumbs
def getCurrentObject
def getCurrentParent
def getCurrentSelection
def getMyItems
def getRecentItems
def kupuSearch
def infoForQuery
def infoForBrains
def canCaption
def getLabelFromWidget
def getKupuFields
def supportedCaptioning
def unsupportedCaptioning
def transformIsEnabled
def isUploadSupported
def getBaseUrl
def getUploadImageSizes
def getUploadImageClasses
def convertUidsToPaths

Static Public Attributes

tuple security = ClassSecurityInfo()

Private Member Functions

def _getKupuFields
def _getImageSizes

Detailed Description

Definition at line 479 of file plonedrawers.py.


Member Function Documentation

Definition at line 917 of file plonedrawers.py.

00917 
00918     def _getImageSizes(self):
00919         resource_type = self.getResourceType()
00920         portal = getToolByName(self, 'portal_url').getPortalObject()
00921         mediatypes = resource_type.get_portal_types()
00922         catalog = getToolByName(self, 'portal_catalog')
00923         adaptor = InfoAdaptor(self, resource_type, portal)
00924 
00925         sizes = {}
00926         for portal_type in mediatypes:
00927             brains = catalog.searchResults(portal_type=portal_type, limit=1)[:1]
00928             if brains:
00929                 info = adaptor.get_image_sizes(brains[0], portal_type, '')
00930                 if info:
00931                     for i in info:
00932                         sizes[i['uri']] = 1
00933         return sizes

Here is the call graph for this function:

Yield all fields which are editable using kupu

Definition at line 807 of file plonedrawers.py.

00807 
00808     def _getKupuFields(self):
00809         """Yield all fields which are editable using kupu"""
00810         archetype_tool = getToolByName(self, 'archetype_tool', None)
00811         types = archetype_tool.listRegisteredTypes()
00812         for t in types:
00813             schema = t.get('schema')
00814             if schema:
00815                 typename = getattr(t['klass'], 'archetype_name', t['portal_type'])
00816                 for f in schema.fields():
00817                     w = f.widget
00818                     if isinstance(w, (RichWidget, VisualWidget)):
00819                         yield typename, f, t['portal_type']

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 786 of file plonedrawers.py.

00786 
00787     def canCaption(self, field):
00788         return (getattr(field, 'default_output_type', None) in
00789             ('text/x-html-safe', 'text/x-html-captioned'))

Here is the caller graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.convertUidsToPaths (   self,
  value = None 
)
Convert a list of uids
(or a single space or newline separated string)
to a list of paths

Definition at line 935 of file plonedrawers.py.

00935 
00936     def convertUidsToPaths(self, value=None):
00937         """Convert a list of uids
00938         (or a single space or newline separated string)
00939         to a list of paths"""
00940         uid_catalog = getToolByName(self, 'uid_catalog')
00941         ppath = getToolByName(self, 'portal_url').getPortalPath()[1:]+'/'
00942         
00943         if isinstance(value, basestring):
00944             value = value.split()
00945         if not value:
00946             return []
00947             
00948         brains = uid_catalog.searchResults(UID=value)
00949         paths = [ppath+b.getPath() for b in brains]
00950         return paths
00951 
00952 InitializeClass(PloneDrawers)

Here is the call graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.getBaseUrl (   self,
  context,
  include_factory = False,
  resource_type = None 
)

Definition at line 866 of file plonedrawers.py.

00866 
00867     def getBaseUrl(self, context, include_factory=False, resource_type=None):
00868         base = context.absolute_url()
00869 
00870         if resource_type:
00871             rt = self.getResourceType(resource_type);
00872             sd = rt.startup_directory
00873             if sd:
00874                 base = sd
00875 
00876         posfactory = base.find('/portal_factory/')
00877         if posfactory>0:
00878             if include_factory:
00879                 base = base[:posfactory+15]
00880             else:
00881                 base = base[:posfactory]
00882         return base

Here is the call graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.getBreadCrumbs (   self,
  context,
  template 
)
Return breadcrumbs for drawer

Definition at line 597 of file plonedrawers.py.

00597 
00598     def getBreadCrumbs(self, context, template):
00599         """Return breadcrumbs for drawer"""
00600         resource_type = self.getResourceType()
00601         if not resource_type.allow_browse:
00602             return []
00603 
00604         id = template.getId()
00605         putils = getToolByName(self, 'plone_utils')
00606         path = [ ("Home", getToolByName(self, 'portal_url')())]
00607 
00608         if getattr(putils.aq_base, 'createBreadCrumbs', None) is not None:
00609             path = path + [(x['Title'],x['absolute_url']) for x in putils.createBreadCrumbs(context)]
00610         else:
00611             path = path + self.breadcrumbs(context)[1:-1]
00612 
00613         # Last crumb should not be linked:
00614         path[-1] = (path[-1][0], None)
00615 
00616         crumbs = []
00617         for title,url in path:
00618             if url:
00619                 url = self.kupuUrl("%s/%s" % (url.rstrip('/'), id))
00620             crumbs.append({'Title':title, 'absolute_url':url})
00621 
00622         return crumbs

Here is the call graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.getCurrentObject (   self,
  portal = None 
)
Returns object information for a selected object

Definition at line 624 of file plonedrawers.py.

00624 
00625     def getCurrentObject(self, portal=None):
00626         '''Returns object information for a selected object'''
00627         request = self.REQUEST
00628         if portal is None:
00629             portal = getToolByName(self, 'portal_url').getPortalObject()
00630         reference_tool = getToolByName(portal, 'reference_catalog')
00631         rt = self.getResourceType()
00632         portal_types = rt.portal_types
00633         src = request.get('src')
00634         # Remove any spurious query string or fragment
00635         for c in '#?':
00636             if c in src:
00637                 src = src.split(c, 1)[0]
00638 
00639         match = UIDURL.match(src)
00640 
00641         if match:
00642             # src=http://someurl/resolveuid/<uid>
00643             uid = match.group(1)
00644             obj = reference_tool.lookupObject(uid)
00645             
00646         elif src and '://' in src:
00647             # src=http://someurl/somepath/someobject
00648             base = portal.absolute_url()
00649             if src.startswith(base):
00650                 src = src[len(base):].lstrip('/')
00651             try:
00652                 obj = portal.restrictedTraverse(src)
00653                 if portal_types:
00654                     while not shasattr(obj.aq_base, 'portal_type'):
00655                         obj = obj.aq_parent
00656                     while obj.portal_type not in portal_types:
00657                         obj = obj.aq_parent
00658                         if obj is portal:
00659                             return []
00660             except (KeyError, AttributeError):
00661                 return []
00662         else:
00663             # src=<uid1> <uid2> ... <uidn>
00664             src = src.split(' ') # src is a list of uids.
00665             objects = [ reference_tool.lookupObject(uid) for uid in src ]
00666             objects = [ o for o in objects if o is not None ]
00667             return objects
00668 
00669         if obj is None:
00670             return None
00671         return [obj]

Here is the call graph for this function:

Here is the caller graph for this function:

Find the parent of the object specified in the src string.
If multiple objects and they don't have the same parent, or if no suitable object
returns None, otherwise returns the parent.

Definition at line 673 of file plonedrawers.py.

00673 
00674     def getCurrentParent(self):
00675         """Find the parent of the object specified in the src string.
00676         If multiple objects and they don't have the same parent, or if no suitable object
00677         returns None, otherwise returns the parent."""
00678         objects = self.getCurrentObject()
00679         parent = None
00680         for obj in objects:
00681             if parent is not None and parent is not obj.aq_parent:
00682                 return None
00683             parent = obj.aq_parent
00684         return parent

Here is the call graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.getCurrentSelection (   self,
  portal = None 
)
Returns object information for a selected object

Definition at line 686 of file plonedrawers.py.

00686 
00687     def getCurrentSelection(self, portal=None):
00688         '''Returns object information for a selected object'''
00689         objects = self.getCurrentObject(portal)
00690         return self.infoForBrains(objects, self.getResourceType(), portal)

Here is the call graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.getFolderItems (   self,
  context,
  resource_type = None,
  portal = None 
)
List the contents of a folder

Definition at line 543 of file plonedrawers.py.

00543 
00544     def getFolderItems(self, context, resource_type=None, portal=None):
00545         """List the contents of a folder"""
00546         resource_type = self.getResourceType(resource_type)
00547         collection_type = self.getResourceType('collection')
00548         coll_types = collection_type.portal_types
00549         link_types = resource_type.portal_types
00550         allow_browse = resource_type.allow_browse
00551 
00552         if portal is None:
00553             portal = getToolByName(self, 'portal_url').getPortalObject()
00554 
00555         query = resource_type.getQuery()
00556         content =  context.getFolderContents(contentFilter=query)
00557         linkable = dict([(o.id,1) for o in content ])
00558 
00559         if allow_browse and coll_types:
00560             # Do an extended query which includes collections whether
00561             # or not they were matched by the first query,
00562             # and which also, unfortunately may include content which
00563             # doesn't match the original query.
00564             query2 = {}
00565             if link_types:
00566                 query2['portal_type'] = tuple(link_types) + tuple(coll_types)
00567             else:
00568                 query2['portal_type'] = ()
00569 
00570             if 'sort_on' in query:
00571                 query2['sort_on'] = query['sort_on']
00572 
00573             allcontent = context.getFolderContents(contentFilter=query2)
00574             content = [c for c in allcontent
00575                 if c.portal_type in coll_types or c.id in linkable ]
00576 
00577         link_types = query['portal_type']
00578         items = self.infoForBrains(content, resource_type, portal, linkids=linkable)
00579 
00580         if allow_browse and context is not portal:
00581             parent = context.aq_parent
00582             pt = getattr(parent, 'portal_type', None)
00583             if pt in collection_type.portal_types:
00584                 data = self.getSingleObjectInfo(parent, resource_type)
00585                 data['label'] = '.. (Parent folder)'
00586                 items.insert(0, data)
00587         return items

Here is the call graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.getKupuFields (   self,
  filter = 1 
)
Returns a list of all kupu editable fields

Definition at line 799 of file plonedrawers.py.

00799 
00800     def getKupuFields(self, filter=1):
00801         """Returns a list of all kupu editable fields"""
00802         inuse = getToolByName(self, 'portal_catalog').uniqueValuesFor('portal_type')
00803         for t,f,pt in self._getKupuFields():
00804             if html2captioned.sanitize_portal_type(pt) in inuse or not filter:
00805                 yield dict(type=t, name=f.getName(), portal_type=pt,
00806                            label=self.getLabelFromWidget(f.widget))

Here is the call graph for this function:

Get the label for a widget converting from i18n message if needed

Definition at line 791 of file plonedrawers.py.

00791 
00792     def getLabelFromWidget(self, widget):
00793         """Get the label for a widget converting from i18n message if needed"""
00794         label = util.translate(widget.Label(self), self.REQUEST)
00795         if isinstance(label, str):
00796             label = label.decode('utf8', 'replace')
00797         return label

Here is the caller graph for this function:

Definition at line 692 of file plonedrawers.py.

00692 
00693     def getMyItems(self):
00694         request = self.REQUEST
00695         response = request.RESPONSE
00696         response.setHeader('Cache-Control', 'no-cache')
00697 
00698         member_tool = getToolByName(self, 'portal_membership')
00699         member = member_tool.getAuthenticatedMember()
00700 
00701         # the default resource type is mediaobject
00702         search_params = {}
00703         search_params['sort_on'] = 'modified'
00704         search_params['sort_order'] = 'reverse'
00705         search_params['limit'] = 20
00706         search_params['Creator'] = member.getMemberId()
00707 
00708         return self.infoForQuery(search_params)

Here is the call graph for this function:

Returns previewable types and a possible preview path

Definition at line 483 of file plonedrawers.py.

00483 
00484     def getPreviewable(self):
00485         """Returns previewable types and a possible preview path"""
00486         if HAS_PIL:
00487             def best_preview(field):
00488                 sizes = getattr(field, 'sizes', None)
00489                 if not sizes:
00490                     return field.getName()
00491 
00492                 preview = None
00493                 previewsize = (0,0)
00494                 for k in sizes:
00495                     try:
00496                         if previewsize < sizes[k] <= (128,128):
00497                             preview = k
00498                             previewsize = sizes[k]
00499                     except TypeError: # Fails on Plone 2.1
00500                         return field.getName()
00501                 if not preview:
00502                     smallest = min(sizes.values())
00503                     for k in sizes:
00504                         if sizes[k]==smallest:
00505                             preview = k
00506                             break
00507                 return "%s_%s" % (field.getName(), preview)
00508 
00509         else:
00510             def best_preview(field):
00511                 return field.getName()
00512 
00513         result = []
00514         typestool = getToolByName(self, 'portal_types')
00515         archetype_tool = getToolByName(self, 'archetype_tool', None)
00516         if archetype_tool is None:
00517             return result
00518         valid = dict.fromkeys([t.getId() for t in typestool.listTypeInfo()])
00519         types = archetype_tool.listRegisteredTypes()
00520         for t in types:
00521             name = t['portal_type']
00522             if not name in valid:
00523                 continue
00524             schema = t['schema']
00525             for field in schema.fields():
00526                 if not isinstance(field, ImageField):
00527                     continue
00528                 result.append((name, best_preview(field)))
00529                 break
00530         return result
        

Here is the call graph for this function:

Definition at line 710 of file plonedrawers.py.

00710 
00711     def getRecentItems(self):
00712         search_params = {}
00713         search_params['sort_on'] = 'modified'
00714         search_params['sort_order'] = 'reverse'
00715         search_params['limit'] = 20
00716         search_params['review_state'] = 'visible', 'published'
00717 
00718         return self.infoForQuery(search_params)

Here is the call graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.getResourceType (   self,
  resource_type = None 
)
Convert resource type string to instance

Definition at line 532 of file plonedrawers.py.

00532 
00533     def getResourceType(self, resource_type=None):
00534         """Convert resource type string to instance"""
00535         if isinstance(resource_type, ResourceType):
00536             return resource_type
00537 
00538         if not resource_type:
00539             resource_type = self.REQUEST.get('resource_type', 'mediaobject')
00540 
00541         return ResourceType(self, resource_type)

Here is the caller graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.getSingleObjectInfo (   self,
  context,
  resource_type = None,
  portal = None 
)
Return info for a single object

Definition at line 589 of file plonedrawers.py.

00589 
00590     def getSingleObjectInfo(self, context, resource_type=None, portal=None):
00591         """Return info for a single object"""
00592         if not resource_type: resource_type = self.getResourceType()
00593         if portal is None:
00594             portal = getToolByName(self, 'portal_url').getPortalObject()
00595         return self.infoForBrains([context], resource_type, portal)[0]

Here is the call graph for this function:

Here is the caller graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.getUploadImageClasses (   self,
  portal_type = None 
)

Definition at line 900 of file plonedrawers.py.

00900 
00901     def getUploadImageClasses(self, portal_type=None):
00902         if portal_type is None:
00903             portal_type = self.getDefaultImageType()
00904         stored = self.getClassesForType(portal_type)
00905         classes = []
00906         for c in stored:
00907             c = c.strip()
00908             if not c:
00909                 continue
00910             if '|' in c:
00911                 title, classname = c.split('|', 1)
00912                 classes.append({'title': title, 'classname': classname})
00913             else:
00914                 classes.append({'title': c, 'classname': c})
00915         return classes
00916 

Here is the call graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.getUploadImageSizes (   self,
  portal_type = None 
)

Definition at line 884 of file plonedrawers.py.

00884 
00885     def getUploadImageSizes(self, portal_type=None):
00886         resource_type = self.getResourceType()
00887         portal = getToolByName(self, 'portal_url').getPortalObject()
00888         mediatypes = resource_type.get_portal_types()
00889         catalog = getToolByName(self, 'portal_catalog')
00890         adaptor = InfoAdaptor(self, resource_type, portal)
00891         if portal_type is None:
00892             portal_type = self.getDefaultImageType()
00893 
00894         brains = catalog.searchResults(portal_type=portal_type, limit=1)[:1]
00895         if brains:
00896             info = adaptor.get_image_sizes(brains[0], portal_type, '')
00897             return info
00898         return []

Here is the call graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.infoForBrains (   self,
  values,
  resource_type,
  portal = None,
  linkids = None 
)

Definition at line 751 of file plonedrawers.py.

00751 
00752     def infoForBrains(self, values, resource_type, portal=None, linkids=None):
00753         request = self.REQUEST
00754         response = request.RESPONSE
00755         response.setHeader('Cache-Control', 'no-cache')
00756         linktypes=resource_type.portal_types
00757         if portal is None:
00758             portal = getToolByName(self, 'portal_url').getPortalObject()
00759         
00760         adaptor = InfoAdaptor(self, resource_type, portal)
00761         
00762         # For Plone 2.0.5 compatability, if getId is callable we assume
00763         # we have an object rather than a brains.
00764         if values and callable(values[0].getId):
00765             info = adaptor.info_object
00766         else:
00767             info = adaptor.info
00768 
00769         res = []
00770 
00771         for obj in values:
00772             portal_type = getattr(obj, 'portal_type', '')
00773 
00774             if linkids is not None:
00775                 linkable = obj.id in linkids
00776             elif len(linktypes)==0:
00777                 linkable = True
00778             else:
00779                 linkable = portal_type in linktypes
00780 
00781             data = info(obj, linkable)
00782             if data:
00783                 res.append(data)
00784         return res

Here is the call graph for this function:

Here is the caller graph for this function:

def kupu.plone.plonedrawers.PloneDrawers.infoForQuery (   self,
  query,
  resource_type = None,
  portal = None 
)

Definition at line 733 of file plonedrawers.py.

00733 
00734     def infoForQuery(self, query, resource_type=None, portal=None):
00735         resource_type = self.getResourceType()
00736         if portal is None:
00737             portal = getToolByName(self, 'portal_url').getPortalObject()
00738         
00739         baseQuery = resource_type.getQuery()
00740         query.update(baseQuery)
00741         limit = query.get('limit', None)
00742         pt = query['portal_type']
00743         if not pt:
00744             del query['portal_type']
00745         catalog = getToolByName(portal, 'portal_catalog')
00746         values = catalog.searchResults(query)
00747         if limit:
00748             values = values[:limit]
00749         return self.infoForBrains(values, resource_type, portal)

Here is the call graph for this function:

Here is the caller graph for this function:

Returns True if we can upload the the current folder.

Definition at line 852 of file plonedrawers.py.

00852 
00853     def isUploadSupported(self, context):
00854         """Returns True if we can upload the the current folder."""
00855         resource_type = self.getResourceType()
00856         if resource_type.name != 'mediaobject':
00857             return False
00858 
00859         allowedContent = context.getAllowedTypes()
00860         allowed = dict.fromkeys([a.getId() for a in allowedContent])
00861         for t in resource_type.portal_types:
00862             if t in allowed:
00863                 return True
00864         return False

Here is the call graph for this function:

Definition at line 720 of file plonedrawers.py.

00720 
00721     def kupuSearch(self):
00722         request = self.REQUEST
00723         search_params = {}
00724         search_params.update(request.form)
00725 
00726         # Get the maximum number of results with 500 being the default and
00727         # absolute maximum.
00728         abs_max = 500
00729         search_params['limit'] = min(request.get('max_results', abs_max), abs_max)
00730 
00731         return self.infoForQuery(search_params)

Here is the call graph for this function:

Returns a list of document/fields which have support for captioning

Definition at line 821 of file plonedrawers.py.

00821 
00822     def supportedCaptioning(self):
00823         """Returns a list of document/fields which have support for captioning"""
00824         supported = [t+'/'+self.getLabelFromWidget(f.widget) for (t,f,pt) in self._getKupuFields() if self.canCaption(f) ]
00825         return str.join(', ', supported)

Here is the call graph for this function:

Test whether the output transform is enabled for x-html-safe

Definition at line 833 of file plonedrawers.py.

00833 
00834     def transformIsEnabled(self):
00835         """Test whether the output transform is enabled for x-html-safe"""
00836         uid_catalog = getToolByName(self, 'uid_catalog', None)
00837         portal_transforms = getToolByName(self, 'portal_transforms', None)
00838         if not uid_catalog or not portal_transforms:
00839             return False
00840         # Find something, anything which has a UID
00841         content = uid_catalog.searchResults(sort_on='', sort_limit=1)
00842         if not content:
00843             return False
00844         uid = content[0].UID # Get an arbitrary used UID.
00845         link = 'resolveuid/%s' % uid
00846         test = '<a href="%s"></a>' % link
00847         txfrm = portal_transforms.convertTo('text/x-html-safe', test, mimetype='text/html', context=self)
00848         if hasattr(txfrm, 'getData'):
00849             txfrm = txfrm.getData()
00850         return txfrm and not link in txfrm

Here is the call graph for this function:

Returns a list of document/fields which do not have support for captioning

Definition at line 827 of file plonedrawers.py.

00827 
00828     def unsupportedCaptioning(self):
00829         """Returns a list of document/fields which do not have support for captioning"""
00830         unsupp = [t+'/'+self.getLabelFromWidget(f.widget) for (t,f,pt) in self._getKupuFields() if not self.canCaption(f) ]
00831         return str.join(', ', unsupp)

Here is the call graph for this function:


Member Data Documentation

tuple kupu.plone.plonedrawers.PloneDrawers.security = ClassSecurityInfo() [static]

Reimplemented in kupu.plone.plonelibrarytool.PloneKupuLibraryTool.

Definition at line 480 of file plonedrawers.py.


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