Ticket #15938: unlocalize_maxLength2.diff

File unlocalize_maxLength2.diff, 4.1 KB (added by Filippo Squillace, 13 years ago)

Lev's patch with test_prepopulated_maxlength_localized that use the override_settings decorator (I got rid of some new lines).

  • django/contrib/admin/templates/admin/prepopulated_fields_js.html

     
     1{% load l10n %}
    12<script type="text/javascript">
    23(function($) {
    34    var field = null;
     
    78        id: '#{{ field.field.auto_id }}',
    89        dependency_ids: [],
    910        dependency_list: [],
    10         maxLength: {{ field.field.field.max_length|default_if_none:"50" }}
     11        maxLength: {{ field.field.field.max_length|default_if_none:"50"|unlocalize }}
    1112    };
    1213
    1314    {% for dependency in field.dependencies %}
  • tests/regressiontests/admin_views/admin.py

     
    2222    Gadget, Villain, SuperVillain, Plot, PlotDetails, CyclicOne, CyclicTwo,
    2323    WorkHour, Reservation, FoodDelivery, RowLevelChangePermissionModel, Paper,
    2424    CoverLetter, Story, OtherStory, Book, Promo, ChapterXtra1, Pizza, Topping,
    25     Album, Question, Answer, ComplexSortedPerson)
     25    Album, Question, Answer, ComplexSortedPerson, PrePopulatedPostLargeSlug)
    2626
    2727
    2828def callable_year(dt_value):
     
    469469    list_filter = ('employee',)
    470470
    471471
     472class PrePopulatedPostLargeSlugAdmin(admin.ModelAdmin):
     473    prepopulated_fields = {
     474        'slug' : ('title',)
     475    }
     476 
    472477site = admin.AdminSite(name="admin")
    473478site.register(Article, ArticleAdmin)
    474479site.register(CustomArticle, CustomArticleAdmin)
     
    538543from django.contrib.auth.admin import UserAdmin, GroupAdmin
    539544site.register(User, UserAdmin)
    540545site.register(Group, GroupAdmin)
     546site.register(PrePopulatedPostLargeSlug, PrePopulatedPostLargeSlugAdmin)
  • tests/regressiontests/admin_views/tests.py

     
    2828from django.utils.encoding import iri_to_uri
    2929from django.utils.html import escape
    3030from django.utils.http import urlencode
     31from django.test.utils import override_settings
    3132
    3233# local test models
    3334from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,
     
    27562757        self.assertNotContains(response, "id: '#id_slug'")
    27572758        self.assertNotContains(response, "field['dependency_ids'].push('#id_title');")
    27582759        self.assertNotContains(response, "id: '#id_prepopulatedsubpost_set-0-subslug',")
     2760   
     2761    @override_settings(USE_THOUSAND_SEPARATOR = True, USE_L10N = True)
     2762    def test_prepopulated_maxlength_localized(self):
     2763        """
     2764        Regression test for #15938: if USE_THOUSAND_SEPARATOR is set, make sure
     2765        that maxLength (in the javascript) is rendered without separators.
     2766        """
     2767        response = self.client.get('/test_admin/admin/admin_views/prepopulatedpostlargeslug/add/')
     2768        self.assertContains(response, "maxLength: 1000") # instead of 1,000
    27592769
    27602770class ReadonlyTest(TestCase):
    27612771    urls = "regressiontests.admin_views.urls"
  • tests/regressiontests/admin_views/models.py

     
    538538    age = models.PositiveIntegerField()
    539539    is_employee = models.NullBooleanField()
    540540
     541class PrePopulatedPostLargeSlug(models.Model):
     542    """
     543    Regression test for #15938: a large max_length for the slugfield must not
     544    be localized in prepopulated_fields_js.html or it might end up breaking
     545    the javascript (ie, using THOUSAND_SEPARATOR ends up with maxLength=1,000)
     546    """
     547    title = models.CharField(max_length=100)
     548    published = models.BooleanField()
     549    slug = models.SlugField(max_length=1000)
     550   
     551 No newline at end of file
Back to Top