Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#19229 closed New feature (wontfix)

Use thousands separator to ease the reading of numbers with many digits

Reported by: zachborboa@… Owned by: nobody
Component: contrib.admin Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

diff --git a/contrib/admin/templates/admin/pagination.html b/contrib/admin/templates/admin/pagination.html
index 3588132..a8d744a 100644
--- a/contrib/admin/templates/admin/pagination.html
+++ b/contrib/admin/templates/admin/pagination.html
@@ -1,12 +1,13 @@
 {% load admin_list %}
 {% load i18n %}
+{% load humanize %}
 <p class="paginator">
 {% if pagination_required %}
 {% for i in page_range %}
     {% paginator_number cl i %}
 {% endfor %}
 {% endif %}
-{{ cl.result_count }} {% ifequal cl.result_count 1 %}{{ cl.opts.verbose_name }}{% else %}{{ cl.opts.verbose_name_plural }}{% endifequal %}
+{{ cl.result_count|intcomma }} {% ifequal cl.result_count 1 %}{{ cl.opts.verbose_name }}{% else %}{{ cl.opts.verbose_name_plural }}{% endifequal %}
 {% if show_all_url %}&nbsp;&nbsp;<a href="{{ show_all_url }}" class="showall">{% trans 'Show all' %}</a>{% endif %}
 {% if cl.formset and cl.result_count %}<input type="submit" name="_save" class="default" value="{% trans 'Save' %}"/>{% endif %}
 </p>

Attachments (1)

thousands-separator.png (9.0 KB) - added by zachborboa@… 2 years ago.

Download all attachments as: .zip

Change History (9)

Changed 2 years ago by zachborboa@…

comment:1 Changed 2 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Also requires 'django.contrib.humanize'.

INSTALLED_APPS = (
    'django.contrib.humanize',
)

comment:2 Changed 2 years ago by julien

  • Resolution set to wontfix
  • Status changed from new to closed

Thanks for the report, however the pagination count is already displayed following the active localization rules. For example, if English is active then commas should already be displayed as thousand separators. For other locales (e.g. French), then spaces should be used instead. Forcing the use of |intcomma would bypass the localization rules, which isn't acceptable.

comment:3 Changed 2 years ago by anonymous

Thank you for the response. In short, set:

USE_THOUSAND_SEPARATOR = True # False by default
USE_L10N = True # True by default
USE_I18N = True # True by default

comment:4 Changed 2 years ago by anonymous

Why should USE_THOUSAND_SEPARATOR not be enabled by default?

comment:5 Changed 2 years ago by aaugustin

USE_THOUSAND_SEPARATOR = True will break any non-trivial application that hasn't been designed to support it from the start.

Random example: a template contains <div data-id="{{ myobj.pk }}>{{ myobj }}</div>, and something in JavaScript uses the pk.

That works perfectly, until a user creates the 1000th post — six months after you consider the site final...

comment:6 Changed 2 years ago by zachborboa@…

Would there anything wrong or particularly difficult with excluding localization formatting when accessing an object's primary key (e.g. myobj.pk), but including localization formatting for all other numbers in templates?

comment:7 follow-up: Changed 2 years ago by anonymous

Well, that might fix the specific example I just gave, but that isn't an obviously correct behavior either. If I'm displaying Order #{{ order.pk }}, I expect a thousand separator.

comment:8 in reply to: ↑ 7 Changed 2 years ago by anonymous

Replying to anonymous:

Well, that might fix the specific example I just gave, but that isn't an obviously correct behavior either. If I'm displaying Order #{{ order.pk }}, I expect a thousand separator.

I respectfully disagree. Accessing an object's primary key, I don't expect any separators. The pk represents the object's unique identifier in a database or collection -- often used in increasing sequence.

Note: See TracTickets for help on using tickets.
Back to Top