Handle session and timeout

This commit is contained in:
Cédric Krier committed 2008-03-05 15:10:39 +01:00
1 parent 739e979fd1
commit ded8b23084
7 files changed
+64 -41

No files matched your search

+2 -1
View File
@@ -347,9 +347,10 @@ def ask(question, parent, visibility=True):
response = win.run()
parent.present()
res = entry.get_text()
win.destroy()
if response == gtk.RESPONSE_OK:
return entry.get_text()
return res
else:
return None
+6 -6
View File
@@ -534,9 +534,9 @@ class Main(object):
self.notebook.set_current_page(page - 1)
def sig_user_preferences(self, widget):
win = Preference(rpc.session.user, self.window)
win = Preference(rpc._USER, self.window)
if win.run():
rpc.session.context_reload()
rpc.context_reload()
self.window.present()
return True
@@ -545,28 +545,28 @@ class Main(object):
def sig_request_new(self, widget):
return Window.create(None, 'res.request', False,
[('act_from', '=', rpc.session.user)], 'form',
[('act_from', '=', rpc._USER)], 'form',
mode=['form', 'tree'], window=self.window,
context={'active_test': False})
def sig_request_open(self, widget):
ids = self.request_set()[0]
return Window.create(False, 'res.request', ids,
[('act_to', '=', rpc.session.user), ('active', '=', True)],
[('act_to', '=', rpc._USER), ('active', '=', True)],
'form', mode=['tree', 'form'], window=self.window,
context={'active_test': False})
def sig_request_wait(self, widget):
ids = self.request_set()[0]
return Window.create(False, 'res.request', ids,
[('act_from', '=', rpc.session.user),
[('act_from', '=', rpc._USER),
('state', '=', 'waiting'), ('active', '=', True)],
'form', mode=['tree', 'form'], window=self.window,
context={'active_test': False})
def request_set(self):
try:
ids, ids2 = rpc.session.rpc_exec_auth_try('/object', 'execute',
ids, ids2 = rpc.execute('object', 'execute',
'res.request', 'request_get')
if len(ids):
message = _('%s request(s)') % len(ids)
+7 -6
View File
@@ -160,14 +160,15 @@ class Tree(SignalEvent):
def menu_main_clicked(self, widget):
if widget.get_active():
obj_id = widget.get_data('id')
args = ('object', 'execute', self.model,
'read', obj_id, [self.view['field_childs']])
try:
ids = rpc.execute('object', 'execute', self.model,
'read', obj_id, [self.view['field_childs']])\
[self.view['field_childs']]
ids = rpc.execute(*args)[self.view['field_childs']]
except Exception, exception:
rpc.process_exception(exception, self.window)
return False
ids = rpc.process_exception(exception, self.window, *args)\
[self.view['field_childs']]
if not ids:
return False
self.tree_res.ids = ids
self.tree_res.reload()
+3 -2
View File
@@ -92,10 +92,11 @@ class ModelRecord(SignalEvent):
try:
self.id = self.rpc.create(value, self.context_get())
except Exception, exception:
rpc.process_exception(exception, self.window, 'object',
self.id = rpc.process_exception(exception, self.window, 'object',
'execute', self.resource, 'create', value,
self.context_get())
return False
if not self.id:
return False
else:
if not self.is_modified():
return self.id
+6 -5
View File
@@ -53,9 +53,10 @@ class ViewTreeModel(gtk.GenericTreeModel, gtk.TreeSortable):
ctx = {}
ctx.update(rpc.CONTEXT)
ctx.update(self.context)
args = ('object', 'execute', self.view['model'], 'read', ids, fields,
ctx)
try:
res_ids = rpc.execute('object', 'execute',
self.view['model'], 'read', ids, fields, ctx)
res_ids = rpc.execute(*args)
except:
res_ids = []
for obj_id in ids:
@@ -321,9 +322,9 @@ class ViewTree(object):
def reload(self):
del self.model
self.model = ViewTreeModel(self.ids, self.view_info,
self.fields_order, self.fields, context=self.context,
pixbufs=self.pixbufs, treeview=self.view)
self.model = ViewTreeModel(self.ids, self.view_info, self.fields_order,
self.fields, context=self.context, pixbufs=self.pixbufs,
treeview=self.view)
self.view.set_model(self.model)
def widget_get(self):
+6 -5
View File
@@ -27,13 +27,14 @@ class ViewTreeSC(object):
store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING,
gobject.TYPE_STRING)
user = rpc._USER
args = ('object', 'execute', 'ir.ui.view_sc', 'get_sc', user,
self.model, rpc.CONTEXT)
try:
view_sc = rpc.execute('object', 'execute',
'ir.ui.view_sc', 'get_sc', user, self.model,
rpc.CONTEXT)
view_sc = rpc.execute(*args)
except Exception, exception:
rpc.process_exception(exception, self.window)
return
view_sc = rpc.process_exception(exception, self.window, *args)
if not view_sc:
return
for shortcut in view_sc:
num = store.append()
store.set(num, 0, shortcut['res_id'], 1, shortcut['name'],
+34 -16
View File
@@ -9,7 +9,7 @@ import socket
_SOCK = None
_USER = 0
_USERNAME = ''
_PASSWORD = ''
_SESSION = ''
_DATABASE = ''
CONTEXT = {}
_VIEW_CACHE = {}
@@ -27,8 +27,7 @@ def db_list(host, port):
_SOCK.send(('db', 'list'))
res = _SOCK.receive()
return res
except Exception, e:
print e
except:
return None
def db_exec(host, port, method, *args):
@@ -43,14 +42,10 @@ def db_exec(host, port, method, *args):
return res
def login(username, password, host, port, database):
global _SOCK, _USER, _USERNAME, _PASSWORD, _DATABASE, _VIEW_CACHE, SECURE
global _SOCK, _USER, _USERNAME, _SESSION, _DATABASE, _VIEW_CACHE, SECURE
if _SOCK:
_SOCK.disconnect()
_SOCK = None
_USER = 0
_USERNAME = ''
_PASSWORD = ''
_DATABASE = ''
_VIEW_CACHE = {}
SECURE = False
try:
@@ -59,25 +54,33 @@ def login(username, password, host, port, database):
_SOCK.send(('common', 'login', database, username, password))
res = _SOCK.receive()
except socket.error:
_USER = 0
_USERNAME = ''
_SESSION = ''
_DATABASE = ''
return -1
if not res:
_USER = 0
_USERNAME = ''
_SESSION = ''
_DATABASE = ''
return -2
_USER = res
_USER = res[0]
_USERNAME = username
_PASSWORD = password
_SESSION = res[1]
_DATABASE = database
SECURE = _SOCK.ssl
context_reload()
return 1
def logout():
global _SOCK, _USER, _USERNAME, _PASSWORD, _DATABASE, _VIEW_CACHE
global _SOCK, _USER, _USERNAME, _SESSION, _DATABASE, _VIEW_CACHE
if _SOCK:
_SOCK.disconnect()
_SOCK = None
_USER = 0
_USERNAME = ''
_PASSWORD = ''
_SESSION = ''
_DATABASE = ''
_VIEW_CACHE = {}
@@ -107,7 +110,7 @@ def context_reload():
TIMEZONE = execute('common', 'timezone_get')
def execute(obj, method, *args):
global _SOCK
global _SOCK, _DATABASE, _USER, _SESSION
if not _SOCK:
raise Exception('Not logged!')
logging.getLogger('rpc.request').info(str((obj, method, args)))
@@ -118,11 +121,11 @@ def execute(obj, method, *args):
args = args[:]
args = args + (_VIEW_CACHE[key][0],)
try:
_SOCK.send((obj, method, _DATABASE, _USER, _PASSWORD) + args)
_SOCK.send((obj, method, _DATABASE, _USER, _SESSION) + args)
result = _SOCK.receive()
except socket.error:
_SOCK.reconnect()
_SOCK.send((obj, method, _DATABASE, _USER, _PASSWORD) + args)
_SOCK.send((obj, method, _DATABASE, _USER, _SESSION) + args)
result = _SOCK.receive()
if key:
if result is True and key in _VIEW_CACHE:
@@ -132,7 +135,22 @@ def execute(obj, method, *args):
return result
def process_exception(exception, parent, obj='', method='', *args):
global _USERNAME, _DATABASE
global _USERNAME, _DATABASE, _SOCK
if str(exception.args[0]) == 'NotLogged':
while True:
password = common.ask(_('Password:'), parent, visibility=False)
if password is None:
break
res = login(_USERNAME, password, _SOCK.host, _SOCK.port, _DATABASE)
if res < 0:
continue
if obj and method:
try:
return execute(obj, method, *args)
except Exception, exception:
return process_exception(exception, parent, obj,
method, *args)
return
type = 'error'
data = str(exception.args[0])
description = data