MCPcopy Create free account
hub / github.com/django-haystack/django-haystack / build_page

Method build_page

haystack/views.py:91–117  ·  view source on GitHub ↗

Paginates the results appropriately. In case someone does not want to use Django's built-in pagination, it should be a simple matter to override this method to do what they would like.

(self)

Source from the content-addressed store, hash-verified

89 return self.form.search()
90
91 def build_page(self):
92 """
93 Paginates the results appropriately.
94
95 In case someone does not want to use Django's built-in pagination, it
96 should be a simple matter to override this method to do what they would
97 like.
98 """
99 try:
100 page_no = int(self.request.GET.get("page", 1))
101 except (TypeError, ValueError):
102 raise Http404("Not a valid number for page.")
103
104 if page_no < 1:
105 raise Http404("Pages should be 1 or greater.")
106
107 start_offset = (page_no - 1) * self.results_per_page
108 self.results[start_offset : start_offset + self.results_per_page]
109
110 paginator = Paginator(self.results, self.results_per_page)
111
112 try:
113 page = paginator.page(page_no)
114 except InvalidPage:
115 raise Http404("No such page!")
116
117 return (paginator, page)
118
119 def extra_context(self):
120 """

Callers 1

get_contextMethod · 0.95

Calls 1

getMethod · 0.80

Tested by

no test coverage detected