Default value for binary field doesn't displayed in image widget

Bug #504451 reported by Kontaxis Panagiotis
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Status tracked in Trunk
5.0
Fix Released
Medium
Unassigned
Trunk
Fix Released
Undecided
Unassigned

Bug Description

I 'm trying to apply a default value (an image file) to a binary field but it doens't displayed on binary and image widget in object's view.

In particular:
1) I set the default value of binary field on the model:
class patient_curves (osv.osv):
 def _get_diag(self, cr, uid, context):
     content_of_image=..................
     return content_of_image
 _defaults = {
   'height05': _get_diag,
   }
 _name = "med.patient.curves"
 _columns = {
   'height05' : fields.binary('height05'),
  }
patient_curves()

2) In the view, when I'm trying to display the default content of the binary field inside a text widget
 <field name="height05" widget="text"/>
I can see the content of the image (in characters)
BUT
when I'm trying to display the default content of the binary field inside a binary or image widget
 <field name="height05" widget="image"/> or
 <field name="height05"/>
I can't see the the image (or the file). The image of binary widgets have no content.

(Note that image is successfully displayed when it is generated inside a functional field)

Related branches

tags: added: default image widget
tags: added: defaults
removed: default
Revision history for this message
Borja López Soilán (NeoPolus) (borjals) wrote :

Are you encoding the file in base 64 before returning it in _get_diag?

I mean, something like:

image_buffer = cStringIO.StringIO()
# .......write something into the image_buffer file-like object........
data = encodestring(image_buffer.getvalue())
return data

Revision history for this message
Kontaxis Panagiotis (pkontaxis) wrote :

Sure.

my code (image generation using matplotlib):

import StringIO
img=StringIO.StringIO()
canvas.print_figure(img, dpi=150, format="png")
import base64
encoded_data = base64.encodestring(img.getvalue())
return encoded_data

I tried the above code inside a functional field and the image is displayed successfully.

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hi Kontaxis,

It has been fixed in the trunk version,
Thanks.

Changed in openobject-server:
milestone: none → 6.0
status: New → Fix Released
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

It has been fixed by revision 1085 <email address hidden>.
Thanks.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.