From 02104cd18b57722a3b3a25d7b4cc36b363481da7 Mon Sep 17 00:00:00 2001 From: Jay Vora Date: Tue, 16 Sep 2008 13:01:23 +0530 Subject: [PATCH] Added filtered file selection feature on binary field.Usage: fields.binary('Upload a file',filters=['*.zip','a*.jpg','*.doc']) bzr revid: jvo@tinyerp.com-20080916073123-xjbylq32uci2yr2d --- bin/osv/fields.py | 10 +++++++--- bin/osv/orm.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/osv/fields.py b/bin/osv/fields.py index 2aaa516f572..5c15f5461a9 100644 --- a/bin/osv/fields.py +++ b/bin/osv/fields.py @@ -204,7 +204,11 @@ class binary(_column): _symbol_set = (_symbol_c, _symbol_f) _classic_read = False - + + def __init__(self, string='unknown', filters=None, **args): + _column.__init__(self, string=string, **args) + self.filters = filters + def get_memory(self, cr, obj, ids, name, user=None, context=None, values=None): if not context: context = {} @@ -220,7 +224,7 @@ class binary(_column): break res.setdefault(i, val) if context.get('get_binary_size', True): - res[i] = tools.human_size(val) + res[i] = tools.human_size(val) return res @@ -615,7 +619,7 @@ class function(_column): res = self._fnct(obj, cr, user, ids, name, self._arg, context) else: res = self._fnct(cr, obj._table, ids, name, self._arg, context) - + if self._type == 'binary' and context.get('get_binary_size', False): # convert the data returned by the function with the size of that data... res = dict(map(lambda (x, y): (x, tools.human_size(len(y))), res.items())) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index b935c05cc16..783b5899ba7 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -686,7 +686,7 @@ class orm_template(object): if not read_access: res[f]['readonly'] = True res[f]['states'] = {} - for arg in ('digits', 'invisible'): + for arg in ('digits', 'invisible','filters'): if hasattr(self._columns[f], arg) \ and getattr(self._columns[f], arg): res[f][arg] = getattr(self._columns[f], arg)