Back to index

plone3  3.1.7
icons.py
Go to the documentation of this file.
00001 from Acquisition import aq_inner
00002 from zope.interface import implements
00003 
00004 from plone.memoize.instance import memoize
00005 
00006 from Products.CMFCore.utils import getToolByName
00007 from plone.app.layout.icons.interfaces import IContentIcon
00008 
00009 
00010 class BaseIcon(object):
00011     """Helper base class for html rendering
00012     """
00013 
00014     __allow_access_to_unprotected_subobjects__ = True
00015 
00016     @memoize
00017     def html_tag(self):
00018         
00019         if not self.url:
00020             return None
00021         
00022         tag = '<img width="%s" height="%s" src="%s"' % (self.width, self.height, self.url,)
00023         if self.title:
00024             tag += ' title="%s"' % self.title
00025         if self.description:
00026             tag += ' alt="%s"' % self.description
00027         tag += ' />'
00028         return tag
00029 
00030 
00031 class CatalogBrainContentIcon(BaseIcon):
00032     implements(IContentIcon)
00033 
00034     def __init__(self, context, request, brain):
00035         self.context = context
00036         self.request = request
00037         self.brain = brain
00038 
00039     width = 16
00040     height = 16
00041 
00042     @property
00043     def url(self):
00044         portal_url = getToolByName(self.context, 'portal_url')()
00045         path = self.brain.getIcon
00046         return "%s/%s" % (portal_url, path)
00047 
00048     @property
00049     def description(self):
00050         context = aq_inner(self.context)
00051         tt = getToolByName(context, 'portal_types')
00052         return tt.get(self.brain['portal_type']).Title()
00053 
00054     @property
00055     def title(self):
00056         return None
00057 
00058 
00059 class CMFContentIcon(BaseIcon):
00060     implements(IContentIcon)
00061 
00062     def __init__(self, context, request, obj):
00063         self.context = context
00064         self.request = request
00065         self.obj = obj
00066 
00067     width = 16
00068     height = 16
00069 
00070     @property
00071     def url(self):
00072         portal_url = getToolByName(self.context, 'portal_url')()
00073         path = self.obj.getIcon(1)
00074         return "%s/%s" % (portal_url, path)
00075 
00076     @property
00077     def description(self):
00078         context = aq_inner(self.context)
00079         tt = getToolByName(context, 'portal_types')
00080         return tt.get(self.obj.portal_type).Title()
00081 
00082     @property
00083     def title(self):
00084         return None
00085 
00086 
00087 class FTIContentIcon(BaseIcon):
00088     implements(IContentIcon)
00089 
00090     def __init__(self, context, request, obj):
00091         self.context = context
00092         self.request = request
00093         self.obj = obj
00094 
00095     width = 16
00096     height = 16
00097 
00098     @property
00099     def url(self):
00100         portal_url = getToolByName(self.context, 'portal_url')()
00101         path = self.obj.getIcon()
00102         return "%s/%s" % (portal_url, path)
00103 
00104     @property
00105     def description(self):
00106         return self.obj.Title()
00107 
00108     @property
00109     def title(self):
00110         return None
00111 
00112 
00113 class PloneSiteContentIcon(BaseIcon):
00114     implements(IContentIcon)
00115 
00116     def __init__(self, context, request, obj):
00117         self.context = context
00118         self.request = request
00119         self.obj = obj
00120 
00121     width = 16
00122     height = 16
00123 
00124     @property
00125     def url(self):
00126         portal_url = getToolByName(self.context, 'portal_url')()
00127         return "%s/site_icon.gif" % portal_url
00128 
00129     @property
00130     def description(self):
00131         return self.obj.Title()
00132 
00133     @property
00134     def title(self):
00135         return None
00136 
00137 
00138 class DefaultContentIcon(BaseIcon):
00139     implements(IContentIcon)
00140 
00141     def __init__(self, context, request, obj):
00142         self.context = context
00143         self.request = request
00144         self.obj = obj
00145 
00146     width = 16
00147     height = 16
00148 
00149     @property
00150     def url(self):
00151         portal_url = getToolByName(self.context, 'portal_url')()
00152         if self.obj is None:
00153             return None
00154         return "%s/error_icon.gif" % portal_url
00155 
00156     @property
00157     def description(self):
00158         if self.obj is None:
00159             return None
00160         return self.obj.Title()
00161 
00162     @property
00163     def title(self):
00164         return None