[kupu-checkins] r37753 - in kupu/trunk/kupu: doc plone
duncan at codespeak.net
duncan at codespeak.net
Thu Feb 1 16:59:57 CET 2007
Author: duncan
Date: Thu Feb 1 16:59:55 2007
New Revision: 37753
Modified:
kupu/trunk/kupu/doc/CHANGES.txt
kupu/trunk/kupu/plone/html2captioned.py
Log:
Added a hook so that the transform removing resolveuid urls can do something useful when the link is broken.
Modified: kupu/trunk/kupu/doc/CHANGES.txt
==============================================================================
--- kupu/trunk/kupu/doc/CHANGES.txt (original)
+++ kupu/trunk/kupu/doc/CHANGES.txt Thu Feb 1 16:59:55 2007
@@ -2,6 +2,11 @@
Kupu changes
============
+ - the uid/captioning transform now has a hook which gets called if
+ kupu fails to resolve the uid. Use this for any fallback processing
+ (e.g. lookup the uid catalog in a different plone site, or just return
+ a default error page.
+
- 1.4 Beta 3
- Fixed NonXHTMLTagFilter default filterdata: 'big', 'small' and 'tt' are
Modified: kupu/trunk/kupu/plone/html2captioned.py
==============================================================================
--- kupu/trunk/kupu/plone/html2captioned.py (original)
+++ kupu/trunk/kupu/plone/html2captioned.py Thu Feb 1 16:59:55 2007
@@ -88,6 +88,19 @@
return self.config['output']
raise AttributeError(attr)
+ def resolveuid(self, context, reference_catalog, uid):
+ """Convert a uid to an object by looking it up in the reference catalog.
+ If not found then tries to fallback to a possible hook (e.g. so you could
+ resolve uids on another system).
+ """
+ target = reference_catalog.lookupObject(uid)
+ if target is not None:
+ return target
+ hook = getattr(context, 'kupu_resolveuid_hook', None)
+ if hook:
+ target = hook(uid)
+ return target
+
def convert(self, data, idata, filename=None, **kwargs):
"""convert the data, store the result in idata and return that
optional argument filename may give the original file name of received data
@@ -100,6 +113,7 @@
context = kwargs.get('context', None)
if context:
at_tool = context.archetype_tool
+ rc = at_tool.reference_catalog
if context and at_tool:
def replaceImage(match):
@@ -115,7 +129,7 @@
width = attrs.group('width')
if src:
d = attrs.groupdict()
- target = at_tool.reference_catalog.lookupObject(src)
+ target = self.resolveuid(context, rc, src)
if target:
d['caption'] = newline_to_br(html_quote(target.Description()))
tag = CLASS_PATTERN.sub('', d['tag'])
@@ -145,7 +159,7 @@
def replaceUids(match):
tag = match.group('tag')
uid = match.group('uid')
- target = at_tool.reference_catalog.lookupObject(uid)
+ target = self.resolveuid(context, rc, uid)
if target:
try:
url = target.getRemoteUrl()
More information about the kupu-checkins
mailing list