Skip to content

Commit

Permalink
@@version-view: Handle file fields defined in behaviors when converti…
Browse files Browse the repository at this point in the history
…ng download URLs.
  • Loading branch information
rafaelbco authored and pysailor committed Nov 22, 2015
1 parent fb583a6 commit 40927fe
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions plone/app/versioningbehavior/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class VersionView(object):

download_url_patterns = (
re.compile(r'/@@download/(?P<field_id>.*?)/(?P<filename>.*?)"'),

# Behavior name before field name, like "LeadImage.image"
re.compile(
r'/versions_history_form/'
r'\+\+widget\+\+form\.widgets\.\S+\.(?P<field_id>.*?)'
r'/@@download/(?P<filename>.*?)"'
),

re.compile(
r'/versions_history_form/'
r'\+\+widget\+\+form\.widgets\.(?P<field_id>.*?)'
Expand All @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 40927fe

Please sign in to comment.