Commit f5ce78b0 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: Fix code to generate PDF from images taken

parent 813fc044
......@@ -93,13 +93,13 @@
}
});
})
.push(function (response) {
var state_dict = {};
.push(function (evt) {
var state_dict = {},
data = JSON.parse(evt.target.responseText);
state_dict['blob_state_' + blob_page] = 'OK';
state_dict['blob_uuid_' + blob_page] = response.uuid;
state_dict['blob_uuid_' + blob_page] = data.uuid;
return gadget.changeState(state_dict);
}, function () {
// XXX TODO: Handle error case
var state_dict = {};
state_dict['blob_state_' + blob_page] = 'error';
return gadget.changeState(state_dict);
......@@ -607,18 +607,29 @@
// Used when submitting the form
//////////////////////////////////////////////////
.declareMethod('getContent', function () {
var gadget = this,
result = {};
// XXX TODO: check all blob, and only return the UUID for the one in stored state
result.data_json = JSON.stringify({
active_process: gadget.state.active_process,
image_list: gadget.state.image_list
});
result[gadget.state.key] = JSON.stringify({
input_value: 'XXX',
preferred_cropped_canvas_data: gadget.state.preferred_cropped_canvas_data
});
throw new Error('not implemented getContent');
var key,
uuid_key,
result,
gadget = this,
image_list = [];
for (key in gadget.state) {
if (gadget.state.hasOwnProperty(key)) {
if (key.indexOf("blob_state_") !== -1 &&
gadget.state[key] == "OK") {
uuid_key = "blob_uuid_" + key.replace("blob_state_", "");
image_list.push(gadget.state[uuid_key]);
}
}
}
result = {
data_json: JSON.stringify({
active_process: gadget.state.active_process,
image_list: image_list,
preferred_cropped_canvas_data: gadget.state.preferred_cropped_canvas_data
})
};
return result;
}, {mutex: 'changestate'})
.declareMethod('checkValidity', function () {
......@@ -628,7 +639,7 @@
for (key in gadget.state) {
if (gadget.state.hasOwnProperty(key)) {
if (key.indexOf("blob_state_") !== -1 &&
!gadget.state[key].match("deleted|stored")) {
!gadget.state[key].match("deleted|OK")) {
return false;
}
if (key.indexOf("blob_url_") !== -1) {
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>981.40903.42421.64529</string> </value>
<value> <string>981.42511.4469.1024</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1580845018.98</float>
<float>1580940947.83</float>
<string>UTC</string>
</tuple>
</state>
......
"""
Proxy role as Manager is required here to access getResultList
"""
from base64 import decodestring
if REQUEST:
return RuntimeError("You cannot run this script in the url")
......@@ -8,9 +9,10 @@ image_module = context.getPortalObject().image_module
pdf_data_list = []
for result in active_process.getResultList():
pdf_data_list.append(
image_module.newContent(data=result.detail,
portal_type="Image",
temp_object=True).convert(format="pdf")[1])
if result.reference in image_list:
pdf_data_list.append(
image_module.newContent(data=decodestring(result.detail),
portal_type="Image",
temp_object=False).convert(format="pdf")[1])
return pdf_data_list
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>active_process, REQUEST=None</string> </value>
<value> <string>active_process, image_list, REQUEST=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
......
......@@ -5,9 +5,9 @@ class StringIOWithFileName(StringIO):
kw.get("title") or DateTime().strftime('%d-%m-%Y_%Hh%M'))
portal = context.getPortalObject()
active_process = portal.restrictedTraverse(active_process_url)
active_process = portal.restrictedTraverse(str(active_process_url))
pdf_data_list = context.Base_getTempImageList(active_process)
pdf_data_list = context.Base_getTempImageList(active_process, image_list)
pdf_data = context.ERP5Site_mergePDFList(pdf_data_list=pdf_data_list)
file_object = StringIOWithFileName(pdf_data)
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>publication_state, active_process_url=None, **kw</string> </value>
<value> <string>publication_state, active_process_url, image_list, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
import json
data_dict = json.loads(data_json)
portal = context.getPortalObject()
translateString = portal.Base_translateString
active_process_url = data_dict.pop("active_process")
image_list = data_dict.pop("image_list")
# Avoid to pass huge images to the activity
kw.pop("your_document_scanner_gadget", None)
context.activate().Base_uploadDocumentFromCamera(
publication_state=publication_state,
active_process_url=active_process_url,
image_list=image_list,
**kw)
return context.Base_redirect('view',
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>active_process_url=None, **kw</string> </value>
<value> <string>data_json, publication_state, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
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