Reviewers: ,


Please review this at http://codereview.tryton.org/107001/

Affected files:
  M tryton/gui/window/form.py
  M tryton/rpc.py


Index: tryton/gui/window/form.py
===================================================================
--- a/tryton/gui/window/form.py
+++ b/tryton/gui/window/form.py
@@ -33,7 +33,6 @@
 class Form(SignalEvent, TabContent):
     "Form"

-    _toolbar_cache = {}
     toolbar_def = [
         ('new', 'tryton-new', _('New'), _('Create a new record'),
             'sig_new'),
@@ -150,18 +149,16 @@
             gobject.timeout_add(int(auto_refresh) * 1000, self.sig_reload)

     def get_toolbars(self):
-        if self.model not in self._toolbar_cache:
-            ctx = {}
-            ctx.update(rpc.CONTEXT)
-            ctx.update(self.context)
-            args = ('model', self.model, 'view_toolbar_get', ctx)
-            try:
-                toolbars = rpc.execute(*args)
-            except TrytonServerError, exception:
-                toolbars = common.process_exception(exception, *args)
-                toolbars = toolbars if toolbars else {}
-            self._toolbar_cache[self.model] = toolbars
-        return self._toolbar_cache[self.model]
+        ctx = {}
+        ctx.update(rpc.CONTEXT)
+        ctx.update(self.context)
+        args = ('model', self.model, 'view_toolbar_get', ctx)
+        try:
+            toolbars = rpc.execute(*args)
+        except TrytonServerError, exception:
+            toolbars = common.process_exception(exception, *args)
+            toolbars = toolbars if toolbars else {}
+        return toolbars

     def widget_get(self):
         return self.screen.widget
Index: tryton/rpc.py
===================================================================
--- a/tryton/rpc.py
+++ b/tryton/rpc.py
@@ -21,6 +21,7 @@
 _DATABASE = ''
 CONTEXT = {}
 _VIEW_CACHE = {}
+_TOOLBAR_CACHE = {}
 TIMEZONE = 'utc'
 _SEMAPHORE = Semaphore()
 _CA_CERTS = os.path.join(get_config_dir(), 'ca_certs')
@@ -66,7 +67,9 @@

 def login(username, password, host, port, database):
global CONNECTION, _USER, _USERNAME, _SESSION, _HOST, _PORT, _DATABASE, _VIEW_CACHE
+    global _TOOLBAR_CACHE
     _VIEW_CACHE = {}
+    _TOOLBAR_CACHE = {}
     try:
         _SEMAPHORE.acquire()
         try:
@@ -102,6 +105,7 @@

 def logout():
global CONNECTION, _USER, _USERNAME, _SESSION, _HOST, _PORT, _DATABASE, _VIEW_CACHE
+    global _TOOLBAR_CACHE
     if IPCServer.instance:
         IPCServer.instance.stop()
     if CONNECTION is not None:
@@ -123,6 +127,7 @@
     _PORT = None
     _DATABASE = ''
     _VIEW_CACHE = {}
+    _TOOLBAR_CACHE = {}

 def context_reload():
     global CONTEXT, TIMEZONE, _HOST, _PORT
@@ -146,7 +151,8 @@
     if CONNECTION is None:
         raise TrytonServerError('NotLogged')
     key = False
-    if args[2] == 'fields_view_get':
+    method = args[2]
+    if method == 'fields_view_get':
         args, ctx = args[:-1], args[-1]
         # Make sure all the arguments are present
         args = tuple(arg if arg is not None else default
@@ -158,6 +164,10 @@
             args += (_VIEW_CACHE[key][0], ctx)
         else:
             args += (ctx,)
+    elif method == 'view_toolbar_get':
+        key = str(args)
+        if key in _TOOLBAR_CACHE:
+            return _TOOLBAR_CACHE[key]
     res = _SEMAPHORE.acquire(blocking)
     if not res:
         return
@@ -168,11 +178,13 @@
         result = getattr(CONNECTION, name)(*args)
     finally:
         _SEMAPHORE.release()
-    if key:
+    if key and method == 'fields_view_get':
         if result is True and key in _VIEW_CACHE:
             result = _VIEW_CACHE[key][1]
         else:
             _VIEW_CACHE[key] = (result['md5'], result)
+    elif key and method == 'view_toolbar_get':
+        _TOOLBAR_CACHE[key] = result
     logging.getLogger('rpc.result').debug(repr(result))
     return result



--
tryton-dev@googlegroups.com mailing list

Reply via email to