← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-client-web/6.0-opw-4009-al into lp:openobject-client-web/6.0

 

Antony Lesuisse has proposed merging lp:~openerp-dev/openobject-client-web/6.0-opw-4009-al into lp:openobject-client-web/6.0.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-client-web/6.0-opw-4009-al/+merge/50846

Fix for binary fields updates. OPW ticket 4009.

The filename change is implemented by an javascript onchange that takes the value of the filename from the input type file and sets an input type text. This is not fixed yet.

-- 
https://code.launchpad.net/~openerp-dev/openobject-client-web/6.0-opw-4009-al/+merge/50846
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-client-web/6.0-opw-4009-al.
=== modified file 'addons/openerp/static/javascript/binary.js'
--- addons/openerp/static/javascript/binary.js	2011-01-17 11:57:11 +0000
+++ addons/openerp/static/javascript/binary.js	2011-02-23 01:13:55 +0000
@@ -18,28 +18,8 @@
 // You can see the MPL licence at: http://www.mozilla.org/MPL/MPL-1.1.html
 //
 ////////////////////////////////////////////////////////////////////////////////
-
-function save_binary_data(src, filename) {
-
-    var name = openobject.dom.get(src) ? openobject.dom.get(src).name : src;
-
-    var prefix = name.split('/');
-    name = prefix.pop();
-    prefix = prefix.join('/');
-    prefix = prefix ? prefix + '/' : '';
-
-    var fname = openobject.dom.get(prefix + filename) || openobject.dom.get(prefix + 'name');
-
-    fname = fname ? fname.value || fname.innerHTML : null;
-
-    var act = get_form_action('save_binary_data', undefined);
-    act = fname ? act + '/' + fname : act;
-
-    submit_form(openobject.http.getURL(act, {
-        _terp_field: name,
-        _terp_model: openobject.dom.get(prefix + '_terp_model').value,
-        _terp_id: openobject.dom.get(prefix + '_terp_id').value
-    }), undefined, '_blank');
+function save_binary_data(src) {
+    submit_form(src, undefined, '_blank');
 }
 
 function clear_binary_data(src, filename) {

=== modified file 'addons/openerp/widgets/form/_binary.py'
--- addons/openerp/widgets/form/_binary.py	2011-01-20 19:05:31 +0000
+++ addons/openerp/widgets/form/_binary.py	2011-02-23 01:13:55 +0000
@@ -19,7 +19,7 @@
 #
 ###############################################################################
 
-import random, time
+import os, random
 
 from openobject import tools
 from openerp import utils
@@ -37,32 +37,35 @@
 
 __all__ = ["Binary", "Image"]
 
-
 class Binary(TinyInputWidget):
     template = "/openerp/widgets/form/templates/binary.mako"
-    params = ["name", "text", "readonly", "filename", "bin_data", 'value_bin_size']
+    params = ["name", "src", "text", "readonly", "filename", "filename_value", "model", "id", "field"]
 
+    src = ""
     text = None
     file_upload = True
 
     def __init__(self, **attrs):
         super(Binary, self).__init__(**attrs)
+        print dir(self)
+        self.field = self.name.split('/')[-1]
         self.validator = validators.Binary()
+        self.bin_data = attrs.get('value')
         self.onchange = "set_binary_filename(this, '%s');" % (self.filename or '')
-        self.bin_data = attrs.get('value')
-        # if bin_size was in context when reading the binary field, then the field's value is actually the binary
-        # field's content size
+        self.filename_value = self.filename_value or 'file.dat'
+        # if bin_size was in context when reading the binary field, then the field's value is actually the binary field's content size
         self.value_bin_size = getattr(self, 'context', {}).get('bin_size', False)
 
+        self.src = tools.url('/openerp/form/save_binary_data/%s'%os.path.basename(self.filename_value.replace('\\','/')), _terp_field=self.field, _terp_model=self.model, _terp_id=self.id)
+
     def set_value(self, value):
-        #XXX: server bug work-arround
         if self.value_bin_size:
             self.text = value
-            return
-        try:
-            self.text = utils.get_size(value)
-        except:
-            self.text = value or ''
+        else:
+            try:
+                self.text = utils.get_size(value)
+            except:
+                self.text = ''
 
 register_widget(Binary, ["binary"])
 

=== modified file 'addons/openerp/widgets/form/_form.py'
--- addons/openerp/widgets/form/_form.py	2011-01-28 15:21:15 +0000
+++ addons/openerp/widgets/form/_form.py	2011-02-23 01:13:55 +0000
@@ -905,7 +905,7 @@
 
                 self.view_fields.append(name)
 
-                field = self._make_field_widget(fields[name], values.get(name))
+                field = self._make_field_widget(fields[name], values.get(name), values)
                 views.append(field)
 
             elif node.localName=='hpaned':
@@ -942,7 +942,7 @@
 
         return views
 
-    def _make_field_widget(self, attrs, value=False):
+    def _make_field_widget(self, attrs, value=False, values={}):
 
         attrs['editable'] = self.editable
         if not attrs['type'] == 'many2one':
@@ -964,8 +964,10 @@
         name = attrs['name']
         kind = attrs.get('type', 'char')
 
-        if kind == 'image' or kind == 'picture':
+        if kind == 'image' or kind == 'picture' or attrs['type'] == 'binary':
             attrs['id'] = self.id
+        if attrs.get('filename'):
+            attrs['filename_value']=values.get(attrs['filename'])
 
         # suppress by container's readonly property
         if self.readonly:

=== modified file 'addons/openerp/widgets/form/templates/binary.mako'
--- addons/openerp/widgets/form/templates/binary.mako	2010-11-15 12:50:28 +0000
+++ addons/openerp/widgets/form/templates/binary.mako	2011-02-23 01:13:55 +0000
@@ -1,38 +1,12 @@
 <div>
-    % if bin_data and not value_bin_size:
-        <input
-            type="hidden"
-            class="${css_class}"
-            kind="${kind}"
-            id="${name}"
-            name="${name}"
-            value="${bin_data}"/>
-    % endif
     <div id="${name}_binary_add" style="display: none;">
-        % if editable and not readonly:
-        <input ${py.attrs(attrs)}
-            type="file"
-            class="${css_class}"
-            kind="${kind}"
-            disabled="disabled"
-            id="${name}"
-            name="${name}"/>
-        % endif
+        <input type="file" disabled="disabled" id="${name}" name="${name}"/>
     </div>
     <div id="${name}_binary_buttons" class="binary_buttons">
-        <input type="text" value="${value or text or ''}" readonly="readonly"/>
-        %if value or text:
-        	<input type="hidden" name="${name}" value="${value or text}"></input>
-       	% endif
-        % if text:
-        <a class="button-a" href="javascript: void(0)" onclick="save_binary_data('${name}', '${filename}')">${_("Save As")}</a>
-        % endif
+        <input type="text" value="${text}" readonly="readonly" disabled="disabled"/>
+        <a class="button-a" href="javascript: void(0)" onclick="save_binary_data('${src}')">${_("Save As")}</a>
         % if editable and not readonly:
-        <a class="button-a" href="javascript: void(0)" onclick="add_binary('${name}')">${_("add attachment")}</a>
+            <a class="button-a" href="javascript: void(0)" onclick="add_binary('${name}')">${_("Set file")}</a>
         % endif
     </div>
-    % if editable and error:
-    <span class="fielderror">${error}</span>
-    % endif
 </div>
-


Follow ups