changeset 60b4dc6f3da9 in tryton:default
details: https://hg.tryton.org/tryton?cmd=changeset;node=60b4dc6f3da9
description:
        Fallback to model name as title

        issue9596
        review300381002
diffstat:

 CHANGELOG                       |   1 +
 tryton/common/__init__.py       |   4 ++--
 tryton/common/common.py         |  22 ++++++++++++++++++++++
 tryton/gui/main.py              |   1 +
 tryton/gui/window/board.py      |   7 +++----
 tryton/gui/window/form.py       |   2 ++
 tryton/gui/window/win_form.py   |   4 +++-
 tryton/gui/window/win_search.py |   2 ++
 8 files changed, 36 insertions(+), 7 deletions(-)

diffs (141 lines):

diff -r 9095afd5c5a7 -r 60b4dc6f3da9 CHANGELOG
--- a/CHANGELOG Sat Oct 03 23:37:02 2020 +0200
+++ b/CHANGELOG Sun Oct 04 00:35:23 2020 +0200
@@ -1,3 +1,4 @@
+* Fallback to model name as title
 * Manage deletable and writable state
 * Support e-mail template
 * Send e-mail via the server
diff -r 9095afd5c5a7 -r 60b4dc6f3da9 tryton/common/__init__.py
--- a/tryton/common/__init__.py Sat Oct 03 23:37:02 2020 +0200
+++ b/tryton/common/__init__.py Sun Oct 04 00:35:23 2020 +0200
@@ -1,7 +1,7 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
 from .common import (
-    IconFactory, MODELACCESS, MODELHISTORY, VIEW_SEARCH,
+    IconFactory, MODELACCESS, MODELHISTORY, MODELNAME, VIEW_SEARCH,
     get_toplevel_window, get_sensible_widget, selection, file_selection,
     slugify, file_write, file_open, mailto, message, warning, userwarning, sur,
     sur_3b, ask, concurrency, error, to_xml, process_exception, Login, Logout,
@@ -18,7 +18,7 @@
 from . import timedelta
 
 __all__ = [
-    IconFactory, MODELACCESS, MODELHISTORY, VIEW_SEARCH,
+    IconFactory, MODELACCESS, MODELHISTORY, MODELNAME, VIEW_SEARCH,
     get_toplevel_window, get_sensible_widget, selection, file_selection,
     slugify, file_write, file_open, mailto, message, warning, userwarning, sur,
     sur_3b, ask, concurrency, error, to_xml, process_exception, Login, Logout,
diff -r 9095afd5c5a7 -r 60b4dc6f3da9 tryton/common/common.py
--- a/tryton/common/common.py   Sat Oct 03 23:37:02 2020 +0200
+++ b/tryton/common/common.py   Sun Oct 04 00:35:23 2020 +0200
@@ -228,6 +228,28 @@
 MODELHISTORY = ModelHistory()
 
 
+class ModelName:
+    _names = {}
+
+    def load_names(self):
+        try:
+            self._names = rpc.execute(
+                'model', 'ir.model', 'get_names', rpc.CONTEXT)
+        except TrytonServerError:
+            pass
+
+    def get(self, model):
+        if not self._names:
+            self.load_names()
+        return self._names.get(model, '')
+
+    def clear(self):
+        return self._names.clear()
+
+
+MODELNAME = ModelName()
+
+
 class ViewSearch(object):
     searches = {}
 
diff -r 9095afd5c5a7 -r 60b4dc6f3da9 tryton/gui/main.py
--- a/tryton/gui/main.py        Sat Oct 03 23:37:02 2020 +0200
+++ b/tryton/gui/main.py        Sun Oct 04 00:35:23 2020 +0200
@@ -532,6 +532,7 @@
                 self.favorite_unset()
                 self.primary_menu.set_menu_model(self._get_primary_menu())
             CONFIG['client.lang'] = prefs['language']
+        common.MODELNAME.clear()
         # Set placeholder after language is set to get correct translation
         self.global_search_entry.set_placeholder_text(_("Action"))
         CONFIG.save()
diff -r 9095afd5c5a7 -r 60b4dc6f3da9 tryton/gui/window/board.py
--- a/tryton/gui/window/board.py        Sat Oct 03 23:37:02 2020 +0200
+++ b/tryton/gui/window/board.py        Sun Oct 04 00:35:23 2020 +0200
@@ -7,7 +7,7 @@
 from tryton.signal_event import SignalEvent
 from tryton.gui import Main
 from tryton.gui.window.view_board import ViewBoard
-from tryton.common import RPCExecute, RPCException
+from tryton.common import RPCExecute, RPCException, MODELNAME
 
 from .tabcontent import TabContent
 
@@ -35,9 +35,8 @@
         self.model = model
         self.dialogs = []
         if not name:
-            self.name = self.board.name
-        else:
-            self.name = name
+            name = MODELNAME.get(model)
+        self.name = name
 
         self.create_tabcontent()
         self.board.reload()
diff -r 9095afd5c5a7 -r 60b4dc6f3da9 tryton/gui/window/form.py
--- a/tryton/gui/window/form.py Sat Oct 03 23:37:02 2020 +0200
+++ b/tryton/gui/window/form.py Sun Oct 04 00:35:23 2020 +0200
@@ -48,6 +48,8 @@
         self.screen = Screen(self.model, **attributes)
         self.screen.widget.show()
 
+        if not name:
+            name = common.MODELNAME.get(model)
         self.name = name
 
         self.create_tabcontent()
diff -r 9095afd5c5a7 -r 60b4dc6f3da9 tryton/gui/window/win_form.py
--- a/tryton/gui/window/win_form.py     Sat Oct 03 23:37:02 2020 +0200
+++ b/tryton/gui/window/win_form.py     Sun Oct 04 00:35:23 2020 +0200
@@ -6,7 +6,7 @@
 
 from .infobar import InfoBar
 import tryton.common as common
-from tryton.common import TRYTON_ICON
+from tryton.common import TRYTON_ICON, MODELNAME
 from tryton.common.domain_parser import quote
 from tryton.common.underline import set_underline
 from tryton.common.widget_style import widget_class
@@ -30,6 +30,8 @@
         self.domain = domain
         self.context = context
         self.save_current = save_current
+        if not title:
+            title = MODELNAME.get(screen.model_name)
         self.title = title
         self.prev_view = self.screen.current_view
         self.screen.screen_container.alternate_view = True
diff -r 9095afd5c5a7 -r 60b4dc6f3da9 tryton/gui/window/win_search.py
--- a/tryton/gui/window/win_search.py   Sat Oct 03 23:37:02 2020 +0200
+++ b/tryton/gui/window/win_search.py   Sun Oct 04 00:35:23 2020 +0200
@@ -32,6 +32,8 @@
         self.views_preload = views_preload
         self.sel_multi = sel_multi
         self.callback = callback
+        if not title:
+            title = common.MODELNAME.get(model)
         self.title = title
         self.exclude_field = exclude_field
 

Reply via email to