changeset 8f943feeb315 in tryton:default
details: https://hg.tryton.org/tryton?cmd=changeset&node=8f943feeb315
description:
        Add limit to search count

        issue10967
        review389301002
diffstat:

 CHANGELOG                                                 |   3 ++
 tryton/common/common.py                                   |  13 ++++++++---
 tryton/gui/window/form.py                                 |  15 +++++++++----
 tryton/gui/window/view_form/screen/screen.py              |  11 +++++++--
 tryton/gui/window/view_form/view/form_gtk/binary.py       |   2 +-
 tryton/gui/window/view_form/view/form_gtk/state_widget.py |  16 +++++++++-----
 tryton/gui/window/view_form/view/list_gtk/widget.py       |   2 +-
 tryton/gui/window/view_form/view/screen_container.py      |   5 +++-
 8 files changed, 46 insertions(+), 21 deletions(-)

diffs (192 lines):

diff -r ec9dd80cc0e5 -r 8f943feeb315 CHANGELOG
--- a/CHANGELOG Sun Jan 23 13:32:59 2022 +0100
+++ b/CHANGELOG Sun Jan 30 01:42:23 2022 +0100
@@ -1,3 +1,6 @@
+* Display the number of selected records
+* Humanize the count result
+* Add limit to search_count
 * Call view_get for board view
 * Limit board action domain to active id and ids
 * Add support for Python 3.10
diff -r ec9dd80cc0e5 -r 8f943feeb315 tryton/common/common.py
--- a/tryton/common/common.py   Sun Jan 23 13:32:59 2022 +0100
+++ b/tryton/common/common.py   Sun Jan 30 01:42:23 2022 +0100
@@ -3,6 +3,7 @@
 
 import colorsys
 import gettext
+import locale
 import logging
 import os
 import platform
@@ -1236,10 +1237,14 @@
     return timezoned_date(date, reverse=True)
 
 
-def humanize(size):
-    for x in ('bytes', 'KB', 'MB', 'GB', 'TB', 'PB'):
-        if size < 1000:
-            return '%3.1f%s' % (size, x)
+def humanize(size, suffix=''):
+    for u in ['', 'K', 'M', 'G', 'T', 'P']:
+        if size <= 1000:
+            if isinstance(size, int) or size.is_integer():
+                size = locale.localize('{0:.0f}'.format(size))
+            else:
+                size = locale.localize('{0:.{1}f}'.format(size, 2).rstrip('0'))
+            return ''.join([size, u, suffix])
         size /= 1000.0
 
 
diff -r ec9dd80cc0e5 -r 8f943feeb315 tryton/gui/window/form.py
--- a/tryton/gui/window/form.py Sun Jan 23 13:32:59 2022 +0100
+++ b/tryton/gui/window/form.py Sun Jan 30 01:42:23 2022 +0100
@@ -602,6 +602,9 @@
 
     def record_message(self, position, size, max_size, record_id):
         name = str(position) if position else '_'
+        selected = len(self.screen.selected_records)
+        if selected > 1:
+            name += '#%i' % selected
         for button_id in ('print', 'relate', 'email', 'open', 'save',
                 'attach'):
             button = self.buttons[button_id]
@@ -624,11 +627,13 @@
         menu_save = self.menu_buttons['save']
         menu_save.props.sensitive = not self.screen.readonly
 
-        msg = name + ' / ' + str(size)
-        if (size < max_size
-                and self.screen.limit is not None
-                and max_size > self.screen.limit):
-            msg += _(' of ') + str(max_size)
+        if size < max_size:
+            msg = "%s@%s/%s" % (
+                name, common.humanize(size), common.humanize(max_size))
+            if max_size >= self.screen.count_limit:
+                msg += "+"
+        else:
+            msg = "%s/%s" % (name, common.humanize(size))
         self.status_label.set_text(msg)
         self.message_info()
         self.activate_save()
diff -r ec9dd80cc0e5 -r 8f943feeb315 
tryton/gui/window/view_form/screen/screen.py
--- a/tryton/gui/window/view_form/screen/screen.py      Sun Jan 23 13:32:59 
2022 +0100
+++ b/tryton/gui/window/view_form/screen/screen.py      Sun Jan 30 01:42:23 
2022 +0100
@@ -155,6 +155,10 @@
     def deletable(self):
         return all(r.deletable for r in self.selected_records)
 
+    @property
+    def count_limit(self):
+        return self.limit * 100 + self.offset
+
     def search_active(self, active=True):
         if active and not self.parent:
             self.screen_container.set_screen(self)
@@ -299,8 +303,9 @@
         if not only_ids:
             if self.limit is not None and len(ids) == self.limit:
                 try:
-                    self.search_count = RPCExecute('model', self.model_name,
-                        'search_count', domain, context=context)
+                    self.search_count = RPCExecute(
+                        'model', self.model_name, 'search_count',
+                        domain, 0, self.count_limit, context=context)
                 except RPCException:
                     self.search_count = 0
             else:
@@ -376,7 +381,7 @@
             domain = ['AND', domain, screen_domain]
             set_tab_counter(lambda: None, idx)
             RPCExecute('model', self.model_name,
-                'search_count', domain, context=self.context,
+                'search_count', domain, 0, 1000, context=self.context,
                 callback=functools.partial(set_tab_counter, idx=idx))
 
     @property
diff -r ec9dd80cc0e5 -r 8f943feeb315 
tryton/gui/window/view_form/view/form_gtk/binary.py
--- a/tryton/gui/window/view_form/view/form_gtk/binary.py       Sun Jan 23 
13:32:59 2022 +0100
+++ b/tryton/gui/window/view_form/view/form_gtk/binary.py       Sun Jan 30 
01:42:23 2022 +0100
@@ -209,7 +209,7 @@
             size = self.field.get_size(self.record)
         else:
             size = len(self.field.get(self.record))
-        self.wid_size.set_text(common.humanize(size or 0))
+        self.wid_size.set_text(common.humanize(size or 0, 'B'))
         reset_position(self.wid_size)
         if self.wid_text:
             self.wid_text.set_text(self.filename_field.get(self.record) or '')
diff -r ec9dd80cc0e5 -r 8f943feeb315 
tryton/gui/window/view_form/view/form_gtk/state_widget.py
--- a/tryton/gui/window/view_form/view/form_gtk/state_widget.py Sun Jan 23 
13:32:59 2022 +0100
+++ b/tryton/gui/window/view_form/view/form_gtk/state_widget.py Sun Jan 30 
01:42:23 2022 +0100
@@ -167,9 +167,9 @@
             for n, d, c in action['domains'] if c]
         if tab_domains:
             label = ('%s\n' % action['name']) + '\n'.join(
-                '%s (%%d)' % n for n, _ in tab_domains)
+                '%s (%%s)' % n for n, _ in tab_domains)
         else:
-            label = '%s (%%d)' % action['name']
+            label = '%s (%%s)' % action['name']
         if record and self.action_id in record.links_counts:
             counter = record.links_counts[self.action_id]
             self._set_label_counter(label, counter)
@@ -181,14 +181,15 @@
                 for i, (_, tab_domain) in enumerate(tab_domains):
                     common.RPCExecute(
                         'model', action['res_model'], 'search_count',
-                        ['AND', domain, tab_domain], context=context,
+                        ['AND', domain, tab_domain], 0, 100, context=context,
                         callback=functools.partial(
                             self._set_count, idx=i, current=self._current,
                             counter=counter, label=label))
             else:
                 common.RPCExecute(
-                    'model', action['res_model'], 'search_count', domain,
-                    context=context, callback=functools.partial(
+                    'model', action['res_model'], 'search_count',
+                    domain, 0, 100, context=context,
+                    callback=functools.partial(
                         self._set_count, current=self._current,
                         counter=counter, label=label))
 
@@ -196,7 +197,10 @@
         if current != self._current and not self.get_parent():
             return
         try:
-            counter[idx] = value()
+            count = value()
+            if count > 99:
+                count = '99+'
+            counter[idx] = count
         except common.RPCException:
             pass
         self._set_label_counter(label, counter)
diff -r ec9dd80cc0e5 -r 8f943feeb315 
tryton/gui/window/view_form/view/list_gtk/widget.py
--- a/tryton/gui/window/view_form/view/list_gtk/widget.py       Sun Jan 23 
13:32:59 2022 +0100
+++ b/tryton/gui/window/view_form/view/list_gtk/widget.py       Sun Jan 30 
01:42:23 2022 +0100
@@ -546,7 +546,7 @@
             size = field.get_size(record)
         else:
             size = len(field.get(record))
-        return common.humanize(size) if size else ''
+        return common.humanize(size, 'B') if size else ''
 
     def value_from_text(self, record, text, callback=None):
         if callback:
diff -r ec9dd80cc0e5 -r 8f943feeb315 
tryton/gui/window/view_form/view/screen_container.py
--- a/tryton/gui/window/view_form/view/screen_container.py      Sun Jan 23 
13:32:59 2022 +0100
+++ b/tryton/gui/window/view_form/view/screen_container.py      Sun Jan 30 
01:42:23 2022 +0100
@@ -507,7 +507,10 @@
             label.set_label('')
             tooltip.set_tip(label, '')
         else:
-            tooltip.set_tip(label, '%d' % count)
+            tip = common.humanize(count)
+            if count >= 1000:
+                tip += '+'
+            tooltip.set_tip(label, tip)
             fmt = '(%d)'
             if count > 99:
                 fmt = '(%d+)'

Reply via email to