Back to index

plone3  3.1.7
Functions | Variables
kupu.plone.util Namespace Reference

Functions

def register_layer
def unregister_layers
def layer_installed
def install_transform
def remove_transform
def translate

Variables

tuple kupu_package_dir = package_home(kupu_globals)
string UID_TRANSFORM = 'html-to-captioned'
string INVERSE_TRANSFORM = 'captioned-to-html'
string MT_SAFE = 'text/x-html-safe'
string MT_CAPTIONED = 'text/x-html-captioned'

Function Documentation

Install the uid transform and set up the policy chain to include it when going from html to safe html

Definition at line 81 of file util.py.

00081 
00082 def install_transform(self):
00083     """Install the uid transform and set up the policy chain to include it when going from html to safe html"""
00084     mimetypes_tool = getToolByName(self, 'mimetypes_registry')
00085     if not mimetypes_tool.lookup(MT_CAPTIONED):
00086         newtype = MimeTypeItem.MimeTypeItem('HTML with captioned images',
00087             (MT_CAPTIONED,), ('html-captioned',), 0)
00088         mimetypes_tool.register(newtype)
00089 
00090     transform_tool = getToolByName(self, 'portal_transforms')
00091     if not hasattr(transform_tool, UID_TRANSFORM):
00092         transform_tool.manage_addTransform(UID_TRANSFORM, 'Products.kupu.plone.html2captioned')
00093 
00094     if not hasattr(transform_tool, INVERSE_TRANSFORM):
00095         transform_tool.manage_addTransform(INVERSE_TRANSFORM, 'Products.PortalTransforms.transforms.identity')
00096         # Need to commit a subtransaction here, otherwise setting the
00097         # parameters will cause an exception when the transaction is
00098         # finally comitted.
00099         try:
00100             import transaction
00101             transaction.savepoint(optimistic=True)
00102         except ImportError:
00103             get_transaction().commit(1)
00104 
00105     inverse = transform_tool[INVERSE_TRANSFORM]
00106     if inverse.get_parameter_value('inputs') != [MT_CAPTIONED] or inverse.get_parameter_value('output') != 'text/html':
00107         inverse.set_parameters(inputs=[MT_CAPTIONED], output='text/html')
00108 
00109     # Set policy
00110     policies = [ (mimetype, required) for (mimetype, required) in transform_tool.listPolicies()
00111          if mimetype==MT_SAFE ]
00112     required = [UID_TRANSFORM]
00113     if policies:
00114         if not UID_TRANSFORM in required:
00115             required.append(UID_TRANSFORM)
00116 
00117         transform_tool.manage_delPolicies([MT_SAFE])
00118     transform_tool.manage_addPolicy(MT_SAFE, required)

Here is the call graph for this function:

def kupu.plone.util.layer_installed (   self,
  name 
)

Definition at line 64 of file util.py.

00064 
00065 def layer_installed(self, name):
00066     skinstool = getToolByName(self, 'portal_skins')
00067 
00068     # remove this layer from all known skins
00069     for skinName in skinstool.getSkinSelections():
00070         path = skinstool.getSkinPath(skinName) 
00071         path = [i.strip() for i in path.split(',')]
00072 
00073         if name not in path:
00074             return False
00075     return True

Here is the call graph for this function:

def kupu.plone.util.register_layer (   self,
  relpath,
  name,
  out,
  add = True 
)
Register a file system directory as skin layer

Definition at line 15 of file util.py.

00015 
00016 def register_layer(self, relpath, name, out, add=True):
00017     """Register a file system directory as skin layer
00018     """
00019     print >>out, "register skin layers"
00020     skinstool = getToolByName(self, 'portal_skins')
00021     if name not in skinstool.objectIds():
00022         kupu_plone_skin_dir = minimalpath(os.path.join(kupu_package_dir, relpath))
00023         createDirectoryView(skinstool, kupu_plone_skin_dir, name)
00024         print >>out, "The layer '%s' was added to the skins tool" % name
00025 
00026     if not add:
00027         return
00028 
00029     # put this layer into all known skins
00030     for skinName in skinstool.getSkinSelections():
00031         path = skinstool.getSkinPath(skinName) 
00032         path = [i.strip() for i in path.split(',')]
00033         try:
00034             if name not in path:
00035                 path.insert(path.index('custom')+1, name)
00036         except ValueError:
00037             if name not in path:
00038                 path.append(name)
00039 
00040         path = ','.join(path)
00041         skinstool.addSkinSelection(skinName, path)

Here is the call graph for this function:

Disable the UID transform: remove the policy but leave everything else intact.

Definition at line 119 of file util.py.

00119 
00120 def remove_transform(self):
00121     """Disable the UID transform: remove the policy but leave everything else intact."""
00122     transform_tool = getToolByName(self, 'portal_transforms', None)
00123     if transform_tool is None:
00124         return
00125     policies = [ (mimetype, required) for (mimetype, required) in transform_tool.listPolicies() if mimetype==MT_SAFE ]
00126     if not policies:
00127         return
00128     required = list(policies[0][1])
00129     if UID_TRANSFORM in required:
00130         required.remove(UID_TRANSFORM)
00131         transform_tool.manage_delPolicies([MT_SAFE])
00132         if required:
00133             transform_tool.manage_addPolicy(MT_SAFE, required)
00134 
00135 try:
00136     from zope.i18nmessageid import Message
00137     from zope.i18n import translate as i18n_translate
00138     def translate(label, context):
00139         if isinstance(label, Message):
00140             return i18n_translate(label, context=context)
        return label

Here is the call graph for this function:

def kupu.plone.util.translate (   label,
  context 
)

Definition at line 142 of file util.py.

00142 
00143     def translate(label, context):
00144         return label
00145 

Here is the caller graph for this function:

def kupu.plone.util.unregister_layers (   self,
  names,
  out 
)
Remove a directory from the skins

Definition at line 42 of file util.py.

00042 
00043 def unregister_layers(self, names, out):
00044     """Remove a directory from the skins"""
00045     skinstool = getToolByName(self, 'portal_skins')
00046 
00047     # remove this layer from all known skins
00048     for skinName in skinstool.getSkinSelections():
00049         path = skinstool.getSkinPath(skinName) 
00050         path = [i.strip() for i in path.split(',')]
00051 
00052         opath = list(path)
00053         for name in names:
00054             if name in path:
00055                 path.remove(name)
00056 
00057         if opath != path:
00058             path = ','.join(path)
00059             skinstool.addSkinSelection(skinName, path)
00060 
00061             print >>out, "removed layers '%s' from '%s'" % (', '.join(names), skinName)
00062     self.changeSkin(None)
00063 

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

string kupu.plone.util.INVERSE_TRANSFORM = 'captioned-to-html'

Definition at line 77 of file util.py.

Definition at line 9 of file util.py.

string kupu.plone.util.MT_CAPTIONED = 'text/x-html-captioned'

Definition at line 79 of file util.py.

string kupu.plone.util.MT_SAFE = 'text/x-html-safe'

Definition at line 78 of file util.py.

string kupu.plone.util.UID_TRANSFORM = 'html-to-captioned'

Definition at line 76 of file util.py.