Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Aurélien Vermylen
erp5
Commits
98076a1b
Commit
98076a1b
authored
May 19, 2017
by
Klaus Wölfel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_data_notebook: Add notebook conversion and execution
parent
220338f7
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
732 additions
and
7 deletions
+732
-7
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterConvert.py
...teItem/portal_components/extension.erp5.JupyterConvert.py
+71
-0
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterConvert.xml
...eItem/portal_components/extension.erp5.JupyterConvert.xml
+127
-0
bt5/erp5_data_notebook/PortalTypeTemplateItem/portal_types/Data%20Notebook.xml
...k/PortalTypeTemplateItem/portal_types/Data%20Notebook.xml
+402
-6
bt5/erp5_data_notebook/SkinTemplateItem/portal_skins/erp5_data_notebook/DataNotebook_toHtml.xml
...m/portal_skins/erp5_data_notebook/DataNotebook_toHtml.xml
+28
-0
bt5/erp5_data_notebook/SkinTemplateItem/portal_skins/erp5_data_notebook/DataNotebook_toPdf.py
...tem/portal_skins/erp5_data_notebook/DataNotebook_toPdf.py
+40
-0
bt5/erp5_data_notebook/SkinTemplateItem/portal_skins/erp5_data_notebook/DataNotebook_toPdf.xml
...em/portal_skins/erp5_data_notebook/DataNotebook_toPdf.xml
+62
-0
bt5/erp5_data_notebook/bt/template_extension_id_list
bt5/erp5_data_notebook/bt/template_extension_id_list
+2
-1
No files found.
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterConvert.py
0 → 100644
View file @
98076a1b
import
nbformat
import
ssl
import
re
from
base64
import
b64encode
,
b64decode
from
nbconvert
import
HTMLExporter
from
nbconvert.preprocessors
import
Preprocessor
,
ExecutePreprocessor
from
xmlrpclib
import
ServerProxy
from
urllib
import
urlencode
from
urllib2
import
urlopen
class
PyMarkdownPreprocessor
(
Preprocessor
):
"""
:mod:`nbconvert` Preprocessor for the python-markdown nbextension.
This :class:`~nbconvert.preprocessors.Preprocessor` replaces kernel code in
markdown cells with the results stored in the cell metadata.
"""
def
replace_variables
(
self
,
source
,
variables
):
"""
Replace {{variablename}} with stored value
"""
try
:
replaced
=
re
.
sub
(
"{{(.*?)}}"
,
lambda
m
:
variables
.
get
(
m
.
group
(
1
),
''
),
source
)
except
TypeError
:
replaced
=
source
return
replaced
def
preprocess_cell
(
self
,
cell
,
resources
,
index
):
"""
Preprocess cell
Parameters
----------
cell : NotebookNode cell
Notebook cell being processed
resources : dictionary
Additional resources used in the conversion process. Allows
preprocessors to pass variables into the Jinja engine.
cell_index : int
Index of the cell being processed (see base.py)
"""
if
cell
.
cell_type
==
"markdown"
:
if
hasattr
(
cell
[
'metadata'
],
'variables'
):
variables
=
cell
[
'metadata'
][
'variables'
]
if
len
(
variables
)
>
0
:
cell
.
source
=
self
.
replace_variables
(
cell
.
source
,
variables
)
return
cell
,
resources
def
to_html
(
self
):
notebook
=
nbformat
.
reads
(
self
.
getTextContent
(),
as_version
=
4
)
resources
=
{}
notebook
=
\
ExecutePreprocessor
(
kernel_name
=
"erp5"
).
preprocess
(
notebook
,
resources
)[
0
]
notebook
=
PyMarkdownPreprocessor
().
preprocess
(
notebook
,
resources
)[
0
]
html_exporter
=
HTMLExporter
()
html_exporter
.
template_file
=
'full'
body
,
resources
=
html_exporter
.
from_notebook_node
(
notebook
)
return
body
def
cloudoooConvertFile
(
self
,
data
,
source_mimetype
,
destination_mimetype
,
zip
=
False
,
refresh
=
False
,
conversion_kw
=
None
):
url
=
'https://softinst78992.host.vifib.net/erp5/ERP5Site_htmlToPdf'
data_dict
=
{
'data'
:
b64encode
(
data
)}
data_dict
.
update
(
**
conversion_kw
)
return
urlopen
(
url
=
url
,
data
=
urlencode
(
data_dict
)).
read
()
proxy
=
ServerProxy
(
self
.
getPortalObject
().
portal_preferences
.
getPreferredDocumentConversionServerUrl
(),
allow_none
=
True
)
return
b64decode
(
proxy
.
convertFile
(
b64encode
(
data
),
source_mimetype
,
destination_mimetype
,
zip
,
refresh
,
conversion_kw
or
{}))
bt5/erp5_data_notebook/ExtensionTemplateItem/portal_components/extension.erp5.JupyterConvert.xml
0 → 100644
View file @
98076a1b
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"Extension Component"
module=
"erp5.portal_type"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
_recorded_property_dict
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAI=
</string>
</persistent>
</value>
</item>
<item>
<key>
<string>
default_reference
</string>
</key>
<value>
<string>
JupyterConvert
</string>
</value>
</item>
<item>
<key>
<string>
description
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
extension.erp5.JupyterConvert
</string>
</value>
</item>
<item>
<key>
<string>
portal_type
</string>
</key>
<value>
<string>
Extension Component
</string>
</value>
</item>
<item>
<key>
<string>
sid
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
text_content_error_message
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
text_content_warning_message
</string>
</key>
<value>
<tuple>
<string>
W: 65, 75: Redefining built-in \'zip\' (redefined-builtin)
</string>
<string>
W: 70, 2: Unreachable code (unreachable)
</string>
<string>
W: 2, 0: Unused import ssl (unused-import)
</string>
</tuple>
</value>
</item>
<item>
<key>
<string>
version
</string>
</key>
<value>
<string>
erp5
</string>
</value>
</item>
<item>
<key>
<string>
workflow_history
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAM=
</string>
</persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"2"
aka=
"AAAAAAAAAAI="
>
<pickle>
<global
name=
"PersistentMapping"
module=
"Persistence.mapping"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
data
</string>
</key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"3"
aka=
"AAAAAAAAAAM="
>
<pickle>
<global
name=
"PersistentMapping"
module=
"Persistence.mapping"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
data
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
component_validation_workflow
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAQ=
</string>
</persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"4"
aka=
"AAAAAAAAAAQ="
>
<pickle>
<global
name=
"WorkflowHistoryList"
module=
"Products.ERP5Type.patches.WorkflowTool"
/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key>
<string>
action
</string>
</key>
<value>
<string>
validate
</string>
</value>
</item>
<item>
<key>
<string>
validation_state
</string>
</key>
<value>
<string>
validated
</string>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
bt5/erp5_data_notebook/PortalTypeTemplateItem/portal_types/Data%20Notebook.xml
View file @
98076a1b
This diff is collapsed.
Click to expand it.
bt5/erp5_data_notebook/SkinTemplateItem/portal_skins/erp5_data_notebook/DataNotebook_toHtml.xml
0 → 100644
View file @
98076a1b
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"ExternalMethod"
module=
"Products.ExternalMethod.ExternalMethod"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
_function
</string>
</key>
<value>
<string>
to_html
</string>
</value>
</item>
<item>
<key>
<string>
_module
</string>
</key>
<value>
<string>
JupyterConvert
</string>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
DataNotebook_toHtml
</string>
</value>
</item>
<item>
<key>
<string>
title
</string>
</key>
<value>
<string></string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
bt5/erp5_data_notebook/SkinTemplateItem/portal_skins/erp5_data_notebook/DataNotebook_toPdf.py
0 → 100644
View file @
98076a1b
from
base64
import
b64encode
portal
=
context
.
getPortalObject
()
#web_page = portal.web_page_module.newContent(
# text_content = text_content,
# temp_object=1,
# title="Bericht")
web_page
=
context
.
web_page_module
[
"6"
]
text_content
=
context
.
DataNotebook_toHtml
()
web_page
.
setTextContent
(
text_content
)
html_data
=
web_page
.
WebPage_exportAsSingleFile
(
format
=
"html"
,
allow_script
=
True
)
pdf_file
=
portal
.
Base_cloudoooConvertFile
(
html_data
,
"html"
,
"pdf"
,
conversion_kw
=
dict
(
encoding
=
"utf8"
,
margin_top
=
10
,
margin_bottom
=
10
,
margin_left
=
10
,
margin_right
=
10
,
header_spacing
=
0
,
header_html_data
=
b64encode
(
""
),
footer_html_data
=
b64encode
(
""
),
print_media_type
=
True
,
javascript_delay
=
9000
,
page_size
=
"A4"
,
zoom
=
1
,
dpi
=
"75"
)
)
REQUEST
=
context
.
REQUEST
if
REQUEST
is
not
None
:
REQUEST
.
RESPONSE
.
setHeader
(
"Content-Type"
,
"application/pdf"
)
REQUEST
.
response
.
setHeader
(
'Content-Length'
,
len
(
pdf_file
))
#REQUEST.response.setHeader('Content-Disposition',
# 'attachment;filename="%s.pdf"' % context.getTitle())
return
pdf_file
bt5/erp5_data_notebook/SkinTemplateItem/portal_skins/erp5_data_notebook/DataNotebook_toPdf.xml
0 → 100644
View file @
98076a1b
<?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>
DataNotebook_toPdf
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
bt5/erp5_data_notebook/bt/template_extension_id_list
View file @
98076a1b
extension.erp5.JupyterCompile
extension.erp5.JupyterCompile
extension.erp5.JupyterConvert
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment