Exemplo n.º 1
0
    def _oooConvertByFormat(self, printout, content_type, extra_context, REQUEST, format, batch_mode):
        """
    Convert the ODF document into the given format.

    Keyword arguments:
    printout -- ODF document
    content_type -- the content type of the printout
    extra_context -- extra_context including a format
    REQUEST -- Request object
    format -- requested output format
    batch_mode -- Disable headers overriding
    """
        if REQUEST is not None and not format:
            format = REQUEST.get("format", None)
        filename = self.getProperty("filename")
        # Call refresh through cloudooo
        # XXX This is a temporary implementation:
        # Calling a webservice must be done through a WebServiceMethod
        # and a WebServiceConnection
        from Products.ERP5OOo.Document.OOoDocument import OOoServerProxy, enc, dec

        server_proxy = OOoServerProxy(self)
        extension = guess_extension(content_type).strip(".")
        printout = dec(
            server_proxy.convertFile(
                enc(printout), extension, extension, False, True  # source_format  # destination_format  # zip
            )
        )  # refresh
        # End of temporary implementation
        if not format:
            if REQUEST is not None and not batch_mode:
                REQUEST.RESPONSE.setHeader("Content-Length", len(printout))
                REQUEST.RESPONSE.setHeader("Content-Type", "%s" % content_type)
                REQUEST.RESPONSE.setHeader(
                    "Content-disposition", 'inline;filename="%s%s"' % (filename, guess_extension(content_type) or "")
                )
            return printout
        from Products.ERP5Type.Document import newTempOOoDocument

        tmp_ooo = newTempOOoDocument(self, self.title_or_id())
        tmp_ooo.edit(
            data=printout,
            base_data=printout,
            filename=self.title_or_id(),
            content_type=content_type,
            base_content_type=content_type,
        )
        mime, data = tmp_ooo.convert(format)
        if REQUEST is not None and not batch_mode:
            REQUEST.RESPONSE.setHeader("Content-Length", len(data))
            REQUEST.RESPONSE.setHeader("Content-type", mime)
            REQUEST.RESPONSE.setHeader("Content-disposition", 'attachment;filename="%s.%s"' % (filename, format))
        return str(data)
Exemplo n.º 2
0
 def convertTo(self, format):
     server_proxy = OOoServerProxy(self.context)
     response_code, response_dict, message = server_proxy.getAllowedTargetItemList(self.mimetype)
     allowed_extension_list = response_dict["response_data"]
     if format in dict(allowed_extension_list):
         response_code, response_dict, message = server_proxy.run_generate(
             "", enc(self.data), None, format, self.mimetype
         )
         data = dec(response_dict["data"])
         if self.mimetype == "text/html":
             data = self.includeImageList(data)
         return data
     else:
         raise ConversionError("Format not allowed %s" % format)
Exemplo n.º 3
0
 def convertTo(self, format):
     server_proxy = OOoServerProxy(self.context)
     response_code, response_dict, message = \
                            server_proxy.getAllowedTargetItemList(self.mimetype)
     allowed_extension_list = response_dict['response_data']
     if format in dict(allowed_extension_list):
         response_code, response_dict, message = server_proxy.run_generate(
             '', enc(self.data), None, format, self.mimetype)
         data = dec(response_dict['data'])
         if self.mimetype == 'text/html':
             data = self.includeImageList(data)
         return data
     else:
         raise ConversionError('Format not allowed %s' % format)