1
# Copyright 2009 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
7
'PackageSearchViewBase'
10
from canonical.launchpad.webapp.batching import BatchNavigator
11
from canonical.launchpad.webapp.publisher import LaunchpadView
12
from lp.services.propertycache import cachedproperty
15
class PackageSearchViewBase(LaunchpadView):
16
"""A common package search interface"""
19
"""Save the search text set by the user."""
20
self.text = self.request.get("text", None)
21
if self.text is not None:
22
# The user may have URL hacked a query string with more than one
23
# "text" parameter. We'll take the last one.
24
if isinstance(self.text, list):
25
self.text = self.text[-1]
26
self.text = self.text.strip()
27
# We need to ensure the form on the refreshed page shows the
29
self.request.form['text'] = self.text
32
def search_requested(self):
33
"""Return whether the current view included a search request."""
34
return self.text is not None
38
"""Return the number of matched search results."""
39
return self.batchnav.batch.total()
43
"""Return whether detailed results should be provided."""
44
return self.matches <= 5
48
"""Return the batch navigator for the search results."""
49
return BatchNavigator(self.search_results, self.request)
52
def search_results(self):
53
"""Search for packages matching the request text.
55
Try to find the packages that match the given text, then present
56
those as a list. Cache previous results so the search is only done
59
return self.contextSpecificSearch()
61
def contextSpecificSearch(self):
62
"""Call the context specific search."""
63
raise NotImplementedError(
64
"do_context_specific_search needs to be implemented in sub-class"