Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit 6224cd15 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the logic to export a graph as a PDF of PNG file.

parent ac79105f
*~
*.pdf
.project
.pydevproject
*.pyc
......
......@@ -48,8 +48,22 @@ def graph_mpl():
# build the report title
title = do_title(config, selector)
# extract the image
# encode special character to be used in the image URI
extension = request.extension
if extension == "html":
data = graph.to_svg()
data = urllib.quote(data)
elif extension == "pdf":
data = graph.to_pdf()
elif extension == "png":
data = graph.to_png()
# delegate the rendering to the view
return dict(data=graph.to_svg(), title=title)
return dict(data=data, title=title)
def grid():
......
......@@ -118,6 +118,8 @@
'events': 'évènements',
'Evènement': 'Evènement',
'Executed': 'Executé',
'Export to PDF...': 'Exporter au format PDF...',
'Export to PNG...': 'Exporter au format PNG...',
'Feature not yet implemented ...': 'Feature not yet implemented ...',
'Features': 'Features',
'Field': 'Champ',
......@@ -293,6 +295,7 @@
'Please select a metric!': 'Sélectionnez une metrique !',
'Plot': 'Plot',
'plugin not install': 'greffon pas installé',
'Processing time %s seconds': 'Image générée en %s secondes',
'Profile': 'Profile',
'Project': 'Projet',
'project leader,...': 'project leader,...',
......@@ -318,6 +321,7 @@
'Reset Password key': 'Reset Password key',
'responsibilities': 'responsabilités',
'Responsibility': 'Responsabilité',
'Right click on the image in order to export it...': "Click droit sur l'image pour l'exporter...",
'Role': 'Role',
"Row are grouped according to the value of that field. It can be any field of the history table including those of the foreign tables, the individual property of the history.data dictionary, or 'year'.": "Les lignes sont regroupées en fonctions des valeurs de ce champ. C'est un champ de la table historique en incluant tous les champs des tables étrangères, les clés du dictionaire history.data , ou 'year'.",
'Select': 'Selectionnez',
......
......@@ -62,7 +62,7 @@ def do_title(config, selector):
elif selector.year_start and selector.year_end:
years = (str(selector.year_start), str(selector.year_end))
metadata.append(T("from %s to %s") % years)
metadata.append(T("from %s to %s", lazy=False) % years)
return "%s: %s" % (title, " / ".join(metadata))
......
{{
#--------------------------------------------------------------------------
#.........................................................................
#
# The python controller return image as a string:
# - data (string)
# - title (string)
#
#--------------------------------------------------------------------------
import datetime
import urllib
#
# The title
#
response.write(H2(title, _class="dbui-h2 dbui-small-cap"))
# build the url to retrieve the png or pdf image
# it should contains the current "vars" use to generate the image
myapp = request.application
myvars = urllib.urlencode(request.vars)
url_pdf = "/%s/plugin_event/graph_mpl.pdf?%s" % (myapp, myvars)
url_png = "/%s/plugin_event/graph_mpl.png?%s" % (myapp, myvars)
# unique identfier for the div block
divid = "myimage-%i" % id(data)
# elapse time for the footer
delta = (datetime.datetime.now()-request.now).total_seconds()
processing_time = T('Processing time %s seconds') % round(delta, 2)
# encode special charactier bo be used in the image URI
data = urllib.quote(data)
# translate
trExport = T("Right click on the image in order to export it...")
trToPDF = T("Export to PDF...")
trToPNG = T("Export to PNG...")
}}
<img src="data:image/svg+xml;utf8,{{=data}}" height=400></img>
<h2 class="dbui-h2 dbui-small-cap">{{=title}}</h2>
<div id="{{=divid}}"></div>
<p class="dbui-p">
<br>
{{=trExport}}<br>
{{=processing_time}}
</p>
<script type="text/javascript">
/**
* Create the panel to include the image
* The panel allow to expose a context menu which can be used to
* export the image in different format
*/
var menu, panel;
panel = Ext.create("Ext.panel.Panel", {
border: false,
html: '<img src="data:image/svg+xml;utf8,{{=data}}" height=400></img>',
layout: "fit",
padding: "0 0 0 30",
renderTo: "{{=divid}}",
});
menu = Ext.create("Ext.menu.Menu", {
items: [{
text: "{{=trToPNG}}",
href: "{{=url_png}}"
}, {
text: "{{=trToPDF}}",
href: "{{=url_pdf}}",
iconCls: 'xminetype-pdf'
}]
});
panel.body.on("contextmenu", function(event) {
event.stopEvent();
menu.showAt(event.getXY());
});
</script>
{{
import cStringIO
response.body = cStringIO.StringIO()
response.headers['Content-Type']='application/pdf'
response.write(data, escape=False)
}}
\ No newline at end of file
{{
import cStringIO
response.body = cStringIO.StringIO()
response.headers['Content-Type']='application/png'
response.write(data, escape=False)
}}
\ No newline at end of file
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