From 33aa27dbb30b4dfba9cf7f4d50c70ed6667091fe Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Sun, 3 Jan 2010 15:08:11 +0100 Subject: [PATCH 1/7] [imp] replace hasattr-based conditionals by getattrs bzr revid: xmo@tinyerp.com-20100103140811-0xnljbidnvomstg0 --- bin/netsvc.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/bin/netsvc.py b/bin/netsvc.py index 91630563452..e0e97efe28d 100644 --- a/bin/netsvc.py +++ b/bin/netsvc.py @@ -364,10 +364,7 @@ class OpenERPDispatcher: self.log('service', service_name) self.log('method', method) self.log('params', params) - if hasattr(self,'auth_provider'): - auth = self.auth_provider - else: - auth = None + auth = getattr(self, 'auth_provider', None) result = ExportService.getService(service_name).dispatch(method, auth, params) self.log('result', result) # We shouldn't marshall None, @@ -376,10 +373,7 @@ class OpenERPDispatcher: return result except Exception, e: self.log('exception', tools.exception_to_unicode(e)) - if hasattr(e, 'traceback'): - tb = e.traceback - else: - tb = sys.exc_info() + tb = getattr(e, 'traceback', sys.exc_info()) tb_s = "".join(traceback.format_exception(*tb)) if tools.config['debug_mode']: import pdb From 9ff92fa5e10e71e4f34814377e6ff9f1626e9f8f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Sun, 3 Jan 2010 15:10:21 +0100 Subject: [PATCH 2/7] [imp] replace hasattr-base attribute selection by getattrs bzr revid: xmo@tinyerp.com-20100103141021-61pmlw1iom392xaq --- bin/osv/osv.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/osv/osv.py b/bin/osv/osv.py index 5b2e4ee8da8..8fb5afae8b1 100644 --- a/bin/osv/osv.py +++ b/bin/osv/osv.py @@ -195,8 +195,8 @@ class osv_memory(osv_base, orm.orm_memory): # put objects in the pool var # def createInstance(cls, pool, module, cr): - name = hasattr(cls, '_name') and cls._name or cls._inherit - parent_names = hasattr(cls, '_inherit') and cls._inherit + name = getattr(cls, '_name', cls._inherit) + parent_names = getattr(cls, '_inherit', None) if parent_names: for parent_name in ((type(parent_names)==list) and parent_names or [parent_names]): parent_class = pool.get(parent_name).__class__ @@ -209,7 +209,7 @@ class osv_memory(osv_base, orm.orm_memory): else: new.extend(cls.__dict__.get(s, [])) nattr[s] = new - name = hasattr(cls, '_name') and cls._name or cls._inherit + name = getattr(cls, '_name', cls._inherit) cls = type(name, (cls, parent_class), nattr) obj = object.__new__(cls) @@ -223,7 +223,7 @@ class osv(osv_base, orm.orm): # put objects in the pool var # def createInstance(cls, pool, module, cr): - parent_names = hasattr(cls, '_inherit') and cls._inherit + parent_names = getattr(cls, '_inherit', None) if parent_names: for parent_name in ((type(parent_names)==list) and parent_names or [parent_names]): parent_class = pool.get(parent_name).__class__ @@ -247,7 +247,7 @@ class osv(osv_base, orm.orm): else: new.extend(cls.__dict__.get(s, [])) nattr[s] = new - name = hasattr(cls, '_name') and cls._name or cls._inherit + name = getattr(cls, '_name', cls._inherit) cls = type(name, (cls, parent_class), nattr) obj = object.__new__(cls) obj.__init__(pool, cr) From eca47ce8b65fb2e3bc857f81fa7cb32b301fcf61 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Sun, 3 Jan 2010 15:14:57 +0100 Subject: [PATCH 3/7] [imp] replace hasattr usages with getattr in socket shutdowns bzr revid: xmo@tinyerp.com-20100103141457-uff2ss505npnkoti --- bin/service/http_server.py | 2 +- bin/service/netrpc_server.py | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/service/http_server.py b/bin/service/http_server.py index 72dd787533c..2f608a56b95 100644 --- a/bin/service/http_server.py +++ b/bin/service/http_server.py @@ -137,7 +137,7 @@ class BaseHttpDaemon(threading.Thread, netsvc.Server): if os.name != 'nt': try: self.server.socket.shutdown( - hasattr(socket, 'SHUT_RDWR') and socket.SHUT_RDWR or 2) + getattr(socket, 'SHUT_RDWR', 2) except socket.error, e: if e.errno != 57: raise # OSX, socket shutdowns both sides if any side closes it diff --git a/bin/service/netrpc_server.py b/bin/service/netrpc_server.py index 50e9b5e7a9b..6260ec3d0e5 100644 --- a/bin/service/netrpc_server.py +++ b/bin/service/netrpc_server.py @@ -42,10 +42,8 @@ class TinySocketClientThread(threading.Thread, netsvc.OpenERPDispatcher): def __del__(self): if self.sock: try: - if hasattr(socket, 'SHUT_RDWR'): - self.socket.shutdown(socket.SHUT_RDWR) - else: - self.socket.shutdown(2) + self.socket.shutdown( + getattr(socket, 'SHUT_RDWR', 2)) except: pass # That should garbage-collect and close it, too self.sock = None @@ -131,10 +129,8 @@ class TinySocketServerThread(threading.Thread,netsvc.Server): for t in self.threads: t.stop() try: - if hasattr(socket, 'SHUT_RDWR'): - self.socket.shutdown(socket.SHUT_RDWR) - else: - self.socket.shutdown(2) + self.socket.shutdown( + getattr(socket, 'SHUT_RDWR', 2)) self.socket.close() except: return False From c700465241251b7978165215d81dc263b3798403 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Sun, 3 Jan 2010 15:20:05 +0100 Subject: [PATCH 4/7] [imp] replace hasattr-based attribute selection by getattr bzr revid: xmo@tinyerp.com-20100103142005-ehlvac2owxjtin1x --- bin/report/report_sxw.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/report/report_sxw.py b/bin/report/report_sxw.py index a03f8b4ba26..be1fdd1bdec 100644 --- a/bin/report/report_sxw.py +++ b/bin/report/report_sxw.py @@ -85,7 +85,7 @@ class _float_format(float, _format): def __str__(self): digits = 2 - if hasattr(self,'_field') and hasattr(self._field, 'digits') and self._field.digits: + if hasattr(self,'_field') and getattr(self._field, 'digits', None): digits = self._field.digits[1] if hasattr(self, 'lang_obj'): return self.lang_obj.format('%.' + str(digits) + 'f', self.name, True) @@ -108,7 +108,7 @@ class _date_format(str, _format): def __str__(self): if self.val: - if hasattr(self,'name') and (self.name): + if getattr(self,'name', None): date = mx.DateTime.strptime(self.name,DT_FORMAT) return date.strftime(self.lang_obj.date_format) return self.val @@ -120,7 +120,7 @@ class _dttime_format(str, _format): def __str__(self): if self.val: - if hasattr(self,'name') and self.name: + if getattr(self,'name', None): datetime = mx.DateTime.strptime(self.name,DHM_FORMAT) return datetime.strftime(self.lang_obj.date_format+ " " + self.lang_obj.time_format) return self.val From bc9bd1eb3852c2826b25154b60610784215aaf0b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Sun, 3 Jan 2010 15:35:19 +0100 Subject: [PATCH 5/7] [imp] replace hasattr-based attribute selection by getattr bzr revid: xmo@tinyerp.com-20100103143519-90zakma8s7xjlxvv --- bin/osv/orm.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index f1c36026c32..6782cfef79b 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -304,7 +304,7 @@ def get_pg_type(f): elif isinstance(f.selection, list) and isinstance(f.selection[0][0], int): f_size = -1 else: - f_size = (hasattr(f, 'size') and f.size) or 16 + f_size = getattr(f, 'size', 16) if f_size == -1: f_type = ('int4', 'INTEGER') @@ -967,8 +967,7 @@ class orm_template(object): res[f]['readonly'] = True res[f]['states'] = {} for arg in ('digits', 'invisible','filters'): - if hasattr(self._columns[f], arg) \ - and getattr(self._columns[f], arg): + if getattr(self._columns[f], arg, None): res[f][arg] = getattr(self._columns[f], arg) #TODO: optimize @@ -1418,7 +1417,7 @@ class orm_template(object): act_id = int(data_menu.split(',')[1]) if act_id: data_action = self.pool.get('ir.actions.act_window').browse(cr, user, [act_id], context)[0] - result['submenu'] = hasattr(data_action,'menus') and data_action.menus or False + result['submenu'] = getattr(data_action,'menus', False) if toolbar: def clean(x): x = x[2] @@ -1857,7 +1856,7 @@ class orm(orm_template): create = False todo_end = [] self._field_create(cr, context=context) - if not hasattr(self, "_auto") or self._auto: + if getattr(self, '_auto', True): cr.execute("SELECT relname FROM pg_class WHERE relkind in ('r','v') AND relname='%s'" % self._table) if not cr.rowcount: cr.execute("CREATE TABLE \"%s\" (id SERIAL NOT NULL, PRIMARY KEY(id)) WITHOUT OIDS" % self._table) @@ -2002,7 +2001,8 @@ class orm(orm_template): f_pg_type = f_pg_def['typname'] f_pg_size = f_pg_def['size'] f_pg_notnull = f_pg_def['attnotnull'] - if isinstance(f, fields.function) and not f.store and (not hasattr(f,'nodrop') or not f.nodrop): + if isinstance(f, fields.function) and not f.store and\ + not getattr(f, 'nodrop', False): logger.notifyChannel('orm', netsvc.LOG_INFO, 'column %s (%s) in table %s removed: converted to a function !\n' % (k, f.string, self._table)) cr.execute('ALTER TABLE "%s" DROP COLUMN "%s"'% (self._table, k)) cr.commit() @@ -2155,7 +2155,7 @@ class orm(orm_template): if not hasattr(self, '_log_access'): # if not access is not specify, it is the same value as _auto - self._log_access = not hasattr(self, "_auto") or self._auto + self._log_access = getattr(self, "_auto", True) self._columns = self._columns.copy() for store_field in self._columns: From 510d0edff7a99bd059f24aa672d440bb515c0424 Mon Sep 17 00:00:00 2001 From: "ame (Tiny)" Date: Tue, 12 Jan 2010 14:36:28 +0530 Subject: [PATCH 6/7] [IMP] ir.module.web (simple web module management) bzr revid: ame@tinyerp.com-20100112090628-ddwphfzrx340tixm --- bin/addons/base/__terp__.py | 1 + bin/addons/base/module/__init__.py | 1 + bin/addons/base/module/module_web.py | 45 ++++++++++++++++++++++ bin/addons/base/module/module_web_view.xml | 28 ++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 bin/addons/base/module/module_web.py create mode 100644 bin/addons/base/module/module_web_view.xml diff --git a/bin/addons/base/__terp__.py b/bin/addons/base/__terp__.py index 2e42b5a08e3..d273c55a8d4 100644 --- a/bin/addons/base/__terp__.py +++ b/bin/addons/base/__terp__.py @@ -42,6 +42,7 @@ 'ir/workflow/workflow_view.xml', 'module/module_wizard.xml', 'module/module_view.xml', + 'module/module_web_view.xml', 'module/module_data.xml', 'module/module_report.xml', 'res/res_request_view.xml', diff --git a/bin/addons/base/module/__init__.py b/bin/addons/base/module/__init__.py index b07332b81d4..aa775e29c1c 100644 --- a/bin/addons/base/module/__init__.py +++ b/bin/addons/base/module/__init__.py @@ -20,6 +20,7 @@ ############################################################################## import module +import module_web import wizard import report diff --git a/bin/addons/base/module/module_web.py b/bin/addons/base/module/module_web.py new file mode 100644 index 00000000000..ca4463f620e --- /dev/null +++ b/bin/addons/base/module/module_web.py @@ -0,0 +1,45 @@ +from osv import fields, osv, orm + +class module_web(osv.osv): + _name = "ir.module.web" + _description = "Web Module" + + _columns = { + 'name': fields.char("Name", size=128, readonly=True, required=True), + 'description': fields.text("Description", readonly=True, translate=True), + 'author': fields.char("Author", size=128, readonly=True), + 'website': fields.char("Website", size=256, readonly=True), + 'state': fields.selection([ + ('uninstallable','Uninstallable'), + ('uninstalled','Not Installed'), + ('installed','Installed') + ], string='State', readonly=True) + } + + _defaults = { + 'state': lambda *a: 'uninstalled', + } + _order = 'name' + + _sql_constraints = [ + ('name_uniq', 'unique (name)', 'The name of the module must be unique !'), + ] + + def update_module_list(self, cr, uid, modules, context={}): + + for module in modules: + mod_name = module['name'] + ids = self.search(cr, uid, [('name','=',mod_name)]) + if ids: + self.write(cr, uid, ids, module) + else: + self.create(cr, uid, module) + + def button_install(self, cr, uid, ids, context={}): + return self.write(cr, uid, ids, {'state': 'installed'}, context) + + def button_uninstall(self, cr, uid, ids, context={}): + return self.write(cr, uid, ids, {'state': 'uninstalled'}, context) + +module_web() + diff --git a/bin/addons/base/module/module_web_view.xml b/bin/addons/base/module/module_web_view.xml new file mode 100644 index 00000000000..d1348aa89e2 --- /dev/null +++ b/bin/addons/base/module/module_web_view.xml @@ -0,0 +1,28 @@ + + + + + + ir.module.web.tree + ir.module.web + tree + + + + + + +