Commit d6174694 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_document_scanner: Fix code to generate PDF from images taken

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