Opened 13 years ago

Closed 13 years ago

Last modified 11 years ago

#743 closed defect (fixed)

new-admin: lookup_val2 not defined in BooleanFieldFilterSpec of django.contrib.admin.views.main

Reported by: Tom Tobin <korpios@…> Owned by: rjwittams
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When attempting to filter on a boolean value in the new-admin admin interface, the following exception is thrown:

TemplateSyntaxError:   While rendering at admin/filters, line 3 , caught exception:
  NameError: global name 'lookup_val2' is not defined

In django.contrib.admin.views.main, the value lookup_val2 is not defined on line 194 in the output method of class BooleanFieldFilterSpec (at the equality test lookup_val2 == 'True'):

    def output(self, cl):
        t = []
        t.append(_('<h3>By %s:</h3><ul>\n') % self.field.verbose_name)
        for k, v in (('All', None), ('Yes', '1'), ('No', '0')):
            t.append('<li%s><a href="%s">%s</a></li>\n' % \
                (((self.lookup_val == v and not self.lookup_val2) and ' class="selected"' or ''),
                cl.get_query_string( {self.lookup_kwarg: v}, [self.lookup_kwarg2]), k))
        if isinstance(self.field, meta.NullBooleanField):
            t.append('<li%s><a href="%s">%s</a></li>\n' % \
                (((lookup_val2 == 'True') and ' class="selected"' or ''),
                cl.get_query_string( {self.lookup_kwarg2: 'True'}, [self.lookup_kwarg]), 'Unknown'))
        return "".join(t)

It seems that changing lookup_val2 to self.lookup_val2 solves this issue.

Change History (4)

comment:1 Changed 13 years ago by Tom Tobin <korpios@…>

As of rev 1131, the relevant method is now choices:

    def choices(self, cl):
        for k, v in (('All', None), ('Yes', '1'), ('No', '0')):
            yield { 'selected' : self.lookup_val == v and not self.lookup_val2,
                    'query_string' : cl.get_query_string( {self.lookup_kwarg: v}, [self.lookup_kwarg2]),
                    'display': k
        if isinstance(self.field, meta.NullBooleanField):
            yield { 'selected' : lookup_val2 == 'True',
                    'query_string' : cl.get_query_string( {self.lookup_kwarg2: 'True'}, [self.lookup_kwarg]),
                    'display': _('Unknown')

yield { 'selected' : lookup_val2 == 'True', is now the line with this issue.

comment:2 Changed 13 years ago by Tom Tobin <korpios@…>

Owner: changed from Adrian Holovaty to rjwittams

Realizing that I should probably assign this to rjwittams since it's new-admin.

comment:3 Changed 13 years ago by rjwittams

Resolution: fixed
Status: newclosed

Fixed in [1138]

comment:4 Changed 11 years ago by korpios

Reporter: changed from Tom Tobin <korpios@…> to Tom Tobin <korpios@…>
Note: See TracTickets for help on using tickets.
Back to Top