Odoo Help

4

1
10 Answers
1
Vicious Paraguay
6/30/14, 2:17 AM

 UPDATE

 By insisting I'll post the code to load more than one file at a time:

In the http.py file must comment a line and add another, in the line 608:

http.py

class HttpRequest(WebRequest):
""" Handler for the ``http`` request type.

matched routing parameters, query string parameters, form_ parameters
and files are passed to the handler method as keyword arguments.

In case of name conflict, routing parameters have priority.

The handler method's result can be:

* a falsy value, in which case the HTTP response will be an
`HTTP 204`_ (No Content)
* a werkzeug Response object, which is returned as-is
* a ``str`` or ``unicode``, will be wrapped in a Response object and
interpreted as HTML

.. _form: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
.. _HTTP 204: http://tools.ietf.org/html/rfc7231#section-6.3.5
"""
_request_type = "http"

def __init__(self, *args):
super(HttpRequest, self).__init__(*args)
params = self.httprequest.args.to_dict()
params.update(self.httprequest.form.to_dict())
#params.update(self.httprequest.files.to_dict())
params.update(self.httprequest.files) # Modified line
params.pop('session_id', None)
self.params = params

My controller:

from openerp import http
import simplejson
import time
import os
import StringIO


class Binary_Multi(http.Controller):

@http.route('/web/binary/multi_picture_upload', type="http", auth="public")
def multi_picture_upload(self, req, callback, ufile):
out = """<script language="javascript src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" type="text/javascript">
var win = window.top.window;
win.jQuery(win).trigger(%s, %s);
</script>"""
args = []
for nfile in ufile:
data = nfile.read()
current_dat_time = time.strftime("%d-%m-%Y-%H_%M_%S")
file_name = current_dat_time + "_" + nfile.filename
addons_path = http.addons_manifest['web']['addons_path'] +\
"/web/static/src/img/image_multi/"
if not os.path.isdir(addons_path):
os.mkdir(addons_path)
addons_path += file_name
buff = StringIO.StringIO()
buff.write(data)
buff.seek(0)
file_name = "/web/static/src/img/image_multi/" + file_name
file = open(addons_path, 'wb')
file.write(buff.read())
file.close()
args.append([len(data), file_name, nfile.content_type,
nfile.filename, time.strftime("%m/%d/%Y %H:%M:%S")])
return out % (simplejson.dumps(callback), simplejson.dumps(args))

 Now you can scroll through the list with for loop

but this would cause us a problem, if we upload attachments in fields.Binary.

I modify the core again to use both, my multiple images fields and traditional fields.Binary attachments.

class HttpRequest(WebRequest):
""" Handler for the ``http`` request type.

matched routing parameters, query string parameters, form_ parameters
and files are passed to the handler method as keyword arguments.

In case of name conflict, routing parameters have priority.

The handler method's result can be:

* a falsy value, in which case the HTTP response will be an
`HTTP 204`_ (No Content)
* a werkzeug Response object, which is returned as-is
* a ``str`` or ``unicode``, will be wrapped in a Response object and
interpreted as HTML

.. _form: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
.. _HTTP 204: http://tools.ietf.org/html/rfc7231#section-6.3.5
"""
_request_type = "http"

def __init__(self, *args):
super(HttpRequest, self).__init__(*args)
params = self.httprequest.args.to_dict()
params.update(self.httprequest.form.to_dict())
#params.update(self.httprequest.files.to_dict())

str_args = str(args)
# If the request is from my controller,( in tis case, multi_picture_upload)then use modified line
if str_args.find("multi_picture_upload") >=0: #
params.update(self.httprequest.files)
# Else, just use the original line
else:
params.update(self.httprequest.files.to_dict())
params.pop('session_id', None)
self.params = params


sorry that my code is so ugly/akward, and my English so bad. 

7 Comments
Vicious Paraguay
6/30/14, 2:41 AM

Forgot to say that when I print the contents of ufile, I returns a dictionary with a single pair FileStorage: u'tula.gif' ('image/gif') , this is the last picture I sent, and analyzing the request indeed, the web client sends all pictures, but the controller only receives the last, it seems like they just dismiss all previous images ....

Open IT Marcin Kieszek, Marcin Kieszek Poland
9/23/14, 4:32 AM

Have you found a solution? I'm also interested in that case.

9/23/14, 9:11 AM
which case?
I have several post's
El 23/09/14 04:32, Bajkar escribió:
<blockquote cite="mid:1411461174.535656929016113.921812722042857-openerp-55718-forum.post@accounts.odoo.com" type="cite">

Have you found a solution? I'm also interested in that case.

--
Bajkar
Sent by OpenERP S.A. using Odoo about Forum Post False
Vicious Paraguay
9/23/14, 9:19 AM

Excuse me, answered from the email, I found a way to make it work, but modifying the core code

David Myers France
10/27/14, 7:23 AM

@Vicious : I like what you are attempting to do here. However I think another potential idea for the process is as follows: link out to an ftp system, and use that to import the files. Obviously you'll need to enable the storage of files on disk rather than in the database. The improvement that I would like to see is to load in multiple image files into a galery in one hit. If I want to enable a gallery with a lot of images I have to spend a lot of time selecting them... which really agravates me, as my local pc is rather old!

Vicious Paraguay
10/27/14, 9:39 AM

@David Myers I already have it running a gallery, using a multiple charger taking the "multiple" property in html, what you say is completely valid, however my clients are very basic users, for each case, taking pictures with they digital camera, then create a folder on the PC, move all the photos to that folder, and the camera stays empty for the next occasion, then the in the Odoo, to get you out the window to select files for all the selected (Ctrl + E) folder . Yes to upload the photos they had to host them on an FTP, copy the link text and copy and paste these links into a box, I would look like a fool. No posting the solution because from the moment we need to modify some of the core Odoo is not a valid option for everyone, and it's not doing anything fancy. However, OpenERP 7 runs well, need to modify 4 lines, and Odoo 8 also to modify a single line ... the most curious is that the lines change to work on OpenERP 7 are now part of the core of Odoo 8 out the box.

sameer alhwety Jordan
7/21/15, 10:15 AM

@Vicious : can you mention the line in Odoo to make the binary field takes more than file ?

1
AbdelAli MERZOUGUI France
6/10/15, 9:37 AM

I've looking for the same functionality, and i inspired from 'Vicious' answer about werkzeug accepting just one file at once, 

In fact, my goal was uploading different images on product profile, since i could not upload but one file at the time, I suited the next procedure:

1- put images in a zip file

2- upload the zip file 

3- get images in memory

4- create images 

That's it, 

Hope that could help you guys

0
tansadio France
7/21/15, 4:35 AM

Hi, I have this error when i upload a image:

image_data = upload.read()

AttributeError: 'unicode' object has no attribute 'read'

When i call my controllers:

The variable request.params['upload'] contains " <FileStorage: u'ir_attachment_117.jpeg' ('image/jpeg')>", 

I want update field product.template image with this image ir_attachment_117.jpeg. 

I need your HELP!

3 Comments
Vicious Paraguay
7/22/15, 10:13 AM

I post a new anwser!

Vicious Paraguay
7/22/15, 10:13 AM

I post a new anwser!

tansadio France
7/23/15, 3:22 AM

Thanks for your answer!

0
yuri Germany
6/27/15, 1:48 PM

Vicious, would you like to share the solution even if modify the core I don't mind.

1 Comment
Vicious Paraguay
7/22/15, 10:14 AM

i post a new anwser

Ask a Question
Writer
Keep Informed
2 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now