Exemple #1
0
def generate_attachment_preview_images(obj):
    if not IAttachmentStoragable.providedBy(obj):
        return
    attachment_storage = IAttachmentStorage(obj)
    for att_id in attachment_storage.keys():
        attachment = attachment_storage.get(att_id)
        if not pi_api.previews.has_previews(attachment):
            pi_api.previews.generate_previews(attachment)
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()
Exemple #3
0
def generate_attachment_preview_images(obj):
    if not IAttachmentStoragable.providedBy(obj):
        return
    attachment_storage = IAttachmentStorage(obj)
    for att_id in attachment_storage.keys():
        attachment = attachment_storage.get(att_id)
        if not pi_api.previews.has_previews(attachment):
            pi_api.previews.generate_previews(attachment)
Exemple #4
0
def generate_attachment_preview_images(obj):
    if not IAttachmentStoragable.providedBy(obj):
        return
    attachment_storage = IAttachmentStorage(obj)
    for att_id in attachment_storage.keys():
        attachment = attachment_storage.get(att_id)
        if not pi_api.previews.has_previews(attachment):
            log.debug('generate_attachment_preview_images'
                      ' - generating attachment preview')
            generate_previews_async(attachment)
    def create_post_attachment(self, post):
        """ Check:
         - if the post supports attachments
         - if we have an attachment posted

        If both are True attach the data to the post
        """
        if IAttachmentStoragable is None:
            return
        if not IAttachmentStoragable.providedBy(post):
            return
        if not self.post_attachment:
            return
        token = self.request.get("attachment-form-token")
        extract_and_add_attachments(self.post_attachment, post, workspace=self.context, token=token)
    def create_post_attachment(self, post):
        """ Check:
         - if the post supports attachments
         - if we have an attachment posted

        If both are True attach the data to the post
        """
        if not IAttachmentStoragable.providedBy(post):
            return
        if not self.post_attachment:
            return
        token = self.request.get('attachment-form-token')
        extract_and_add_attachments(self.post_attachment,
                                    post,
                                    workspace=self.microblog_context,
                                    token=token)
 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
Exemple #10
0
    def handleComment(self, action):

        # Validation form
        data, errors = self.extractData()
        if errors:
            return

        container = queryUtility(IMicroblogTool)
        microblog_context = get_microblog_context(self.context)
        if hasattr(self.context, 'thread_id') and self.context.thread_id:
            thread_id = self.context.thread_id  # threaded
        elif self.context.__class__.__name__ == 'StatusUpdate':
            thread_id = self.context.id  # first reply
        else:
            thread_id = None  # new
        status = StatusUpdate(data['text'],
                              context=microblog_context,
                              thread_id=thread_id)

        file_upload = self.request.get('form.widgets.attachments')
        attachments_supported = (IAttachmentStoragable is not None
                                 and IAttachmentStoragable.providedBy(status))
        if attachments_supported and file_upload:
            token = self.request.get('attachment-form-token')
            extract_and_add_attachments(file_upload,
                                        status,
                                        workspace=self.context,
                                        token=token)

        # debugging only


#        container.clear()

# save the status update
        container.add(status)

        # Redirect to portal home
        self.request.response.redirect(self.action)
    def handleComment(self, action):

        # Validation form
        data, errors = self.extractData()
        if errors:
            return

        container = queryUtility(IMicroblogTool)
        microblog_context = get_microblog_context(self.context)
        if hasattr(self.context, 'thread_id') and self.context.thread_id:
            thread_id = self.context.thread_id  # threaded
        elif self.context.__class__.__name__ == 'StatusUpdate':
            thread_id = self.context.id  # first reply
        else:
            thread_id = None  # new
        status = StatusUpdate(data['text'],
                              context=microblog_context,
                              thread_id=thread_id)

        file_upload = self.request.get('form.widgets.attachments')
        attachments_supported = (
            IAttachmentStoragable is not None and
            IAttachmentStoragable.providedBy(status))
        if attachments_supported and file_upload:
            token = self.request.get('attachment-form-token')
            extract_and_add_attachments(
                file_upload, status, workspace=self.context, token=token)

        # debugging only
#        container.clear()

        # save the status update
        container.add(status)

        # Redirect to portal home
        self.request.response.redirect(self.action)
 def test_storageable(self):
     comment = createObject('plone.Comment')
     self.assertTrue(IAttachmentStoragable.providedBy(comment))
     question = createObject('slc.underflow.question')
     self.assertTrue(IAttachmentStoragable.providedBy(question))