56 lines
2.2 KiB
Python
56 lines
2.2 KiB
Python
from Acquisition import aq_parent
|
|
|
|
from persistent.dict import PersistentDict
|
|
from DateTime import DateTime
|
|
from zope.annotation.interfaces import IAnnotations
|
|
|
|
import collective.documentviewer.convert
|
|
import collective.documentviewer.settings
|
|
import collective.documentviewer.views
|
|
from Products.Five.browser.resource import DirectoryResource
|
|
|
|
import plone.namedfile.utils
|
|
|
|
from . import documents
|
|
|
|
# Monkeypatching of various collective.documentviewer parts
|
|
|
|
class PDFFiles(collective.documentviewer.views.PDFFiles):
|
|
# 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)
|
|
|
|
|
|
orig_init = collective.documentviewer.settings.Base.__init__
|
|
def 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.
|
|
if isinstance(context, documents.TabellioDmsFile):
|
|
self.context = context
|
|
tabellio_folder = aq_parent(aq_parent(context))
|
|
annotations = IAnnotations(tabellio_folder)
|
|
# store metadata in top tabellio folder
|
|
self._metadata = annotations.get('collective.documentviewer-%s' % context.id, None)
|
|
if self._metadata is None:
|
|
self._metadata = PersistentDict()
|
|
self._metadata['last_updated'] = DateTime('1901/01/01').ISO8601()
|
|
self.storage_version = collective.documentviewer.settings.STORAGE_VERSION
|
|
annotations['collective.documentviewer-%s' % context.id] = self._metadata
|
|
else:
|
|
orig_init(self, 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
|