From 40927feb079a833c1a2b7f6b5cb99c8b2d4421a0 Mon Sep 17 00:00:00 2001 From: Rafael Oliveira Date: Mon, 19 Oct 2015 14:45:10 -0200 Subject: [PATCH] @@version-view: Handle file fields defined in behaviors when converting download URLs. --- plone/app/versioningbehavior/browser.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plone/app/versioningbehavior/browser.py b/plone/app/versioningbehavior/browser.py index 7e74c28..2999e9a 100644 --- a/plone/app/versioningbehavior/browser.py +++ b/plone/app/versioningbehavior/browser.py @@ -11,6 +11,14 @@ class VersionView(object): download_url_patterns = ( re.compile(r'/@@download/(?P.*?)/(?P.*?)"'), + + # Behavior name before field name, like "LeadImage.image" + re.compile( + r'/versions_history_form/' + r'\+\+widget\+\+form\.widgets\.\S+\.(?P.*?)' + r'/@@download/(?P.*?)"' + ), + re.compile( r'/versions_history_form/' r'\+\+widget\+\+form\.widgets\.(?P.*?)' @@ -31,7 +39,7 @@ def __call__(self): for pattern in self.download_url_patterns: repl = self.version_of_namedfile_template.format(version_id=version_id) - transformed_html = pattern.sub(repl, html) + transformed_html = pattern.sub(repl, transformed_html) return transformed_html @@ -44,7 +52,10 @@ def __call__(self): filename = self.request.filename repository = getToolByName(self.context, 'portal_repository') old_obj = repository.retrieve(self.context, version_id).object - file_ = getattr(old_obj, field_id) + + # Will only work if the file is stored as an attribute with the same + # name of the field. + file_ = getattr(old_obj, field_id, None) if file_ is None: raise NotFound(self, filename, self.request)