From 14ab2d452c192480a4b8925b2de705d4f20be32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 30 May 2008 09:57:12 +0200 Subject: [PATCH] Remove gtk from rpc.py for issue43 --- tryton/action/main.py | 13 +-- tryton/common/common.py | 68 ++++++++++++++++ tryton/gui/main.py | 4 + tryton/gui/window/attachment.py | 20 ++--- tryton/gui/window/board.py | 3 +- tryton/gui/window/form.py | 5 +- tryton/gui/window/preference.py | 7 +- tryton/gui/window/tree.py | 16 ++-- tryton/gui/window/view_board/action.py | 11 +-- tryton/gui/window/view_form/model/group.py | 9 ++- tryton/gui/window/view_form/model/record.py | 15 ++-- tryton/gui/window/view_form/screen/screen.py | 11 +-- .../view_form/view/form_gtk/interface.py | 3 +- .../view_form/view/form_gtk/many2many.py | 3 +- .../view_form/view/form_gtk/many2one.py | 14 ++-- .../window/view_form/view/form_gtk/parser.py | 14 ++-- .../view_form/view/form_gtk/reference.py | 9 ++- .../view_form/view/form_gtk/selection.py | 5 +- tryton/gui/window/view_form/view/list.py | 3 +- .../window/view_form/view/list_gtk/parser.py | 15 ++-- .../view_form/widget_search/reference.py | 5 +- .../view_form/widget_search/selection.py | 5 +- tryton/gui/window/view_tree/view_tree.py | 3 +- tryton/gui/window/view_tree/view_tree_sc.py | 3 +- tryton/gui/window/win_export.py | 12 +-- tryton/gui/window/win_import.py | 4 +- tryton/gui/window/win_search.py | 5 +- tryton/rpc.py | 80 ------------------- tryton/translate.py | 6 ++ tryton/wizard/main.py | 4 +- 30 files changed, 196 insertions(+), 179 deletions(-) diff --git a/tryton/action/main.py b/tryton/action/main.py index 8f8f7a4a83..323af0ab30 100644 --- a/tryton/action/main.py +++ b/tryton/action/main.py @@ -9,6 +9,7 @@ import tempfile import base64 import os import webbrowser +import tryton.common as common _ = gettext.gettext @@ -27,7 +28,7 @@ class Action(object): ids = rpc.execute('object', 'execute', datas['model'], 'search', []) except Exception, exception: - ids = rpc.process_exception(exception, Main.get_main().window, + ids = common.process_exception(exception, Main.get_main().window, 'object', 'execute', datas['model'], 'search', []) if not ids: return False @@ -40,7 +41,7 @@ class Action(object): try: res = rpc.execute('report', 'execute', name, ids, datas, ctx) except Exception, exception: - res = rpc.process_exception(exception, Main.get_main().window, + res = common.process_exception(exception, Main.get_main().window, 'report', 'execute', name, ids, datas, ctx) if not res: return False @@ -67,7 +68,7 @@ class Action(object): res = rpc.execute('object', 'execute', 'ir.action', 'read', act_id, ['type'], ctx) except Exception, exception: - rpc.process_exception(exception, Main.get_main().window) + common.process_exception(exception, Main.get_main().window) return if not res: raise Exception, 'ActionNotFound' @@ -76,13 +77,13 @@ class Action(object): act_id2 = rpc.execute('object', 'execute', action_type, 'search', [('action', '=', act_id)], 0, None, None, ctx)[0] except Exception, exception: - rpc.process_exception(exception, Main.get_main().window) + common.process_exception(exception, Main.get_main().window) return try: res = rpc.execute('object', 'execute', action_type, 'read', act_id2, False, ctx) except Exception, exception: - rpc.process_exception(exception, Main.get_main().window) + common.process_exception(exception, Main.get_main().window) return Action._exec_action(res, datas) @@ -170,7 +171,7 @@ class Action(object): (data['model'], model_id)) except Exception, exception: from tryton.gui import Main - rpc.process_exception(exception, Main.get_main().window) + common.process_exception(exception, Main.get_main().window) return False keyact = {} diff --git a/tryton/common/common.py b/tryton/common/common.py index 2327691cb0..a5d43d3571 100644 --- a/tryton/common/common.py +++ b/tryton/common/common.py @@ -504,6 +504,74 @@ def ask(question, parent, visibility=True): else: return None +def concurrency(resource, obj_id, context, parent): + dia = glade.XML(GLADE, 'dialog_concurrency_exception', gettext.textdomain()) + win = dia.get_widget('dialog_concurrency_exception') + + win.set_transient_for(parent) + win.set_icon(TRYTON_ICON) + + res = win.run() + parent.present() + win.destroy() + + if res == gtk.RESPONSE_OK: + return True + if res == gtk.RESPONSE_APPLY: + from tryton.gui.window import Window + Window.create(False, resource, obj_id, [('id', '=', obj_id)], 'form', + parent, context, ['form', 'tree']) + return False + +def process_exception(exception, parent, obj='', method='', *args): + global _USERNAME, _DATABASE, _SOCK + type = 'error' + if str(exception.args[0]) == 'NotLogged': + type = 'warning' + while True: + password = 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 + data = str(exception.args[0]) + description = data + if len(exception.args) > 1: + details = str(exception.args[1]) + else: + details = data + if hasattr(data, 'split') and ' -- ' in data: + lines = data.split('\n') + type = lines[0].split(' -- ')[0] + description = '' + if len(lines[0].split(' -- ')) > 1: + description = lines[0].split(' -- ')[1] + if len(lines) > 2: + details = '\n'.join(lines[2:]) + if type == 'warning': + if description == 'ConcurrencyException' \ + and len(args) > 4: + if concurrency(args[0], args[2][0], args[4], parent): + if 'read_delta' in args[4]: + del args[4]['read_delta'] + try: + return execute(obj, method, *args) + except Exception, exception: + return process_exception(exception, parent, obj, + method, *args) + else: + warning(details, parent, description) + else: + error(type, parent, details) + def node_attributes(node): result = {} attrs = node.attributes diff --git a/tryton/gui/main.py b/tryton/gui/main.py index 4c47627e16..4c375240be 100644 --- a/tryton/gui/main.py +++ b/tryton/gui/main.py @@ -14,6 +14,7 @@ from tryton.gui.window import Preference from tryton.gui.window import FilesActions import re import base64 +import tryton.translate as translate _ = gettext.gettext @@ -537,6 +538,9 @@ class Main(object): win = Preference(rpc._USER, self.window) if win.run(): rpc.context_reload() + if 'language_direction' in rpc.CONTEXT: + translate.set_language_direction( + rpc.CONTEXT['language_direction']) self.window.present() return True diff --git a/tryton/gui/window/attachment.py b/tryton/gui/window/attachment.py index 1a346c297b..f79ef26e2a 100644 --- a/tryton/gui/window/attachment.py +++ b/tryton/gui/window/attachment.py @@ -40,7 +40,7 @@ class Attachment(object): view = rpc.execute('object', 'execute', 'ir.attachment', 'fields_view_get', False, 'tree') except Exception, exception: - rpc.process_exception(exception, parent) + common.process_exception(exception, parent) raise parse = Parse(view['fields']) @@ -90,7 +90,7 @@ class Attachment(object): try: rpc.execute(*args) except Exception, exception: - rpc.process_exception(exception, self.win, *args) + common.process_exception(exception, self.win, *args) else: common.warning(_('You must put a text comment to an attachement.'), self.win, _('Text not saved!')) @@ -107,7 +107,7 @@ class Attachment(object): rpc.execute('object', 'execute', 'ir.attachment', 'unlink', [int(obj_id)]) except Exception, exception: - rpc.process_exception(exception, self.win, *args) + common.process_exception(exception, self.win, *args) self.reload() def _sig_link(self, widget): @@ -127,7 +127,7 @@ class Attachment(object): try: obj_id = rpc.execute(*args) except Exception, exception: - obj_id = rpc.process_exception(exception, self.win, *args) + obj_id = common.process_exception(exception, self.win, *args) if not obj_id: return self.reload(preview=False) @@ -145,7 +145,7 @@ class Attachment(object): data = rpc.execute('object', 'execute', 'ir.attachment', 'read', int(obj_id)) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) return None if not data: return None @@ -193,7 +193,7 @@ class Attachment(object): try: obj_id = rpc.execute(*args) except Exception, exception: - obj_id = rpc.process_exception(exception, self.win, *args) + obj_id = common.process_exception(exception, self.win, *args) if not obj_id: return self.reload(preview=False) @@ -214,7 +214,7 @@ class Attachment(object): data = rpc.execute('object', 'execute', 'ir.attachment', 'read', int(obj_id)) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) return None if not data: return None @@ -234,7 +234,7 @@ class Attachment(object): data = rpc.execute('object', 'execute', 'ir.attachment', 'read', obj_id) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) return None if not data: return None @@ -296,14 +296,14 @@ class Attachment(object): ('res_id', '=', self.resource[1]), ]) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) return try: res_ids = rpc.execute('object', 'execute', 'ir.attachment', 'read', ids, self.fields_order + ['link']) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) return for res in res_ids: num = self.model.append() diff --git a/tryton/gui/window/board.py b/tryton/gui/window/board.py index 2f6d4bedcb..25604a08dd 100644 --- a/tryton/gui/window/board.py +++ b/tryton/gui/window/board.py @@ -3,6 +3,7 @@ import gtk from tryton.signal_event import SignalEvent import tryton.rpc as rpc from tryton.gui.window.view_board import ViewBoard +import tryton.common as common class Board(SignalEvent): @@ -15,7 +16,7 @@ class Board(SignalEvent): view = rpc.execute('object', 'execute', 'ir.ui.view', 'read', view_id, ['arch'], context) except Exception, exception: - rpc.process_exception(exception, window) + common.process_exception(exception, window) raise self.board = ViewBoard(view['arch'], window, context=context) diff --git a/tryton/gui/window/form.py b/tryton/gui/window/form.py index eca6b39d18..a7f1b7608a 100644 --- a/tryton/gui/window/form.py +++ b/tryton/gui/window/form.py @@ -17,6 +17,7 @@ from tryton.gui.window.win_import import WinImport from tryton.gui.window.attachment import Attachment from tryton.signal_event import SignalEvent from tryton.common import TRYTON_ICON, message, sur, sur_3b +import tryton.common as common _ = gettext.gettext @@ -204,7 +205,7 @@ class Form(SignalEvent): try: res = rpc.execute(*args) except Exception, exception: - res = rpc.process_exception(exception, self.window, *args) + res = common.process_exception(exception, self.window, *args) if not res: return message_str = '' @@ -262,7 +263,7 @@ class Form(SignalEvent): try: new_id = rpc.execute(*args) except Exception, exception: - new_id = rpc.process_exception(exception, self.window, *args) + new_id = common.process_exception(exception, self.window, *args) if new_id: self.screen.load([new_id]) self.message_state(_('Working now on the duplicated document !')) diff --git a/tryton/gui/window/preference.py b/tryton/gui/window/preference.py index a4797be807..66e5242b91 100644 --- a/tryton/gui/window/preference.py +++ b/tryton/gui/window/preference.py @@ -6,6 +6,7 @@ import tryton.rpc as rpc import copy from tryton.gui.window.view_form.screen import Screen from tryton.config import TRYTON_ICON +import tryton.common as common _ = gettext.gettext @@ -33,7 +34,7 @@ class Preference(object): try: res = user.get_preferences_fields_view(rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, parent) + common.process_exception(exception, parent) self.win.destroy() raise arch = res['arch'] @@ -45,7 +46,7 @@ class Preference(object): try: preferences = user.get_preferences(False, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, parent) + common.process_exception(exception, parent) self.win.destroy() raise self.screen.current_model.set(preferences) @@ -70,7 +71,7 @@ class Preference(object): try: user.set_preferences(val, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) break res = True break diff --git a/tryton/gui/window/tree.py b/tryton/gui/window/tree.py index 94b2a0f537..4eaac1e322 100644 --- a/tryton/gui/window/tree.py +++ b/tryton/gui/window/tree.py @@ -30,21 +30,21 @@ class Tree(SignalEvent): 'ir.ui.view', 'read', view_id, ['model', 'type'], context) except Exception, exception: - rpc.process_exception(exception, window) + common.process_exception(exception, window) raise try: view = rpc.execute('object', 'execute', view_base['model'], 'fields_view_get', view_id, view_base['type'],context) except Exception, exception: - rpc.process_exception(exception, window) + common.process_exception(exception, window) raise else: try: view = rpc.execute('object', 'execute', model, 'fields_view_get', False, 'tree', context) except Exception, exception: - rpc.process_exception(exception, window) + common.process_exception(exception, window) raise self.glade = glade.XML(GLADE, 'win_tree_container', @@ -107,7 +107,7 @@ class Tree(SignalEvent): ids = rpc.execute('object', 'execute', self.model, 'search', self.domain2, 0, None, None, self.context) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return if self.tree_res.toolbar: @@ -121,7 +121,7 @@ class Tree(SignalEvent): results = rpc.execute('object', 'execute', self.view['model'], 'read', ids, ['name', icon_name], ctx) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return radiotb = None for res in results: @@ -165,7 +165,7 @@ class Tree(SignalEvent): try: ids = rpc.execute(*args)[self.view['field_childs']] except Exception, exception: - ids = rpc.process_exception(exception, self.window, *args)\ + ids = common.process_exception(exception, self.window, *args)\ [self.view['field_childs']] if not ids: return False @@ -239,7 +239,7 @@ class Tree(SignalEvent): rpc.execute('object', 'execute', 'ir.ui.view_sc', 'unlink', [sc_id]) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) self.tree_sc.update() def sc_add(self, widget): @@ -258,7 +258,7 @@ class Tree(SignalEvent): 'name': name, }) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) self.tree_sc.update() def sc_go(self, widget=None, *args): diff --git a/tryton/gui/window/view_board/action.py b/tryton/gui/window/view_board/action.py index 564a679e67..907b78032f 100644 --- a/tryton/gui/window/view_board/action.py +++ b/tryton/gui/window/view_board/action.py @@ -7,6 +7,7 @@ import datetime from tryton.gui.window.win_search import WinSearch from tryton.action import Action as Action2 from tryton.gui.window.view_tree.view_tree import ViewTree +import tryton.common as common class Action(object): @@ -22,7 +23,7 @@ class Action(object): 'ir.action.act_window', 'read', self.act_id, False, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) raise if self.action.get('views', []): @@ -142,14 +143,14 @@ class Action(object): 'ir.ui.view', 'read', view_ids[0], ['model', 'type'], self.context) except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) raise try: view = rpc.execute('object', 'execute', view_base['model'], 'fields_view_get', view_ids[0], view_base['type'], self.context) except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) raise self.tree = ViewTree(view, [], self._window, True, context=self.context) @@ -180,7 +181,7 @@ class Action(object): 'get_action_id', self.act_id, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) if action_id: Action2.execute(action_id, {}) @@ -209,7 +210,7 @@ class Action(object): self.action['res_model'], 'search', self.domain, 0, self.action.get('limit', 80)) except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) return False if self.screen: self.screen.clear() diff --git a/tryton/gui/window/view_form/model/group.py b/tryton/gui/window/view_form/model/group.py index cfef2cd5d7..a57cb6aed2 100644 --- a/tryton/gui/window/view_form/model/group.py +++ b/tryton/gui/window/view_form/model/group.py @@ -3,6 +3,7 @@ import tryton.rpc as rpc from record import ModelRecord import field from tryton.signal_event import SignalEvent +import tryton.common as common class ModelList(list): @@ -121,7 +122,7 @@ class ModelRecordGroup(SignalEvent): try: res = getattr(self.rpc, self.on_write)(ids, self.context) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False return res @@ -163,7 +164,7 @@ class ModelRecordGroup(SignalEvent): try: values = self.rpc.read(ids[:80], self.fields.keys(), ctx) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False if not values: return False @@ -311,7 +312,7 @@ class ModelRecordGroup(SignalEvent): try: values = self.rpc.read(old, to_add, ctx) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False if values: for value in values: @@ -324,7 +325,7 @@ class ModelRecordGroup(SignalEvent): try: values = self.rpc.default_get(to_add, ctx) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False for field_to_add in to_add: if field_to_add not in values: diff --git a/tryton/gui/window/view_form/model/record.py b/tryton/gui/window/view_form/model/record.py index 70dd658689..4e5f75f4d2 100644 --- a/tryton/gui/window/view_form/model/record.py +++ b/tryton/gui/window/view_form/model/record.py @@ -5,6 +5,7 @@ import tryton.rpc as rpc from tryton.signal_event import SignalEvent import field import datetime +import tryton.common as common class EvalEnvironment(object): @@ -124,7 +125,7 @@ class ModelRecord(SignalEvent): try: self.id = self.rpc.create(value, self.context_get()) except Exception, exception: - self.id = rpc.process_exception(exception, self.window, 'object', + self.id = common.process_exception(exception, self.window, 'object', 'execute', self.resource, 'create', value, self.context_get()) if not self.id: @@ -143,7 +144,7 @@ class ModelRecord(SignalEvent): if not rpc.execute(*args): return False except Exception, exception: - if not rpc.process_exception(exception, self.window, *args): + if not common.process_exception(exception, self.window, *args): return False self._loaded = False if force_reload: @@ -159,7 +160,7 @@ class ModelRecord(SignalEvent): try: val = self.rpc.default_get(self.mgroup.fields.keys(), context) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return for clause in domain: if clause[0] in self.mgroup.fields: @@ -173,7 +174,7 @@ class ModelRecord(SignalEvent): try: name = self.rpc.name_get([self.id], rpc.CONTEXT)[0] except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False return name @@ -247,7 +248,7 @@ class ModelRecord(SignalEvent): try: res = self.rpc.read([self.id], self.mgroup.mfields.keys(), ctx) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return if res: value = res[0] @@ -288,7 +289,7 @@ class ModelRecord(SignalEvent): res = getattr(self.rpc, 'on_change_' + fieldname)(ids, args, ctx) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return if res: later = {} @@ -311,7 +312,7 @@ class ModelRecord(SignalEvent): self.set_default(ir_default.get_default(self.resource, field_name + '=' + str(value), ctx)) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False def get_attachment_count(self, reload=False): diff --git a/tryton/gui/window/view_form/screen/screen.py b/tryton/gui/window/view_form/screen/screen.py index cd19c21e39..5fcd9935e7 100644 --- a/tryton/gui/window/view_form/screen/screen.py +++ b/tryton/gui/window/view_form/screen/screen.py @@ -8,6 +8,7 @@ from tryton.gui.window.view_form.widget_search import Form from tryton.signal_event import SignalEvent from tryton.common import node_attributes import gobject +import tryton.common as common class Screen(SignalEvent): @@ -125,7 +126,7 @@ class Screen(SignalEvent): self.name, 'search', values, offset, limit, self.sort, self.context) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) ids = rpc.execute('object', 'execute', self.name, 'search', values, offset, limit, self.sort, self.context) @@ -135,7 +136,7 @@ class Screen(SignalEvent): self.search_count = rpc.execute('object', 'execute', self.name, 'search_count', values, self.context) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) self.search_count = rpc.execute('object', 'execute', self.name, 'search_count', values, self.context) else: @@ -265,7 +266,7 @@ class Screen(SignalEvent): view = self.rpc.fields_view_get(view_id, view_type, self.context, self.hastoolbar) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) view = self.rpc.fields_view_get(view_id, view_type, self.context, self.hastoolbar) if self.exclude_field: @@ -441,7 +442,7 @@ class Screen(SignalEvent): if not self.rpc.unlink([obj_id]): return False except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False idx = self.models.models.index(self.current_model) self.models.remove(self.current_model) @@ -467,7 +468,7 @@ class Screen(SignalEvent): if not self.rpc.unlink(ids): return False except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False for model in self.current_view.sel_models_get(): self.models.remove(model) diff --git a/tryton/gui/window/view_form/view/form_gtk/interface.py b/tryton/gui/window/view_form/view/form_gtk/interface.py index 222bdb349d..f63ae31234 100644 --- a/tryton/gui/window/view_form/view/form_gtk/interface.py +++ b/tryton/gui/window/view_form/view/form_gtk/interface.py @@ -5,6 +5,7 @@ import tryton.rpc as rpc from tryton.common import warning, COLORS from tryton.config import GLADE, TRYTON_ICON import gettext +import tryton.common as common _ = gettext.gettext @@ -64,7 +65,7 @@ def field_pref_set(field, name, model, value, dependance=None, window=None): ir_default.set_default(model, field, clause, value, user, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, window) + common.process_exception(exception, window) return False return True return False diff --git a/tryton/gui/window/view_form/view/form_gtk/many2many.py b/tryton/gui/window/view_form/view/form_gtk/many2many.py index 24e5c16a9c..610cca95e9 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2many.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2many.py @@ -4,6 +4,7 @@ from interface import WidgetInterface import tryton.rpc as rpc from tryton.gui.window.win_search import WinSearch from tryton.gui.window.view_form.widget_search.form import _LIMIT +import tryton.common as common class Many2Many(WidgetInterface): @@ -67,7 +68,7 @@ class Many2Many(WidgetInterface): self.wid_text.get_text(), domain, 'ilike', context, _LIMIT) except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) return False ids = [x[0] for x in ids] if len(ids) != 1: diff --git a/tryton/gui/window/view_form/view/form_gtk/many2one.py b/tryton/gui/window/view_form/view/form_gtk/many2one.py index fccd14c55c..c1681c1c0f 100644 --- a/tryton/gui/window/view_form/view/form_gtk/many2one.py +++ b/tryton/gui/window/view_form/view/form_gtk/many2one.py @@ -149,7 +149,7 @@ class Many2One(WidgetInterface): self.attrs['relation'], 'name_search', '', [], 'ilike', {}) except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) ids = [] if ids: self.load_completion(ids) @@ -192,7 +192,7 @@ class Many2One(WidgetInterface): self.attrs['relation'], 'name_search', name, domain, 'ilike', context) except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) return False if len(ids)==1: self._view.modelfield.set_client(self._view.model, ids[0]) @@ -208,7 +208,7 @@ class Many2One(WidgetInterface): self.attrs['relation'], 'name_get', [ids[0]], rpc.CONTEXT)[0] except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) return False self._view.modelfield.set_client(self._view.model, name) return True @@ -243,7 +243,7 @@ class Many2One(WidgetInterface): _LIMIT) except Exception, exception: self.focus_out = True - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) self.changed = True return False if len(ids)==1: @@ -264,7 +264,7 @@ class Many2One(WidgetInterface): rpc.CONTEXT)[0] except Exception, exception: self.focus_out = True - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) self.changed = True return False self._view.modelfield.set_client(self._view.model, name, @@ -315,7 +315,7 @@ class Many2One(WidgetInterface): _LIMIT) except Exception, exception: self.focus_out = True - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) self.changed = True return False if ids and len(ids)==1: @@ -336,7 +336,7 @@ class Many2One(WidgetInterface): rpc.CONTEXT)[0] except Exception, exception: self.focus_out = True - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) self.changed = True return False self._view.modelfield.set_client(self._view.model, name, diff --git a/tryton/gui/window/view_form/view/form_gtk/parser.py b/tryton/gui/window/view_form/view/form_gtk/parser.py index 05ca69d52e..465a43f90a 100644 --- a/tryton/gui/window/view_form/view/form_gtk/parser.py +++ b/tryton/gui/window/view_form/view/form_gtk/parser.py @@ -46,7 +46,7 @@ class Button(object): try: rpc.execute(*args) except Exception, exception: - rpc.process_exception(exception, self.form.window, + common.process_exception(exception, self.form.window, *args) elif button_type == 'object': if not obj_id: @@ -56,7 +56,7 @@ class Button(object): try: rpc.execute(*args) except Exception, exception: - rpc.process_exception(exception, self.form.window, + common.process_exception(exception, self.form.window, *args) elif button_type == 'action': action_id = None @@ -65,7 +65,7 @@ class Button(object): try: action_id = rpc.execute(*args) except Exception, exception: - action_id = rpc.process_exception(exception, self.form.window, + action_id = common.process_exception(exception, self.form.window, *args) if action_id: Action.execute(action_id, { @@ -532,7 +532,7 @@ class ParserForm(ParserInterface): lang_ids = rpc.execute('object', 'execute', 'ir.lang', 'search', [('translatable','=','1')]) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False if not lang_ids: @@ -543,7 +543,7 @@ class ParserForm(ParserInterface): langs = rpc.execute('object', 'execute', 'ir.lang', 'read', lang_ids, ['code', 'name']) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False code = rpc.CONTEXT.get('language', 'en_US') @@ -634,7 +634,7 @@ class ParserForm(ParserInterface): val = rpc.execute('/object', 'execute', model, 'read', [obj_id], [name], context) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False val = val[0] if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: @@ -687,7 +687,7 @@ class ParserForm(ParserInterface): try: rpc.execute(*args) except Exception, exception: - rpc.process_exception(exception, self.window, *args) + common.process_exception(exception, self.window, *args) if response == gtk.RESPONSE_CANCEL: self.window.present() win.destroy() diff --git a/tryton/gui/window/view_form/view/form_gtk/reference.py b/tryton/gui/window/view_form/view/form_gtk/reference.py index 1deebda96a..0d38c74ad5 100644 --- a/tryton/gui/window/view_form/view/form_gtk/reference.py +++ b/tryton/gui/window/view_form/view/form_gtk/reference.py @@ -6,6 +6,7 @@ from many2one import Dialog from tryton.gui.window.win_search import WinSearch import tryton.rpc as rpc from tryton.rpc import RPCProxy +import tryton.common as common _ = gettext.gettext @@ -79,7 +80,7 @@ class Reference(WidgetInterface): selection = rpc.execute('object', 'execute', self.model, selection, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) selection = [] selection.sort(lambda x, y: cmp(x[1], y[1])) self.set_popdown(selection) @@ -162,7 +163,7 @@ class Reference(WidgetInterface): except Exception, exception: self.focus_out = True self.changed = True - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) return False if ids and len(ids) == 1: obj_id, name = ids[0] @@ -185,7 +186,7 @@ class Reference(WidgetInterface): except Exception, exception: self.focus_out = True self.changed = True - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) return False self._view.modelfield.set_client(self._view.model, (model, [obj_id, name])) @@ -255,7 +256,7 @@ class Reference(WidgetInterface): obj_id, name = RPCProxy(model).name_get(obj_id, rpc.CONTEXT)[0] except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) name = '???' self.wid_text.set_text(name) img.set_from_stock('gtk-open', gtk.ICON_SIZE_BUTTON) diff --git a/tryton/gui/window/view_form/view/form_gtk/selection.py b/tryton/gui/window/view_form/view/form_gtk/selection.py index 9a8fd1036e..e9423a7a53 100644 --- a/tryton/gui/window/view_form/view/form_gtk/selection.py +++ b/tryton/gui/window/view_form/view/form_gtk/selection.py @@ -2,6 +2,7 @@ import gtk import gobject from interface import WidgetInterface import tryton.rpc as rpc +import tryton.common as common class Selection(WidgetInterface): @@ -29,7 +30,7 @@ class Selection(WidgetInterface): attrs['relation'], 'name_search', '', attrs.get('domain', []), 'ilike', rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) selection = [] else: if not isinstance(selection, (list, tuple)): @@ -37,7 +38,7 @@ class Selection(WidgetInterface): selection = rpc.execute('object', 'execute', self.model, selection, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self._window) + common.process_exception(exception, self._window) selection = [] selection.sort(lambda x, y: cmp(x[1], y[1])) attrs['selection'] = selection diff --git a/tryton/gui/window/view_form/view/list.py b/tryton/gui/window/view_form/view/list.py index ee9a7a42b8..300efeda03 100644 --- a/tryton/gui/window/view_form/view/list.py +++ b/tryton/gui/window/view_form/view/list.py @@ -7,6 +7,7 @@ from interface import ParserView from tryton.action import Action from tryton.common import message import gettext +import tryton.common as common _ = gettext.gettext @@ -285,7 +286,7 @@ class ViewList(ParserView): (self.screen.fields[path[1].name]['relation'], 0), rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False menu_entries = [] menu_entries.append((None, None, None)) 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 8d462b2b54..c2598200f9 100644 --- a/tryton/gui/window/view_form/view/list_gtk/parser.py +++ b/tryton/gui/window/view_form/view/list_gtk/parser.py @@ -17,6 +17,7 @@ from tryton.gui.window.win_search import WinSearch import tryton.rpc as rpc import datetime as DT from tryton.common import DT_FORMAT, DHM_FORMAT, COLORS, node_attributes, TRYTON_ICON +import tryton.common as common if not hasattr(locale, 'nl_langinfo'): locale.nl_langinfo = lambda *a: '%x' @@ -388,7 +389,7 @@ class M2O(Char): try: names = rpc_relation.name_search(text, domain, 'ilike', context) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return '???' if len(names) != 1: return self.search_remote(relation, [x[0] for x in names], @@ -411,7 +412,7 @@ class M2O(Char): try: names = rpc_relation.name_search(text, domain, 'ilike', context) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False, False if len(names) == 1: return True, names[0] @@ -439,7 +440,7 @@ class M2O(Char): try: return rpc_relation.name_get([found[0]], context)[0] except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False, None else: return False, None @@ -494,7 +495,7 @@ class M2M(Char): try: names = rpc_relation.name_search(text, domain, 'ilike', context) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return [] ids = [x[0] for x in names] win = WinSearch(relation, sel_multi=True, ids=ids, context=context, @@ -515,7 +516,7 @@ class M2M(Char): try: ids = rpc_relation.search(domain) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) return False, None if ids and len(ids)==1: return True, ids @@ -542,7 +543,7 @@ class Selection(Char): self.attrs['relation'], 'name_search', '', self.attrs.get('domain', []), 'ilike', rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) selection = [] else: if not isinstance(selection, (list, tuple)): @@ -550,7 +551,7 @@ class Selection(Char): selection = rpc.execute('object', 'execute', self.model, selection, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) selection = [] selection.sort(lambda x, y: cmp(x[1], y[1])) self.attrs['selection'] = selection diff --git a/tryton/gui/window/view_form/widget_search/reference.py b/tryton/gui/window/view_form/widget_search/reference.py index bc28a60bba..6f4122c94d 100644 --- a/tryton/gui/window/view_form/widget_search/reference.py +++ b/tryton/gui/window/view_form/widget_search/reference.py @@ -2,6 +2,7 @@ import gtk import gettext from interface import Interface import tryton.rpc as rpc +import tryton.common as common _ = gettext.gettext @@ -22,7 +23,7 @@ class Reference(Interface): attrs['relation'], 'name_search', '', attrs.get('domain', []), 'ilike', rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, parent) + common.process_exception(exception, parent) selection = [] else: if not isinstance(selection, (list, tuple)): @@ -30,7 +31,7 @@ class Reference(Interface): selection = rpc.execute('object', 'execute', attrs['model'], selection, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, parent) + common.process_exception(exception, parent) selection = [] selection.sort(lambda x, y: cmp(x[1], y[1])) attrs['selection'] = selection diff --git a/tryton/gui/window/view_form/widget_search/selection.py b/tryton/gui/window/view_form/widget_search/selection.py index e30e457128..729df31083 100644 --- a/tryton/gui/window/view_form/widget_search/selection.py +++ b/tryton/gui/window/view_form/widget_search/selection.py @@ -1,6 +1,7 @@ import gtk from interface import Interface import tryton.rpc as rpc +import tryton.common as common class Selection(Interface): @@ -19,7 +20,7 @@ class Selection(Interface): attrs['relation'], 'name_search', '', attrs.get('domain', []), 'ilike', rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, parent) + common.process_exception(exception, parent) selection = [] else: if not isinstance(selection, (list, tuple)): @@ -27,7 +28,7 @@ class Selection(Interface): selection = rpc.execute('object', 'execute', attrs['model'], selection, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, parent) + common.process_exception(exception, parent) selection = [] selection.sort(lambda x, y: cmp(x[1], y[1])) attrs['selection'] = selection diff --git a/tryton/gui/window/view_tree/view_tree.py b/tryton/gui/window/view_tree/view_tree.py index 1c810262bd..892a261d85 100644 --- a/tryton/gui/window/view_tree/view_tree.py +++ b/tryton/gui/window/view_tree/view_tree.py @@ -9,6 +9,7 @@ from parse import Parse import datetime as DT import locale from tryton.common import DT_FORMAT, DHM_FORMAT +import tryton.common as common if not hasattr(locale, 'nl_langinfo'): locale.nl_langinfo = lambda *a: '%x' @@ -319,7 +320,7 @@ class ViewTree(object): self.fields = rpc.execute('object', 'execute', view_info['model'], 'fields_get', False, self.context) except Exception, exception: - rpc.process_exception(exception, self.window) + common.process_exception(exception, self.window) raise parse = Parse(self.fields) parse.parse(view_info['arch'], self.view) diff --git a/tryton/gui/window/view_tree/view_tree_sc.py b/tryton/gui/window/view_tree/view_tree_sc.py index 0f706a17b3..c8e962dd1f 100644 --- a/tryton/gui/window/view_tree/view_tree_sc.py +++ b/tryton/gui/window/view_tree/view_tree_sc.py @@ -3,6 +3,7 @@ import gobject import gtk import gettext from tryton.gui import Main +import tryton.common as common _ = gettext.gettext @@ -32,7 +33,7 @@ class ViewTreeSC(object): try: view_sc = rpc.execute(*args) except Exception, exception: - view_sc = rpc.process_exception(exception, self.window, *args) + view_sc = common.process_exception(exception, self.window, *args) if not view_sc: return for shortcut in view_sc: diff --git a/tryton/gui/window/win_export.py b/tryton/gui/window/win_export.py index 9560f3e942..7d2170e349 100644 --- a/tryton/gui/window/win_export.py +++ b/tryton/gui/window/win_export.py @@ -79,7 +79,7 @@ class WinExport(object): fields[field]['relation'], 'fields_get', False, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) continue model_populate(fields2, prefix_node+field+'/', node, st_name+'/', level-1) @@ -155,13 +155,13 @@ class WinExport(object): try: export_ids = ir_export.search([('resource', '=', self.model)]) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) return for export in ir_export.read(export_ids): try: fields = ir_export_line.read(export['export_fields']) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) continue self.predef_model.append(( export['id'], @@ -187,7 +187,7 @@ class WinExport(object): new_id = ir_export.create({'name' : name, 'resource' : self.model, 'export_fields' : [('create', {'name' : f}) for f in fields]}) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) return self.predef_model.append(( new_id, @@ -208,7 +208,7 @@ class WinExport(object): try: ir_export.unlink(export_id) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) return for i in range(len(self.predef_model)): if self.predef_model[i][0] == export_id: @@ -283,6 +283,6 @@ class WinExport(object): datas = rpc.execute('object', 'execute', model, 'export_data', ids, fields, ctx) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) return [] return datas diff --git a/tryton/gui/window/win_import.py b/tryton/gui/window/win_import.py index a6da4266c0..b69c2e8183 100644 --- a/tryton/gui/window/win_import.py +++ b/tryton/gui/window/win_import.py @@ -79,7 +79,7 @@ class WinImport(object): 'execute', fields[field]['relation'], 'fields_get', False, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) continue model_populate(fields2, prefix_node+field+'/', node, st_name+'/', level-1) @@ -202,7 +202,7 @@ class WinImport(object): res = rpc.execute('object', 'execute', model, 'import_data', fields, datas) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) return False if res[0] >= 0: common.message(_('Imported %d objects!') % (res[0],), self.parent) diff --git a/tryton/gui/window/win_search.py b/tryton/gui/window/win_search.py index 1ccf29b67b..c1a450cde6 100644 --- a/tryton/gui/window/win_search.py +++ b/tryton/gui/window/win_search.py @@ -4,6 +4,7 @@ import tryton.rpc as rpc from tryton.gui.window.view_form.screen import Screen import tryton.gui.window.view_form.widget_search as widget_search from tryton.config import TRYTON_ICON, GLADE +import tryton.common as common _ = gettext.gettext @@ -63,7 +64,7 @@ class WinSearch(object): False, 'tree', self.context) view_form = rpc.execute(*args) except Exception, exception: - view_form = rpc.process_exception(exception, self.parent, *args) + view_form = common.process_exception(exception, self.parent, *args) self.form = widget_search.Form(view_form['arch'], view_form['fields'], model, parent=self.win) @@ -117,7 +118,7 @@ class WinSearch(object): self.model_name, 'search', value, offset, limit, 0, rpc.CONTEXT) except Exception, exception: - rpc.process_exception(exception, self.win) + common.process_exception(exception, self.win) return False self.reload() self.old_search = self.form.value diff --git a/tryton/rpc.py b/tryton/rpc.py index fcea3f8f55..1cdf27157f 100644 --- a/tryton/rpc.py +++ b/tryton/rpc.py @@ -1,13 +1,7 @@ import pysocket -import translate -from config import CONFIG, GLADE, TRYTON_ICON -import gtk import logging -import common import socket from threading import Semaphore -from gtk import glade -import gettext _SOCK = None _USER = 0 @@ -124,11 +118,6 @@ def context_reload(): for i in context: value = context[i] CONTEXT[i] = value - if i == 'language_direction': - if value == 'rtl': - gtk.widget_set_default_direction(gtk.TEXT_DIR_RTL) - else: - gtk.widget_set_default_direction(gtk.TEXT_DIR_LTR) if i == 'timezone': try: TIMEZONE = execute('common', 'timezone_get') @@ -168,56 +157,6 @@ def execute(obj, method, *args): _VIEW_CACHE[key] = (result['md5'], result) return result -def process_exception(exception, parent, obj='', method='', *args): - global _USERNAME, _DATABASE, _SOCK - type = 'error' - if str(exception.args[0]) == 'NotLogged': - type = 'warning' - 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 - data = str(exception.args[0]) - description = data - if len(exception.args) > 1: - details = str(exception.args[1]) - else: - details = data - if hasattr(data, 'split') and ' -- ' in data: - lines = data.split('\n') - type = lines[0].split(' -- ')[0] - description = '' - if len(lines[0].split(' -- ')) > 1: - description = lines[0].split(' -- ')[1] - if len(lines) > 2: - details = '\n'.join(lines[2:]) - if type == 'warning': - if description == 'ConcurrencyException' \ - and len(args) > 4: - if concurrency(args[0], args[2][0], args[4], parent): - if 'read_delta' in args[4]: - del args[4]['read_delta'] - try: - return execute(obj, method, *args) - except Exception, exception: - return process_exception(exception, parent, obj, - method, *args) - else: - common.warning(details, parent, description) - else: - common.error(type, parent, details) - - class RPCProxy(object): def __init__(self, name): @@ -237,22 +176,3 @@ class RPCFunction(object): def __call__(self, *args): return execute('object', 'execute', self.name, self.func, *args) - -def concurrency(resource, obj_id, context, parent): - dia = glade.XML(GLADE, 'dialog_concurrency_exception', gettext.textdomain()) - win = dia.get_widget('dialog_concurrency_exception') - - win.set_transient_for(parent) - win.set_icon(TRYTON_ICON) - - res = win.run() - parent.present() - win.destroy() - - if res == gtk.RESPONSE_OK: - return True - if res == gtk.RESPONSE_APPLY: - from gui.window import Window - Window.create(False, resource, obj_id, [('id', '=', obj_id)], 'form', - parent, context, ['form', 'tree']) - return False diff --git a/tryton/translate.py b/tryton/translate.py index 0a3f70a392..1e02b9e679 100644 --- a/tryton/translate.py +++ b/tryton/translate.py @@ -113,3 +113,9 @@ def setlang(lang=None): gettext.textdomain(PACKAGE) gettext.install(PACKAGE, unicode=1) gtk.glade.bindtextdomain(PACKAGE, locale_dir) + +def set_language_direction(direction): + if direction == 'rtl': + gtk.widget_set_default_direction(gtk.TEXT_DIR_RTL) + else: + gtk.widget_set_default_direction(gtk.TEXT_DIR_LTR) diff --git a/tryton/wizard/main.py b/tryton/wizard/main.py index 9958a3cf7f..55366cb350 100644 --- a/tryton/wizard/main.py +++ b/tryton/wizard/main.py @@ -86,7 +86,7 @@ class Wizard(object): try: wiz_id = rpc.execute('wizard', 'create', action) except Exception, exception: - rpc.process_exception(exception, parent) + common.process_exception(exception, parent) return dia = None while state != 'end': @@ -219,5 +219,5 @@ class WizardProgress(object): win.destroy() gtk.main_iteration() if self.exception: - rpc.process_exception(self.exception, self.parent) + common.process_exception(self.exception, self.parent) return self.res