Commit 2e2689c7 authored by Julien Phalip's avatar Julien Phalip
Browse files

Fixed #15938 -- Prevented the `max_length` number in the admin...

Fixed #15938 -- Prevented the `max_length` number in the admin `prepopulated_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
parent c1a014bb
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
{% 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 %}
+7 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ from .models import (Article, Chapter, Account, Media, Child, Parent, Picture,
    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 @@ from django.contrib.auth.models import User, Group
from django.contrib.auth.admin import UserAdmin, GroupAdmin
site.register(User, UserAdmin)
site.register(Group, GroupAdmin)
site.register(PrePopulatedPostLargeSlug, PrePopulatedPostLargeSlugAdmin) 
+10 −0
Original line number Diff line number Diff line
@@ -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)
    
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ from django.utils.cache import get_max_age
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,
@@ -2757,6 +2758,15 @@ class PrePopulatedTest(TestCase):
        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"
    fixtures = ['admin-views-users.xml']