djangofloor.views.search

Abstract global-site search view

The DjangoFloor base template provides a site-wide search field. The corresponding search view is defined by the setting DF_SITE_SEARCH_VIEW and should be a class-based view. Here is an example of abstract class-based view, as well as a generic model search view and an example of working search view (searching across users)

class djangofloor.views.search.ModelSearchView(**kwargs)[source]

Reusable search view that search through a Django model

format_result(obj)[source]

basic format for objects

get_query(request, pattern)[source]

compute the query based on the provided pattern and searched attributes

model

searched model

alias of User

searched_attributes = []

all attributes that are compared to the pattern

sort_attributes = []

if provided, results are ordered by these attributes

class djangofloor.views.search.SiteSearchView(**kwargs)[source]

Abstract site-wide search view

format_result(obj)[source]

format a single result as a table row

formatted_header()[source]

provide the header row

formatted_results(paginated_results)[source]

return all results in a formatted form as an iterator

get(request, *args, **kwargs)[source]

Get method (use GET data for filling the form)

get_or_post(request, form)[source]

Common result, the same for GET or POST data. Takes a bound form.

get_query(request, pattern)[source]

given the search pattern provided by the user, return the search query

get_template_values(request)[source]

provide extra template values

post(request)[source]

Post method (use POST data for filling the form)

template_name = 'djangofloor/bootstrap3/search.html'

used template for displaying the results

class djangofloor.views.search.UserSearchView(**kwargs)[source]

Search across all users with username and email

format_result(obj)[source]

a bit better formatted row

formatted_header()[source]

headers row

searched_attributes = ['username__icontains', 'email__icontains']

search in usernames and emails

sort_attributes = ['last_name', 'first_name']

order results by last_name and first_name