[kupu-checkins] r38072 - in kupu/trunk/kupu: Extensions doc plone plone/kupu_plone_layer
duncan at codespeak.net
duncan at codespeak.net
Wed Feb 7 16:25:29 CET 2007
Author: duncan
Date: Wed Feb 7 16:25:13 2007
New Revision: 38072
Modified:
kupu/trunk/kupu/Extensions/Install.py
kupu/trunk/kupu/doc/PLONE2.txt
kupu/trunk/kupu/plone/html2captioned.py
kupu/trunk/kupu/plone/kupu_config.pt
kupu/trunk/kupu/plone/kupu_plone_layer/resolveuid.py
kupu/trunk/kupu/plone/plonelibrarytool.py
kupu/trunk/kupu/plone/util.py
Log:
UID/Captioning transform is now fully installed and enabled when you
turn on UID linking or cpationing. It is installed but not including
in the x-safe-html policy if you have UID linking and captioning
turned off. It is fully removed if you uninstall kupu.
Modified: kupu/trunk/kupu/Extensions/Install.py
==============================================================================
--- kupu/trunk/kupu/Extensions/Install.py (original)
+++ kupu/trunk/kupu/Extensions/Install.py Wed Feb 7 16:25:13 2007
@@ -24,6 +24,7 @@
from Products.CMFCore.DirectoryView import createDirectoryView
from Products.kupu import kupu_globals
from Products.kupu.plone.util import register_layer, unregister_layers
+from Products.kupu.plone import util
from Products.kupu.config import TOOLNAME, PROJECTNAME, TOOLTITLE
from OFS.ObjectManager import BadRequestException
from zExceptions import BadRequest
@@ -194,28 +195,10 @@
def install_transform(self, out):
try:
- print >>out, "Adding new mimetype"
- mimetypes_tool = getToolByName(self, 'mimetypes_registry')
- newtype = MimeTypeItem.MimeTypeItem('HTML with captioned images',
- ('text/x-html-captioned',), ('html-captioned',), 0)
- mimetypes_tool.register(newtype)
-
- print >>out,"Add transform"
- transform_tool = getToolByName(self, 'portal_transforms')
- try:
- transform_tool.manage_delObjects(['html-to-captioned'])
- except: # XXX: get rid of bare except
- pass
- transform_tool.manage_addTransform('html-to-captioned', 'Products.kupu.plone.html2captioned')
- print >>out,"Add identity transform"
- transform_tool = getToolByName(self, 'portal_transforms')
- try:
- transform_tool.manage_delObjects(['captioned-to-html'])
- except: # XXX: get rid of bare except
- pass
- transform_tool.manage_addTransform('captioned-to-html', 'Products.PortalTransforms.transforms.identity')
+ util.install_transform(self)
+ util.remove_transform(self) # Transform is installed but disabled by default.
except (NameError,AttributeError):
- print >>out, "No MimetypesRegistry, captioning not supported."
+ print >>out, "Transform not installed."
def install_customisation(self, out):
"""Default settings may be stored in a customisation policy script so
@@ -260,9 +243,10 @@
def uninstall_transform(self, out):
transform_tool = getToolByName(self, 'portal_transforms')
try:
- transform_tool.manage_delObjects(['html-to-captioned'])
+ util.remove_transform(self)
+ transform_tool.manage_delObjects(['html-to-captioned', 'captioned-to-html'])
except:
- print >>out, "transform not removed"
+ print >>out, "Transform not removed"
pass
else:
print >>out, "Transform removed"
Modified: kupu/trunk/kupu/doc/PLONE2.txt
==============================================================================
--- kupu/trunk/kupu/doc/PLONE2.txt (original)
+++ kupu/trunk/kupu/doc/PLONE2.txt Wed Feb 7 16:25:13 2007
@@ -18,7 +18,7 @@
* CMF 1.4 or greater
-* Archetypes 1.3.x
+* Archetypes 1.3.9 or greater
If you plan on customizing kupu by editing the '.kupu' files then
you also need:
@@ -160,10 +160,10 @@
means that you can move the target object to a different location, or
even rename it, and the link will continue to work.
- - the URL used for the link will require an extra hit on the server,
- and will contain the internal UID. These issues may be avoided by
- configuring the output transform for image caption support (`see
- below`__).
+ - the URL used for the link would require an extra hit on the server,
+ and will contain the internal UID so a transform is installed for any
+ field which has text/x-safe-html or text/x-html-captioned as its
+ output format. (`see below`__).
__ captioning_
@@ -173,6 +173,29 @@
- Links to all objects simply link to the current URL of the object.
+Links which are redirected use Kupu's transform to correct the URL
+when the page is rendered in view mode, but in edit mode the links use
+the resolveuid script to resolve as they are accessed. This involves
+an additional hit through the server.
+
+If a UID link does not have a UID which is currently valid then Kupu
+will look for an additional script kupu_resolveuid_hook. This script
+may be used to lookup the UIDs in an external system, or to provide a
+customised error page for broken UID links.
+
+To point all broken links to a specific URL you could for example
+invent a dummy object::
+
+ from Products.PythonScripts.standard import Object
+ def absurl():
+ return '[insert url of broken link page here]'
+ def Title():
+ return 'This link is broken'
+ return Object(absolute_url=absurl,
+ absolute_url_path=absurl,
+ Title=Title, Description=Description,)
+
+
Warn before losing changes
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -205,7 +228,7 @@
Paragraph Styles
::::::::::::::::
Enter a list of styles to be added to the style pulldown. See `Custom
-Paragraph Styles`_.
+Styles`_.
HTML Filter
@@ -556,11 +579,12 @@
should have its ``default_output_type`` set to
``text/x-html-captioned`` in the Archetypes schema. The problem with
this is that the default ATContentTypes use an output type of
-'text/x-html-safe'. It should be possible to configure the
-portal_transforms tool to apply the captioning transform in addition
-to the safe html, but (at the time of writing) bugs in
-PortalTransforms prevent this working correctly unless you also patch
-Products/PortalTransforms/TransformEngine.py:
+'text/x-html-safe'. If either link by uid or captioning is enabled
+then Kupu will attempt to configure the Portal Transform engine to
+apply the transform automatically.
+
+If you have a version of Portal Transforms earlier than 1.3.9 then you
+may need to patch it to work correctly with the transform:
Find the line::
@@ -570,7 +594,7 @@
requirements = self._policies.get(str(target_mt), [])
-Once you have done this you can configure the portal_transforms tool as follows:
+Once you have done kupu will configure the portal_transforms tool as follows:
* add a new transform id 'captioned_to_html', module
'Products.PortalTransforms.transforms.identity' with input type
Modified: kupu/trunk/kupu/plone/html2captioned.py
==============================================================================
--- kupu/trunk/kupu/plone/html2captioned.py (original)
+++ kupu/trunk/kupu/plone/html2captioned.py Wed Feb 7 16:25:13 2007
@@ -143,7 +143,10 @@
except AttributeError:
pass
if not width:
- width = target.getWidth()
+ try:
+ width = target.getWidth()
+ except AttributeError:
+ pass
if not width:
try:
width = target.getImage().getWidth()
Modified: kupu/trunk/kupu/plone/kupu_config.pt
==============================================================================
--- kupu/trunk/kupu/plone/kupu_config.pt (original)
+++ kupu/trunk/kupu/plone/kupu_config.pt Wed Feb 7 16:25:13 2007
@@ -78,10 +78,11 @@
<blockquote tal:content="here/supportedCaptioning"></blockquote>
</span>
<span tal:condition="not:isTransformEnabled">
-If you enable this option you should also
-enable the output transform as for image captioning (see <a
-href="zmi_docs#images">image captioning documentation</a>). This
-transform will hide the UID based URLs from client browsers.
+If you enable this option a transform to hide UIDs and support image
+captioning from client browsers will also be enabled (see <a
+href="zmi_docs#images">image captioning documentation</a>). If the
+transform does not enable itself automatically you may need to update
+your PortalTransforms product.
</span>
</div>
@@ -98,10 +99,16 @@
Allow captioned images</label>
<div class="formHelp">
+Images which are linked using UID based links may be automatically captioned.
+
<div tal:condition="not:isTransformEnabled">
-<span i18n:translate="help_captioning">To support
-captioning you may need to apply a patch to PortalTransforms. See
-the <a href="zmi_docs#images">image captioning documentation</a> for details.</span>
+<span i18n:translate="help_captioning">
+If you enable this option a transform to hide UIDs and support image
+captioning from client browsers will also be enabled (see <a
+href="zmi_docs#images">image captioning documentation</a>). If the
+transform does not enable itself automatically you may need to update
+your PortalTransforms product.
+</span>
<div>Fields which could support image captioning:</div>
</div>
<div tal:condition="isTransformEnabled">
Modified: kupu/trunk/kupu/plone/kupu_plone_layer/resolveuid.py
==============================================================================
--- kupu/trunk/kupu/plone/kupu_plone_layer/resolveuid.py (original)
+++ kupu/trunk/kupu/plone/kupu_plone_layer/resolveuid.py Wed Feb 7 16:25:13 2007
@@ -17,9 +17,13 @@
reference_tool = getToolByName(context, 'reference_catalog')
obj = reference_tool.lookupObject(uuid)
if not obj:
- return context.standard_error_message(error_type=404,
- error_message='''The link you followed appears to be broken''')
-
+ hook = getattr(context, 'kupu_resolveuid_hook', None)
+ if hook:
+ obj = hook(uid)
+ if not obj:
+ return context.standard_error_message(error_type=404,
+ error_message='''The link you followed appears to be broken''')
+
if traverse_subpath:
traverse_subpath.insert(0, obj.absolute_url())
target = '/'.join(traverse_subpath)
Modified: kupu/trunk/kupu/plone/plonelibrarytool.py
==============================================================================
--- kupu/trunk/kupu/plone/plonelibrarytool.py (original)
+++ kupu/trunk/kupu/plone/plonelibrarytool.py Wed Feb 7 16:25:13 2007
@@ -731,7 +731,16 @@
if captioning is not None:
self.captioning = bool(captioning)
+
+ if self.linkbyuid or self.captioning:
+ util.install_transform(self)
+ else:
+ util.remove_transform(self)
+
if REQUEST:
REQUEST.RESPONSE.redirect(self.absolute_url() + '/kupu_config')
+ def _enableuidtransform(self, enable):
+ """Enable or disable the uid transform."""
+
InitializeClass(PloneKupuLibraryTool)
Modified: kupu/trunk/kupu/plone/util.py
==============================================================================
--- kupu/trunk/kupu/plone/util.py (original)
+++ kupu/trunk/kupu/plone/util.py Wed Feb 7 16:25:13 2007
@@ -3,6 +3,7 @@
from App.Common import package_home
from Products.CMFCore.utils import getToolByName, minimalpath
from Products.CMFCore.DirectoryView import createDirectoryView
+from Products.MimetypesRegistry import MimeTypeItem
from Products.kupu import kupu_globals
kupu_package_dir = package_home(kupu_globals)
@@ -66,4 +67,50 @@
if name not in path:
return False
- return True
\ No newline at end of file
+ return True
+
+UID_TRANSFORM = 'html-to-captioned'
+INVERSE_TRANSFORM = 'captioned-to-html'
+MT_SAFE = 'text/x-html-safe'
+MT_CAPTIONED = 'text/x-html-captioned'
+
+def install_transform(self):
+ """Install the uid transform and set up the policy chain to include it when going from html to safe html"""
+ mimetypes_tool = getToolByName(self, 'mimetypes_registry')
+ if not mimetypes_tool.lookup(MT_CAPTIONED):
+ newtype = MimeTypeItem.MimeTypeItem('HTML with captioned images',
+ (MT_CAPTIONED,), ('html-captioned',), 0)
+ mimetypes_tool.register(newtype)
+
+ transform_tool = getToolByName(self, 'portal_transforms')
+ if not hasattr(transform_tool, UID_TRANSFORM):
+ transform_tool.manage_addTransform(UID_TRANSFORM, 'Products.kupu.plone.html2captioned')
+
+ if not hasattr(transform_tool, INVERSE_TRANSFORM):
+ transform_tool.manage_addTransform(INVERSE_TRANSFORM, 'Products.PortalTransforms.transforms.identity')
+
+ inverse = transform_tool[INVERSE_TRANSFORM]
+ if inverse.get_parameter_value('inputs') != [MT_CAPTIONED] or inverse.get_parameter_value('output') != 'text/html':
+ inverse.set_parameters(inputs=[MT_CAPTIONED], output='text/html')
+
+ # Set policy
+ policies = [ (mimetype, required) for (mimetype, required) in transform_tool.listPolicies()
+ if mimetype==MT_SAFE ]
+ required = [UID_TRANSFORM]
+ if policies:
+ if not UID_TRANSFORM in required:
+ required.append(UID_TRANSFORM)
+
+ transform_tool.manage_delPolicies([MT_SAFE])
+ transform_tool.manage_addPolicy(MT_SAFE, required)
+
+def remove_transform(self):
+ """Disable the UID transform: remove the policy but leave everything else intact."""
+ transform_tool = getToolByName(self, 'portal_transforms')
+ policies = [ (mimetype, required) for (mimetype, required) in transform_tool.listPolicies() if mimetype==MT_SAFE ]
+ required = list(policies[0][1])
+ if UID_TRANSFORM in required:
+ required.remove(UID_TRANSFORM)
+ transform_tool.manage_delPolicies([MT_SAFE])
+ if required:
+ transform_tool.manage_addPolicy(MT_SAFE, required)
More information about the kupu-checkins
mailing list