Code

Opened 18 months ago

Closed 18 months ago

Last modified 18 months 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@… 18 months ago.

Download all attachments as: .zip

Change History (9)

Changed 18 months ago by zachborboa@…

comment:1 Changed 18 months 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 18 months 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 18 months 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 18 months ago by anonymous

Why should USE_THOUSAND_SEPARATOR not be enabled by default?

comment:5 Changed 18 months 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 18 months 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 18 months 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 18 months 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.