Ticket #12105: 12105-r11858.diff

File 12105-r11858.diff, 2.5 KB (added by Travis Cline <travis.cline@…>, 15 years ago)
  • django/contrib/admin/views/main.py

    diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
    index df0fd9f..d34bb1b 100644
    a b class ChangeList(object):  
    185185            if key.endswith('__in'):
    186186                lookup_params[key] = value.split(',')
    187187
     188            # if key ends with __isnull, special case '' and false
     189            if key.endswith('__isnull'):
     190                if value.lower() in ('', 'false'):
     191                    lookup_params[key] = False
     192                else:
     193                    lookup_params[key] = True
     194
    188195        # Apply lookup parameters from the query string.
    189196        try:
    190197            qs = qs.filter(**lookup_params)
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 3124071..dfabe21 100644
    a b class AdminViewBasicTest(TestCase):  
    6565
    6666    def testBasicEditGet(self):
    6767        """
    68         A smoke test to ensureGET on the change_view works.
     68        A smoke test to ensure GET on the change_view works.
    6969        """
    7070        response = self.client.get('/test_admin/%s/admin_views/section/1/' % self.urlbit)
    7171        self.failUnlessEqual(response.status_code, 200)
    class AdminViewBasicTest(TestCase):  
    205205        response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'color__id__exact': 'StringNotInteger!'})
    206206        self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
    207207
     208    def testIsNullLookups(self):
     209        """Ensure is_null is handled correctly."""
     210        response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit)
     211        self.assertTrue('3 articles' in response.content, '"3 articles" missing from response')
     212        response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'section__isnull': 'false'})
     213        self.assertTrue('3 articles' in response.content, '"3 articles" missing from response')
     214        response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'section__isnull': 'true'})
     215        self.assertTrue('0 articles' in response.content, '"0 articles" missing from response')
     216
    208217    def testLogoutAndPasswordChangeURLs(self):
    209218        response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit)
    210219        self.failIf('<a href="/test_admin/%s/logout/">' % self.urlbit not in response.content)
Back to Top