Skip to content

Text input filter

TextInputFilter

Renders simple eq admin filter form with text input and submit button.

choices(self, cl)

Return choices ready to be output in the template.

changelist is the ChangeList to be displayed.

Source code in pxd_admin_extensions/filters/text_input.py
def choices(self, cl):
    all_choice = {
        'selected': self.value() is None,
        'query_string': cl.get_query_string({}, [self.parameter_name]),
        'display': _('Clear'),
    }

    return ({
        'get_query': cl.params,
        'current_value': self.value(),
        'all_choice': all_choice,
        'parameter_name': self.parameter_name
    },)

expected_parameters(self)

Returns the list of parameter names that are expected from the request's query string and that will be used by this filter.

Source code in pxd_admin_extensions/filters/text_input.py
def expected_parameters(self):
    """Returns the list of parameter names that are expected from the
    request's query string and that will be used by this filter.
    """
    return [self.parameter_name]

has_output(self)

Return True if some choices would be output for this filter.

Source code in pxd_admin_extensions/filters/text_input.py
def has_output(self):
    return True

queryset(self, request, queryset)

Return the filtered queryset.

Source code in pxd_admin_extensions/filters/text_input.py
def queryset(self, request, queryset):
    if self.value():
        return queryset.filter(**{self.parameter_name: self.value()})

value(self)

Returns the value (in string format) provided in the request's query string for this filter, if any. If the value wasn't provided then returns None.

Source code in pxd_admin_extensions/filters/text_input.py
def value(self):
    """Returns the value (in string format) provided in the request's
    query string for this filter, if any. If the value wasn't provided then
    returns None.
    """
    return self.used_parameters.get(self.parameter_name, None)