module.erp5.TransformPptToPptx.py 1.25 KB
Newer Older
1
from Products.PortalTransforms.interfaces import itransform
2
from zope.interface import implementer
3 4 5
from Products.ERP5OOo.transforms.oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream


6
@implementer(itransform)
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
class PptToPptx:
  """Transforms ppt to pptx by using Cloudooo"""

  __name__ = 'ppt_to_pptx'
  inputs   = ('application/vnd.ms-powerpoint',
              'application/powerpoint',
              'application/mspowerpoint',
              'application/x-mspowerpoint')
  output = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'

  tranform_engine = OOOdCommandTransform.__module__

  def name(self):
    return self.__name__

  def __getattr__(self, attr):
    if attr == 'inputs':
      return self.config['inputs']
    if attr == 'output':
      return self.config['output']
    raise AttributeError(attr)

  def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs):
Jérome Perrin's avatar
Jérome Perrin committed
30
    data = bytes(orig)
31 32 33 34 35 36 37 38 39 40 41 42
    ppt = OOOdCommandTransform(context, filename, data, self.inputs[0])
    pptx = ppt.convertTo('pptx')
    if cache is not None:
      cache.setData(pptx)
      return cache
    else:
      stream = OOoDocumentDataStream()
      stream.setData(pptx)
      return stream

def register():
  return PptToPptx()