openerp - How to Upload image in Website odoo? -
i working on hr_recruitment module.i have added binary image field hr->application.i trying add functionality external user fill job application them self through website.i have added name,email,phone,resume attachment fields in website job application.when click on submit, updating in hr->job application form.but image field not getting updated in application.when opening job application showing message "could not show selected image".how solve issue?
controller/main.py
if post.get('image',false): image = request.registry['ir.attachment'] name = post.get('image').filename file = post.get('image') attach = file.stream file.show() f = attach.getvalue() webbrowser.open(image) attachment_id = attachments.create(request.cr, request.uid, { 'name': image, 'res_name': image, 'res_model': 'hr.applicant', 'res_id': applicant_id, 'datas': base64.decodestring(str(res[0])), 'datas_fname': post['image'].filename, }, request.context) views/templates.xml <div t-attf-class="form-group"> <label class="col-md-3 col-sm-4 control-label" for="image">image</label> <div class="col-md-7 col-sm-8"> <img id="uploadpreview" style="width: 100px; height: 100px;" /> <input id="uploadimage" name="image" type="file" class="file" multiple="true" data-show-upload="true" data-show-caption="true" data-show-preview="true" onchange="previewimage();"/> </div> </div>
add image field shown below in xml template:
<img itemprop="image" style="margin-top: -53px; margin-left:19px; width:80px;" class="img img-responsive" t-att-src="website.image_url(partner, 'image', none if product_image_big else '300x300')"/> <input class="input-file profilechooser" id="fileinput" type="file" name="ufile" onchange="validateprofileimg();"/>
remove unnecessary attributes you.
and in controller function, can value image fields as:
vals = {} if post['ufile']: vals.update({'image': base64.encodestring(post['ufile'].read())}) request.registry['res.partner'].write(cr, uid, [partner_id], vals)
the above code works me, have been using update partner images odoo website.
Comments
Post a Comment