Opened 14 years ago
Closed 13 years ago
#15938 closed Bug (fixed)
USE_THOUSAND_SEPARATOR breaks prepopulated_fields functionality
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | 1.3 |
Severity: | Normal | Keywords: | USE_THOUSAND_SEPARATOR prepopulated_fields |
Cc: | mathieu.agopian@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | yes | UI/UX: | no |
Description
# models.py from django.db import models class Book(models.Model): slug = models.CharField(max_length=1000) name = models.CharField(max_length=1000) # admin.py from django.contrib import admin import models class BookAdmin(admin.ModelAdmin): prepopulated_fields = { 'slug': ['name'], } admin.site.register(models.Book, BookAdmin) # settings.py USE_L10N = True USE_THOUSAND_SEPARATOR = True
This bug is present with most locales (including en
and en-gb
). Common values for DECIMAL_SEPARATOR
are space, comma and dot. The former two generate a js error in django-generated js code, the latter one results in wrong max_length
for slug field (1.000 = 1)
Disclaimer:
This example is somewhat artificial because NUMBER_GROUPING
is usually 3 and it doesn't make much sense to use slugs 1000 chars long.
So the severity of the bug is not at all high. But the bug there is.
The patch is against 1.3 but at the moment of writing the issue is present in trunk as well.
Attachments (4)
Change History (14)
by , 14 years ago
Attachment: | unlocalize.patch added |
---|
comment:1 by , 14 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 14 years ago
Cc: | added |
---|
comment:3 by , 14 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | unset |
Thanks lev for the update of the patch, looks good now. Sorry for that, but i missed the "needs tests" flag in my previous comment
by , 14 years ago
Attachment: | unlocalize_maxLength.diff added |
---|
Lev's patch with added regression tests
comment:5 by , 14 years ago
Needs tests: | unset |
---|
comment:6 by , 13 years ago
UI/UX: | unset |
---|
I also report the same bug and the Lev's patch works well. Does it need to be flagged RFC?
comment:7 by , 13 years ago
Patch needs improvement: | set |
---|
Patch doesn't apply cleanly and test_prepopulated_maxlength_localized
should use the override_settings
decorator.
comment:8 by , 13 years ago
I tried to look for override_settings documentation but I didn't find enough. Is it correct the use of it as follows?
@override_settings(USE_THOUSAND_SEPARATOR = True, USE_L10N = True) def test_prepopulated_maxlength_localized(self): """ Regression test for #15938: if USE_THOUSAND_SEPARATOR is set, make sure that maxLength (in the javascript) is rendered without separators. """ response = self.client.get('/test_admin/admin/admin_views/prepopulatedpostlargeslug/add/') self.assertContains(response, "maxLength: 1000") # instead of 1,000
by , 13 years ago
Attachment: | unlocalize_maxLength2.diff added |
---|
Lev's patch with test_prepopulated_maxlength_localized that use the override_settings decorator (I got rid of some new lines).
I've reproduced the issue, and can confirm everything stated in the ticket with one minor typo (it's
maxLength
in the javascript and notmax_length
).I'm marking this ticket as Accepted but the patch needs improvements: please remove the trailing comma, as it wasn't there in the first place, and it'll break in Internet Explorer.