def __call__(self): if not self.status_id: return self container = PLONESOCIAL.microblog status = container.get(self.status_id) if not self.attachment_id: # do we want to be able to traverse to the status update itself? # Returning only the id for now return self.status_id attachments = IAttachmentStorage(status) attachment = attachments.get(self.attachment_id) if not self.preview_type: self.request.response.setHeader( 'content-type', attachment.getContentType()) self.request.response.setHeader( 'content-disposition', 'inline; ' 'filename="{0}"'.format( self.attachment_id.encode('utf8'))) return attachment if IDocconv is not None: docconv = IDocconv(attachment) if self.preview_type == 'thumb': if docconv.has_thumbs(): return self._prepare_imagedata( attachment, docconv.get_thumbs()[0]) elif self.preview_type == 'preview': if docconv.has_previews(): return self._prepare_imagedata( attachment, docconv.get_previews()[0]) raise NotFound
def item2attachments(self, item): ''' Take the attachment sotrage item and transform it into an attachment ''' docconv = IDocconv(item) item_url = '/'.join(( self.attachment_base_url, item.getId(), )) if docconv.has_thumbs(): url = '/'.join((item_url, 'thumb')) elif isinstance(item, Image): images = api.content.get_view( 'images', item.aq_base, self.request, ) url = '/'.join(( item_url, images.scale(scale='preview').url.lstrip('/'), )) else: # We need a better fallback image. See #122 url = '/'.join(( api.portal.get().absolute_url(), '++theme++ploneintranet.theme/generated/media/logo.svg' )) return {'img_src': url, 'link': item_url}
def __call__(self): if not self.status_id: return self container = PLONESOCIAL.microblog status = container.get(self.status_id) if not self.attachment_id: # do we want to be able to traverse to the status update itself? # Returning only the id for now return self.status_id attachments = IAttachmentStorage(status) attachment = attachments.get(self.attachment_id) if not self.preview_type: self.request.response.setHeader('content-type', attachment.getContentType()) self.request.response.setHeader( 'content-disposition', 'inline; ' 'filename="{0}"'.format(self.attachment_id.encode('utf8'))) return attachment if IDocconv is not None: docconv = IDocconv(attachment) if self.preview_type == 'thumb': if docconv.has_thumbs(): return self._prepare_imagedata(attachment, docconv.get_thumbs()[0]) elif self.preview_type == 'preview': if docconv.has_previews(): return self._prepare_imagedata(attachment, docconv.get_previews()[0]) raise NotFound
def attachments(self): """ Get preview image for content-related updates""" if self.is_preview_supported(): docconv = IDocconv(self.context.context) if docconv.has_thumbs(): return [self.context.context.absolute_url() + '/docconv_image_thumb.jpg']
def render_attachments(self, attachments): """replaces ploneintranet/docconv/client/view.py helpers""" attachment = attachments[self.attachment_id] if not self.preview_type or self.preview_type in ( 'pdf-not-available', 'request-pdf'): return self._render_nopreview(attachment) docconv = IDocconv(attachment) # upload stage if self.preview_type == 'docconv_image_thumb.jpg': if docconv.has_thumbs(): previews = docconv.get_thumbs() imgdata = self._get_page_imgdata(previews) return self._prepare_imagedata(attachment, imgdata) elif self.preview_type == 'docconv_image_preview.jpg': if docconv.has_previews(): previews = docconv.get_previews() imgdata = self._get_page_imgdata(previews) return self._prepare_imagedata(attachment, imgdata) elif self.preview_type == 'pdf': if docconv.has_pdf(): pdfdata = docconv.get_pdf() return self._prepare_pdfdata(pdfdata) # normal view stage elif self.preview_type == 'thumb': if docconv.has_thumbs(): return self._prepare_imagedata( attachment, docconv.get_thumbs()[0]) elif self.preview_type == 'preview': if docconv.has_previews(): return self._prepare_imagedata( attachment, docconv.get_previews()[0]) elif self.preview_type == '@@images': images = api.content.get_view( 'images', attachment.aq_base, self.request, ) return self._prepare_imagedata( attachment, str(images.scale(scale='preview').data.data) ) raise NotFound
def test_docconv_adapter_on_new_object(self): docconv = IDocconv(self.testfile) self.assertFalse(docconv.has_pdf()) self.assertFalse(docconv.has_previews()) self.assertFalse(docconv.has_thumbs()) self.assertEquals(docconv.get_pdf(), None) self.assertEquals(docconv.get_previews(), None) self.assertEquals(docconv.get_thumbs(), None)
def test_fetch_docconv_data(self): fetchPreviews(self.testfile, virtual_url_parts=['dummy', ], vr_path='/plone') docconv = IDocconv(self.testfile) self.assertTrue(docconv.has_pdf()) self.assertTrue(docconv.has_previews()) self.assertTrue(docconv.has_thumbs())
def generate_attachment_preview_images(obj): if (IAttachmentStoragable is not None and IAttachmentStoragable.providedBy(obj)): attachment_storage = IAttachmentStorage(obj) for att_id in attachment_storage.keys(): docconv = IDocconv(attachment_storage.get(att_id)) if not docconv.has_thumbs(): docconv.generate_all()
def attachments(self): """ Get preview image for content-related updates""" if self.is_preview_supported(): docconv = IDocconv(self.context.context) if docconv.has_thumbs(): base_url = self.context.context.absolute_url() return [dict( img_src="{0}/docconv_image_thumb.jpg".format(base_url), link=base_url)]
def attachments(self): """ Get preview image for content-related updates""" if self.is_preview_supported(): docconv = IDocconv(self.context.context) if docconv.has_thumbs(): return [ self.context.context.absolute_url() + '/docconv_image_thumb.jpg' ]
def test_document(self): testdoc = api.content.create( type='Document', id='test-doc', title=u"Test Document", text=u'The main text', container=self.workspace) fetchPreviews(testdoc, virtual_url_parts=['dummy', ], vr_path='/plone') docconv = IDocconv(testdoc) self.assertTrue(docconv.has_pdf()) self.assertTrue(docconv.has_previews()) self.assertTrue(docconv.has_thumbs())
def __call__(self): if not self.status_id: return self container = PLONEINTRANET.microblog status = container.get(self.status_id) if not self.attachment_id: # do we want to be able to traverse to the status update itself? # Returning only the id for now return self.status_id attachments = IAttachmentStorage(status) attachment = attachments.get(self.attachment_id) if not self.preview_type: primary_field = IPrimaryFieldInfo(attachment).value mimetype = primary_field.contentType data = primary_field.data self.request.response.setHeader( 'content-type', mimetype) self.request.response.setHeader( 'content-disposition', 'inline; ' 'filename="{0}"'.format( safe_unicode(self.attachment_id).encode('utf8'))) return data if IDocconv is not None: docconv = IDocconv(attachment) if self.preview_type == 'thumb': if docconv.has_thumbs(): return self._prepare_imagedata( attachment, docconv.get_thumbs()[0]) elif self.preview_type == 'preview': if docconv.has_previews(): return self._prepare_imagedata( attachment, docconv.get_previews()[0]) elif self.preview_type == '@@images': images = api.content.get_view( 'images', attachment.aq_base, self.request, ) return self._prepare_imagedata( attachment, str(images.scale(scale='preview').data.data) ) raise NotFound
def attachments(self): """ Get preview images for status update attachments """ if all([ self.is_attachment_supported(), self.is_preview_supported(), IAttachmentStoragable.providedBy(self.status), ]): storage = IAttachmentStorage(self.status) attachments = storage.values() for attachment in attachments: docconv = IDocconv(attachment) if docconv.has_thumbs(): url = api.portal.get().absolute_url() yield ('{portal_url}/@@status-attachments/{status_id}/' '{attachment_id}/thumb').format( portal_url=url, status_id=self.status.getId(), attachment_id=attachment.getId())
def attachments(self): """ Get preview images for status update attachments """ if all([ self.is_attachment_supported(), self.is_preview_supported(), IAttachmentStoragable.providedBy(self.status), ]): storage = IAttachmentStorage(self.status) attachments = storage.values() for attachment in attachments: docconv = IDocconv(attachment) if docconv.has_thumbs(): url = api.portal.get().absolute_url() yield ('{portal_url}/@@status-attachments/{status_id}/' '{attachment_id}/thumb').format( portal_url=url, status_id=self.status.getId(), attachment_id=attachment.getId())
def attachments(self): """ Get preview images for status update attachments """ if not self.is_attachment_supported(): return [] if not self.is_preview_supported(): return [] if not IAttachmentStoragable.providedBy(self.status): return [] storage = IAttachmentStorage(self.status) items = storage.values() if not items: return [] attachments = [] portal_url = api.portal.get().absolute_url() base_url = '{portal_url}/@@status-attachments/{status_id}'.format( portal_url=portal_url, status_id=self.status.getId(), ) for item in items: item_url = '/'.join((base_url, item.getId())) docconv = IDocconv(item) if docconv.has_thumbs(): url = '/'.join((item_url, 'thumb')) elif isinstance(item, Image): images = api.content.get_view( 'images', item.aq_base, self.request, ) url = '/'.join(( item_url, images.scale(scale='preview').url.lstrip('/') )) else: # We need a better fallback image. See #See #122 url = '/'.join(( api.portal.get().absolute_url(), '++theme++ploneintranet.theme/generated/media/logo.svg')) if url: attachments.append(dict(img_src=url, link=item_url)) return attachments