Exemplo n.º 1
0
    def _process(self):
        from_preview = request.args.get('from_preview') == '1'
        force_download = request.args.get('download') == '1'

        signals.attachments.attachment_accessed.send(self.attachment,
                                                     user=session.user,
                                                     from_preview=from_preview)
        if request.values.get('preview') == '1':
            if self.attachment.type != AttachmentType.file:
                raise BadRequest
            previewer = get_file_previewer(self.attachment.file)
            if not previewer:
                raise NoReportError.wrap_exc(
                    BadRequest(
                        _('There is no preview available for this file type. '
                          'Please refresh the page.')))
            preview_content = previewer.generate_content(self.attachment)
            return jsonify_template('attachments/preview.html',
                                    attachment=self.attachment,
                                    preview_content=preview_content)
        else:
            if self.attachment.type == AttachmentType.link:
                return redirect(self.attachment.link_url)
            else:
                return self.attachment.file.send(inline=not force_download)
Exemplo n.º 2
0
    def _process(self):
        from_preview = request.args.get('from_preview') == '1'
        force_download = request.args.get('download') == '1'

        signals.attachments.attachment_accessed.send(self.attachment, user=session.user, from_preview=from_preview)
        if request.values.get('preview') == '1':
            if self.attachment.type != AttachmentType.file:
                raise BadRequest
            previewer = get_file_previewer(self.attachment.file)
            if not previewer:
                raise BadRequest
            preview_content = previewer.generate_content(self.attachment)
            return jsonify_template('attachments/preview.html', attachment=self.attachment,
                                    preview_content=preview_content)
        else:
            if self.attachment.type == AttachmentType.link:
                return redirect(self.attachment.link_url)
            else:
                return self.attachment.file.send(inline=not force_download)
Exemplo n.º 3
0
    def _process(self):
        from_preview = request.args.get('from_preview') == '1'
        force_download = request.args.get('download') == '1'

        signals.attachments.attachment_accessed.send(self.attachment, user=session.user, from_preview=from_preview)
        if request.values.get('preview') == '1':
            if self.attachment.type != AttachmentType.file:
                raise BadRequest
            previewer = get_file_previewer(self.attachment.file)
            if not previewer:
                raise NoReportError.wrap_exc(BadRequest(_('There is no preview available for this file type. '
                                                          'Please refresh the page.')))
            preview_content = previewer.generate_content(self.attachment)
            return jsonify_template('attachments/preview.html', attachment=self.attachment,
                                    preview_content=preview_content)
        else:
            if self.attachment.type == AttachmentType.link:
                return redirect(self.attachment.link_url)
            else:
                return self.attachment.file.send(inline=not force_download)
Exemplo n.º 4
0
 def is_previewable(self):
     return get_file_previewer(self) is not None
Exemplo n.º 5
0
 def is_previewable(self):
     return get_file_previewer(self) is not None