Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #15938 -- Prevented the `max_length` number in the admin `prepo…

…pulated_fields` javascript to be localized when `USE_THOUSAND_SEPARATOR` is turned on. Thanks to Lev Maximov, Mathieu Agopian and feel.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17033 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2e2689c7c0436f21d25e40f90f9d386311c776f9 1 parent c1a014b
@jphalip jphalip authored
View
3  django/contrib/admin/templates/admin/prepopulated_fields_js.html
@@ -1,3 +1,4 @@
+{% load l10n %}
<script type="text/javascript">
(function($) {
var field = null;
@@ -7,7 +8,7 @@
id: '#{{ field.field.auto_id }}',
dependency_ids: [],
dependency_list: [],
- maxLength: {{ field.field.field.max_length|default_if_none:"50" }}
+ maxLength: {{ field.field.field.max_length|default_if_none:"50"|unlocalize }}
};
{% for dependency in field.dependencies %}
View
8 tests/regressiontests/admin_views/admin.py
@@ -22,7 +22,7 @@
Gadget, Villain, SuperVillain, Plot, PlotDetails, CyclicOne, CyclicTwo,
WorkHour, Reservation, FoodDelivery, RowLevelChangePermissionModel, Paper,
CoverLetter, Story, OtherStory, Book, Promo, ChapterXtra1, Pizza, Topping,
- Album, Question, Answer, ComplexSortedPerson)
+ Album, Question, Answer, ComplexSortedPerson, PrePopulatedPostLargeSlug)
def callable_year(dt_value):
@@ -469,6 +469,11 @@ class WorkHourAdmin(admin.ModelAdmin):
list_filter = ('employee',)
+class PrePopulatedPostLargeSlugAdmin(admin.ModelAdmin):
+ prepopulated_fields = {
+ 'slug' : ('title',)
+ }
+
site = admin.AdminSite(name="admin")
site.register(Article, ArticleAdmin)
site.register(CustomArticle, CustomArticleAdmin)
@@ -538,3 +543,4 @@ class WorkHourAdmin(admin.ModelAdmin):
from django.contrib.auth.admin import UserAdmin, GroupAdmin
site.register(User, UserAdmin)
site.register(Group, GroupAdmin)
+site.register(PrePopulatedPostLargeSlug, PrePopulatedPostLargeSlugAdmin)
View
10 tests/regressiontests/admin_views/models.py
@@ -538,3 +538,13 @@ class ComplexSortedPerson(models.Model):
age = models.PositiveIntegerField()
is_employee = models.NullBooleanField()
+class PrePopulatedPostLargeSlug(models.Model):
+ """
+ Regression test for #15938: a large max_length for the slugfield must not
+ be localized in prepopulated_fields_js.html or it might end up breaking
+ the javascript (ie, using THOUSAND_SEPARATOR ends up with maxLength=1,000)
+ """
+ title = models.CharField(max_length=100)
+ published = models.BooleanField()
+ slug = models.SlugField(max_length=1000)
+
View
10 tests/regressiontests/admin_views/tests.py
@@ -28,6 +28,7 @@
from django.utils.encoding import iri_to_uri
from django.utils.html import escape
from django.utils.http import urlencode
+from django.test.utils import override_settings
# local test models
from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,
@@ -2756,6 +2757,15 @@ def test_prepopulated_off(self):
self.assertNotContains(response, "id: '#id_slug'")
self.assertNotContains(response, "field['dependency_ids'].push('#id_title');")
self.assertNotContains(response, "id: '#id_prepopulatedsubpost_set-0-subslug',")
+
+ @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
class ReadonlyTest(TestCase):
urls = "regressiontests.admin_views.urls"
Please sign in to comment.
Something went wrong with that request. Please try again.