def get_thumb(self, obj): if not obj: return None resource_rel = storage.getResourceRelURL(obj=obj) if self.resource_url: dvpdffiles = '%s/%s' % (self.resource_url.rstrip('/'), resource_rel) else: dvpdffiles = '%s/%s' % (self.portal_url, resource_rel) if obj.portal_type == 'File': settings = Settings(obj) if settings.successfully_converted: image_format = settings.pdf_image_format if not image_format: image_format = self.global_settings.pdf_image_format return '%s/small/%s_1.%s' % (dvpdffiles, self.dump_path, image_format) else: return '%s/images/pdf.png' % (self.static_url) elif obj.portal_type == 'Image': url = obj.absolute_url() return '%s/image_thumb' % url
def test_get_correct_rel_url_for_new_storage_with_resource_url(self): fi = self.createFile('test.pdf') gsettings = GlobalSettings(self.portal) gsettings.override_base_resource_url = 'http://foobar.com' uid = fi.UID() self.assertEquals(storage.getResourceRelURL(obj=fi), '%s/%s/%s' % (uid[0], uid[1], uid))
def test_get_correct_rel_url_for_old_storage(self): fi = self.createFile('test.pdf') settings = Settings(fi) del settings._metadata['storage_version'] uid = fi.UID() self.assertEquals(storage.getResourceRelURL(obj=fi), '@@dvpdffiles/%s' % uid)
def __call__(self): """ Redirects to the url for the rendered PDF. We need to redirect, because the PDF can be stored on FS, instead of ZODB. """ try: site = api.portal.get() except exc.CannotGetPortalError: raise NotFound settings = Settings(self.context) global_settings = GlobalSettings(site) portal_url = getMultiAdapter( (self.context, self.request), name="plone_portal_state").portal_url() resource_url = global_settings.override_base_resource_url rel_url = storage.getResourceRelURL(gsettings=global_settings, settings=settings) if resource_url: dvpdffiles = '%s/%s' % (resource_url.rstrip('/'), rel_url) else: dvpdffiles = '%s/%s' % (portal_url, rel_url) url = '%s/pdf/dump.pdf' % dvpdffiles self.request.response.redirect(url)
def __call__(self): """ Redirects to the url for the rendered PDF. We need to redirect, because the PDF can be stored on FS, instead of ZODB. """ try: site = api.portal.get() except exc.CannotGetPortalError: raise NotFound settings = Settings(self.context) global_settings = GlobalSettings(site) portal_url = getMultiAdapter((self.context, self.request), name="plone_portal_state").portal_url() resource_url = global_settings.override_base_resource_url rel_url = storage.getResourceRelURL(gsettings=global_settings, settings=settings) if resource_url: dvpdffiles = '%s/%s' % (resource_url.rstrip('/'), rel_url) else: dvpdffiles = '%s/%s' % (portal_url, rel_url) url = '%s/pdf/dump.pdf' % dvpdffiles self.request.response.redirect(url)
def __call__(self): self.site = getPortal(self.context) self.settings = Settings(self.context) self.global_settings = GlobalSettings(self.site) self.portal_url = getMultiAdapter( (self.context, self.request), name="plone_portal_state").portal_url() self.dvstatic = "%s/++resource++dv.resources" % (self.portal_url) resource_url = self.global_settings.override_base_resource_url rel_url = storage.getResourceRelURL(gsettings=self.global_settings, settings=self.settings) if resource_url: self.dvpdffiles = '%s/%s' % (resource_url.rstrip('/'), rel_url) else: self.dvpdffiles = '%s/%s' % (self.portal_url, rel_url) utils = getToolByName(self.context, 'plone_utils') msg = None self.enabled = True if allowedDocumentType(self.context, self.global_settings.auto_layout_file_types): if not self.installed: msg = _( "Since you do not have docsplit installed on this " "system, we can not render the pages of this document.") if self.settings.converting is not None and \ self.settings.converting: if self.settings.successfully_converted: # there is a version that is already converted, show it. self.enabled = True else: msg = _("The document is currently being converted to the " "Document Viewer view.") self.enabled = False elif self.settings.successfully_converted is not None and \ not self.settings.successfully_converted: msg = _("There was an error trying to convert the document. " "Maybe the document is encrypted, corrupt or " "malformed? Check log for details.") self.enabled = False elif self.settings.successfully_converted is None: # must have just switched to this view msg = _("This document is not yet converted to document " "viewer. Please click the `Document Viewer Convert` " "button in the actions menu to convert.") self.enabled = False else: self.enabled = False msg = _("The file is not a supported document type. " "Your type may be supported. Check out the document " "viewer configuration settings.") mtool = getToolByName(self.context, 'portal_membership') self.can_modify = mtool.checkPermission('cmf.ModifyPortalContent', self.context) if msg and self.can_modify: utils.addPortalMessage(_(msg)) return self.index()
def test_get_correct_rel_url_for_old_storage_with_resource_url(self): fi = self.createFile('test.pdf') settings = Settings(fi) gsettings = GlobalSettings(self.portal) gsettings.override_base_resource_url = 'http://foobar.com' del settings._metadata['storage_version'] uid = fi.UID() self.assertEquals(storage.getResourceRelURL(obj=fi), '%s' % uid)
def __call__(self): self.site = getPortal(self.context) self.settings = Settings(self.context) self.global_settings = GlobalSettings(self.site) self.portal_url = getMultiAdapter((self.context, self.request), name="plone_portal_state").portal_url() self.dvstatic = "%s/++resource++dv.resources" % ( self.portal_url) resource_url = self.global_settings.override_base_resource_url rel_url = storage.getResourceRelURL(gsettings=self.global_settings, settings=self.settings) if resource_url: self.dvpdffiles = '%s/%s' % (resource_url.rstrip('/'), rel_url) else: self.dvpdffiles = '%s/%s' % (self.portal_url, rel_url) utils = getToolByName(self.context, 'plone_utils') msg = None if allowedDocumentType(self.context, self.global_settings.auto_layout_file_types): if not self.installed: msg = "Since you do not have docsplit installed on this " + \ "system, we can not render the pages of this document." elif self.settings.converting is not None and \ self.settings.converting: if self.settings.successfully_converted: # there is a version that is already converted, show it. self.enabled = True else: msg = "The document is currently being converted to the " + \ "Document Viewer view." self.enabled = False elif self.settings.successfully_converted is not None and \ not self.settings.successfully_converted: msg = "There was an error trying to convert the document. " +\ "Maybe the document is encrypted, corrupt or " +\ "malformed? Check log for details." self.enabled = False elif self.settings.successfully_converted is None: # must have just switched to this view msg = "This document is not yet converted to document " +\ "viewer. Please click the `Document Viewer Convert` " +\ "button in the actions menu to convert." self.enabled = False else: self.enabled = False msg = "The file is not a supported document type. " + \ "Your type may be supported. Check out the document " + \ "viewer configuration settings." mtool = getToolByName(self.context, 'portal_membership') self.can_modify = mtool.checkPermission('cmf.ModifyPortalContent', self.context) if msg and self.can_modify: utils.addPortalMessage(msg) return self.index()
def test_get_correct_rel_url_for_new_storage(self): fi = self.createFile('test.pdf') uid = fi.UID() self.assertEquals(storage.getResourceRelURL(obj=fi), '@@dvpdffiles/%s/%s/%s' % (uid[0], uid[1], uid))
def _get_dv_data(obj): """ Access the collective.documentviewer settings of an object and return metadata that can be used to retrieve or access a preview image. :param obj: The Plone content object that has a preview :type obj: A Plone content object :return: Metadata consisting of canonical_url, number of pages and resource urls to preview images and thumbnails. :rtype: mapping """ site = getSite() global_settings = GlobalSettings(site) settings = Settings(obj) portal_url = site.portal_url() try: canonical_url = obj.absolute_url() except AttributeError: canonical_url = '' # XXX construct a url to an attachment if not hasattr(obj, 'UID') or not settings.successfully_converted: # Can't have previews on objects without a UID. Return a # minimal datastructure return { 'canonical_url': canonical_url + '/view', 'pages': settings.num_pages, 'resources': { 'page': { 'image': fallback_image_url(obj), 'text': '' }, 'pdf': canonical_url, 'thumbnail': fallback_image_url(obj), } } resource_url = global_settings.override_base_resource_url rel_url = storage.getResourceRelURL(gsettings=global_settings, settings=settings) if resource_url: dvpdffiles = '%s/%s' % (resource_url.rstrip('/'), rel_url) else: dvpdffiles = '%s/%s' % (portal_url, rel_url) dump_path = DUMP_FILENAME.rsplit('.', 1)[0] image_format = settings.pdf_image_format or \ global_settings.pdf_image_format return { 'canonical_url': canonical_url + '/view', 'pages': settings.num_pages, 'resources': { 'page': { 'image': '%s/{size}/%s_{page}.%s' % ( dvpdffiles, dump_path, image_format), 'text': '%s/%s/%s_{page}.txt' % ( dvpdffiles, TEXT_REL_PATHNAME, dump_path) }, 'pdf': canonical_url, 'thumbnail': '%s/small/%s_1.%s' % ( dvpdffiles, dump_path, image_format), } }