Commit d32a1124 authored by Sven Franck's avatar Sven Franck Committed by Xiaowu Zhang

erp5_corporate_identity: improve slideshow rendering including displaying...

erp5_corporate_identity: improve slideshow rendering including displaying legacy presentation as slideshow
parent a8b888ae
Pipeline #9598 failed with stage
in 0 seconds
"""
================================================================================
Try to convert old OpenOffice presentations into slideshows
================================================================================
"""
# uses cloudooo to convert odp/sxi to html (quite buggy) and then salvages the
# result into a slideshow html, which is passed on as remote_content to the
# slideshow renderer
# kw-parameters (* default)
# ------------------------------------------------------------------------------
import re
blank = ''
flags = re.MULTILINE|re.DOTALL|re.IGNORECASE
def getHeaderSlideTitle(my_doc):
return '<h1>' + my_doc.getTitle() + '</h1>'
  • don't we need to escape title here ? ( or move this to a page template which escapes everything )

    /cc @georgios.dagkakis

  • or move this to a page template which escapes everything

    I think this is the best. Handling HTML in Python should be avoided as much as possible

  • This is probably a big change, what is easy to do now is something like this:

    from Products.PythonScripts.standard import html_quote
    
    def getHeaderSlideTitle(my_doc):
      return '<h1>' + html_quote(my_doc.getTitle()) + '</h1>'
Please register or sign in to reply
def getSlideList(content):
return re.findall(r'<html>(.*?)</html>', content, flags=flags)
def getKey(item):
return int(item[0])
# -------------------------------- Setup ---------------------------------------
if context.getPortalType() in ["Presentation"]:
portal = context.getPortalObject()
mimetype = 'text/html'
content_type = context.getContentType()
raw_data = portal.portal_transforms.convertToData(mimetype, str(context.getData() or ""), context=context, mimetype=content_type)
if raw_data is None:
raise ValueError("Failed to convert to %r" % mimetype)
if context.REQUEST is not None:
context.REQUEST.RESPONSE.setHeader("Content-Type", mimetype)
# get a list of slides
content = getSlideList(raw_data)
# every slide is in the raw_data twice, once with the title and image as text,
# once with the slidecontent without title. All slides are mixed randomly, so
# we need to find out which slide contains what and then put them in their
# correct order. We do this by extracting the links in the slides navigation
# bar. This bar as a switch to change from image to text slides with the
# current slide number so <a href="text3">Text</a> to switch from Graphic
# slide 3 to Text slide 3. We use this to identify current slide
if len(content) > 0:
slideshow = []
output = blank
for slide in content:
slide_nav = re.search(r'<center>(.*?)</center>', slide, flags=flags).group()
slide_nav_link_list = re.findall(r'<a(.*?)</a>', slide_nav, flags=flags)
for link in slide_nav_link_list:
# the header slide. Contains header and extracted text from image
if re.search(r'>Graphic', link, flags=flags):
pointer = re.search(r'(text|img)([0-9]*)\.', link, flags=flags)
if pointer is not None:
slide_header = re.search(r'<h1>(.*)?</h1>', slide, flags=flags).group()
slideshow.append([str(pointer.group(2)), slide_header])
# the content slide. Contains image and notes
if re.search(r'>Text', link, flags=flags):
pointer = re.search(r'(text|img)([0-9]*)\.', link, flags=flags)
if pointer is not None:
slideshow.append([str(pointer.group(2)), slide])
# time to sort and add first slide header in case missing
slideshow = sorted(slideshow, key=getKey)
if '<h1' not in slideshow[0][1]:
slideshow.insert(0, ["0", getHeaderSlideTitle(context)])
output = ""
section_start = '<section>'
section_end = '</section>'
# slideshow will contain <header>, <content>, <header>, <content>...
# so we need to go through it two-slides at a time to assemble
# slides
slide_iter = iter(slideshow)
for slide in slide_iter:
slide_1st = slide
slide_2nd = next(slide_iter)
# we don't know whether header is on first or second position
if '<h1' not in slide_1st[1]:
go_1st = slide_2nd[1]
go_2nd = slide_1st[1]
else:
go_1st = slide_1st[1]
go_2nd = slide_2nd[1]
go_2nd = go_2nd.replace(re.search(r'<head>.*?</center><br>', go_2nd, flags=flags).group(), blank)
go_2nd = go_2nd.replace("<h3>Notes:</h3><br>", '<details open="open">')
go_2nd = go_2nd.replace("</body>", "</details>")
output = output + section_start + go_1st + go_2nd + section_end
kw["remote_content"] = output
  • @frequent @xiaowu.zhang Can you please double check, kw is an undefined variable here and this cause a test failure

    https://nexedijs.erp5.net/#/test_result_module/20200527-1082CFAA/46?

  • strange, corporate identity codingstyle tests are not running on my test suite

    kw parameter is missing, i add it

    Edited by Xiaowu Zhang
  • Thanks ! That must be a bug in testnode or something.

    The list of tested business template is evaluated here

    maybe what happens is that this is called first and only after this the new git repository revision is used.

    coding style on this bt was enabled very recently xiaowu.zhang/erp5@73aef12e

    maybe first ERP5BusinessTemplateCodingStyleTestSuite.getTestList was called with the old version of the code, when this business template was still skipped.

    If that's really this, it should not be often a problem, I will not look more into this, unless we see this happening again. If you can fix the missing km parameters (there also seems to be same problem with the other script from this commit), that's good for now I would say. Thanks !

    Edited by Jérome Perrin
Please register or sign in to reply
return context.WebPage_viewAsSlideshowWIP(*args, **kw)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Presentation_viewAsSlideshow</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment