diff --git a/tryton/gui/window/view_form/view/form_gtk/binary.py b/tryton/gui/window/view_form/view/form_gtk/binary.py index 4683caef5a..26f704a722 100644 --- a/tryton/gui/window/view_form/view/form_gtk/binary.py +++ b/tryton/gui/window/view_form/view/form_gtk/binary.py @@ -133,7 +133,10 @@ class Binary(WidgetInterface): filename = ''.join([slugify(root), os.extsep, slugify(ext)]) file_path = os.path.join(dtemp, filename) with open(file_path, 'wb') as fp: - fp.write(self.field.get_data(self.record)) + if hasattr(self.field, 'get_data'): + fp.write(self.field.get_data(self.record)) + else: + fp.write(self.field.get(self.record)) root, type_ = os.path.splitext(filename) if type_: type_ = type_[1:] @@ -148,7 +151,10 @@ class Binary(WidgetInterface): action=gtk.FILE_CHOOSER_ACTION_SAVE) if filename: with open(filename, 'wb') as fp: - fp.write(self.field.get_data(self.record)) + if hasattr(self.field, 'get_data'): + fp.write(self.field.get_data(self.record)) + else: + fp.write(self.field.get(self.record)) def sig_remove(self, widget=None): self.field.set_client(self.record, False) @@ -178,10 +184,14 @@ class Binary(WidgetInterface): return False if self.wid_text: self.wid_text.set_text(self.filename_field.get(record) or '') - self.wid_size.set_text(common.humanize(field.get_size(record) or 0)) + if hasattr(field, 'get_size'): + size = field.get_size(record) + else: + size = len(field.get(record)) + self.wid_size.set_text(common.humanize(size or 0)) if self.but_open: - self.but_open.set_sensitive(bool(field.get_size(record))) - self.but_save_as.set_sensitive(bool(field.get_size(record))) + self.but_open.set_sensitive(bool(size)) + self.but_save_as.set_sensitive(bool(size)) return True def set_value(self, record, field): diff --git a/tryton/gui/window/view_form/view/list_gtk/parser.py b/tryton/gui/window/view_form/view/list_gtk/parser.py index a7e3f9957a..f3848cf8ac 100644 --- a/tryton/gui/window/view_form/view/list_gtk/parser.py +++ b/tryton/gui/window/view_form/view/list_gtk/parser.py @@ -619,8 +619,10 @@ class Binary(Char): def setter(self, column, cell, store, iter): record = store.get_value(iter, 0) field = record[self.field_name] - - size = record[self.field_name].get_size(record) + if hasattr(field, 'get_size'): + size = field.get_size(record) + else: + size = len(field.get(record)) cell.set_property('size', common.humanize(size) if size else '') states = ('invisible',) @@ -665,7 +667,10 @@ class Binary(Char): filename = ''.join([slugify(root), os.extsep, slugify(ext)]) file_path = os.path.join(dtemp, filename) with open(file_path, 'wb') as fp: - fp.write(field.get_data(record)) + if hasattr(field, 'get_data'): + fp.write(field.get_data(record)) + else: + fp.write(field.get(record)) root, type_ = os.path.splitext(filename) if type_: type_ = type_[1:] @@ -682,7 +687,10 @@ class Binary(Char): action=gtk.FILE_CHOOSER_ACTION_SAVE) if filename: with open(filename, 'wb') as fp: - fp.write(field.get_data(record)) + if hasattr(field, 'get_data'): + fp.write(field.get_data(record)) + else: + fp.write(field.get(record)) def clear_binary(self, renderer, path): record, field = self._get_record_field(path)