Ticket #19082: better_prepopulated_fields_logic_with_tests.diff

File better_prepopulated_fields_logic_with_tests.diff, 3.1 KB (added by Roman Gladkov, 12 years ago)

upgrade the patch. added test

  • django/contrib/admin/static/admin/js/prepopulate.js

    diff --git a/django/contrib/admin/static/admin/js/prepopulate.js b/django/contrib/admin/static/admin/js/prepopulate.js
    index 24f24f9..27a1498 100644
    a b  
    1414            field.change(function() {
    1515                field.data('_changed', true);
    1616            });
     17            if (field.val()) {
     18                field.data('_filled', true);
     19            } else {
     20                field.data('_filled', false);
     21            }
    1722
    1823            var populate = function () {
    1924                // Bail if the fields value has changed
    20                 if (field.data('_changed') == true) return;
     25                if (field.data('_changed') == true || field.data('_filled') == true) return;
    2126 
    2227                var values = [];
    2328                $.each(dependencies, function(i, field) {
  • django/contrib/admin/templatetags/admin_modify.py

    diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py
    index cecc6ed..19d696b 100644
    a b def prepopulated_fields_js(context):  
    99    the prepopulated fields for both the admin form and inlines.
    1010    """
    1111    prepopulated_fields = []
    12     if context['add'] and 'adminform' in context:
     12    if 'adminform' in context:
    1313        prepopulated_fields.extend(context['adminform'].prepopulated_fields)
    1414    if 'inline_admin_formsets' in context:
    1515        for inline_admin_formset in context['inline_admin_formsets']:
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 1633fba..b7a5dd9 100644
    a b class SeleniumPrePopulatedFirefoxTests(AdminSeleniumWebDriverTestCase):  
    32703270            slug2='option-one-tabular-inline-ignored-characters',
    32713271        )
    32723272
     3273    def test_populate_existing_entry(self):
     3274        item = MainPrepopulated.objects.create(
     3275            name=' this is the mAin nÀMë',
     3276            pubdate='2012-02-18',
     3277            status='option two',
     3278            slug1='main-name-2012-02-18',
     3279            slug2='option-two-main-name'
     3280        )
     3281        self.admin_login(username='super',
     3282                         password='secret',
     3283                         login_url='/test_admin/admin/')
     3284
     3285        self.selenium.get('%s%s' % (self.live_server_url,
     3286                                    '/test_admin/admin/admin_views/'
     3287                                    'mainprepopulated/{}/'.format(item.id)))
     3288
     3289        self.selenium.find_element_by_css_selector('#id_name').send_keys(' the best')
     3290
     3291        slug1 = self.selenium.find_element_by_css_selector('#id_slug1').get_attribute('value')
     3292        slug2 = self.selenium.find_element_by_css_selector('#id_slug2').get_attribute('value')
     3293
     3294        self.assertEqual(slug1, 'main-name-best-2012-02-18')
     3295        self.assertEqual(slug2, 'option-two-main-name-best')
     3296
     3297
    32733298
    32743299class SeleniumPrePopulatedChromeTests(SeleniumPrePopulatedFirefoxTests):
    32753300    webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
Back to Top