use collective.monkeypatcher to apply patches

This commit is contained in:
Frédéric Péters 2015-01-27 13:37:17 +01:00
parent e6e42150fd
commit e3a26b695c
2 changed files with 24 additions and 13 deletions

View File

@ -4,6 +4,7 @@
xmlns:grok="http://namespaces.zope.org/grok"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:monkey="http://namespaces.plone.org/monkey"
i18n_domain="pfwbged.tabellio">
<five:registerPackage package="." initialize=".initialize" />
@ -18,4 +19,20 @@
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
<monkey:patch
description="Don't check permissions for Tabellio thumbnails"
class="collective.documentviewer.views.PDFFiles"
original="publishTraverse"
preserveOriginal="true"
replacement=".monkey.patched_publishTraverse"
/>
<monkey:patch
description="Store annotations in base Tabellio folder"
class="collective.documentviewer.settings.Base"
original="__init__"
preserveOriginal="true"
replacement=".monkey.patched_base_init"
/>
</configure>

View File

@ -15,19 +15,16 @@ from . import documents
# Monkeypatching of various collective.documentviewer parts
class PDFFiles(collective.documentviewer.views.PDFFiles):
def patched_publishTraverse(self, request, name):
# don't check permissions for tabellio thumbnails; this would otherwise
# require the objects to have a stable UID and to be registered in the
# catalog.
def publishTraverse(self, request, name):
if name.endswith('-noisrev-tabellio'):
fi = DirectoryResource.publishTraverse(self, request, name)
return fi
return super(PDFFiles, self).publishTraverse(request, name)
if name.endswith('-noisrev-tabellio'):
fi = DirectoryResource.publishTraverse(self, request, name)
return fi
return self._old_publishTraverse(request, name)
orig_init = collective.documentviewer.settings.Base.__init__
def base_init(self, context):
def patched_base_init(self, context):
# for our transient files we cannot store documentviewer information in
# the object annotations so we have to create them under varying names
# in the DocumentsFolder object.
@ -43,13 +40,10 @@ def base_init(self, context):
self.storage_version = collective.documentviewer.settings.STORAGE_VERSION
annotations['collective.documentviewer-%s' % context.id] = self._metadata
else:
orig_init(self, context)
self._old___init__(context)
def patchDocumentViewer():
collective.documentviewer.views.PDFFiles = PDFFiles
collective.documentviewer.settings.Base.__init__ = base_init
collective.documentviewer.convert.Converter.isIndexationEnabled = lambda x: True
# avoid streaming files as the blob hack breaks this
plone.namedfile.utils.filestream_iterator = None