124
124
from canonical.launchpad.webapp.vocabulary import (
125
125
BatchedCountableIterator,
126
126
CountableIterator,
127
FilteredVocabularyBase,
128
129
NamedSQLObjectHugeVocabulary,
129
130
NamedSQLObjectVocabulary,
130
131
SQLObjectVocabularyBase,
132
134
from lp.app.browser.tales import DateTimeFormatterAPI
133
135
from lp.app.interfaces.launchpad import ILaunchpadCelebrities
902
904
text = ensure_unicode(text).lower()
903
905
return self._doSearch(text=text)
905
def searchForTerms(self, query=None):
907
def searchForTerms(self, query=None, vocab_filter=None):
906
908
"""See `IHugeVocabulary`."""
907
909
results = self.search(query)
908
910
return CountableIterator(results.count(), results, self.toTerm)
1141
1143
return obj in self._get_teams()
1144
class ActiveMailingListVocabulary:
1146
class ActiveMailingListVocabulary(FilteredVocabularyBase):
1145
1147
"""The set of all active mailing lists."""
1147
1149
implements(IHugeVocabulary)
1221
1223
""" % sqlvalues(text, MailingListStatus.ACTIVE),
1222
1224
clauseTables=['Person'])
1224
def searchForTerms(self, query=None):
1226
def searchForTerms(self, query=None, vocab_filter=None):
1225
1227
"""See `IHugeVocabulary`."""
1226
1228
results = self.search(query)
1227
1229
return CountableIterator(results.count(), results, self.toTerm)
1644
1646
return self.toTerm(search_result)
1645
1647
raise LookupError(token)
1647
def searchForTerms(self, query=None):
1649
def searchForTerms(self, query=None, vocab_filter=None):
1648
1650
"""See `SQLObjectVocabularyBase`."""
1649
1651
results = self._doSearch(query)
1650
1652
if type(results) is list:
1752
class DistroSeriesDerivationVocabulary:
1754
class DistroSeriesDerivationVocabulary(FilteredVocabularyBase):
1753
1755
"""A vocabulary source for series to derive from.
1755
1757
Once a distribution has a series that has derived from a series in another
1816
1818
title = "%s: %s" % (series.distribution.displayname, series.title)
1817
1819
return SimpleTerm(series, series.id, title)
1819
def searchForTerms(self, query=None):
1821
def searchForTerms(self, query=None, vocab_filter=None):
1820
1822
"""See `IHugeVocabulary`."""
1821
1823
results = self.searchParents(query)
1822
1824
return CountableIterator(len(results), results, self.toTerm)
1871
1873
return self.find_terms(where)
1874
class DistroSeriesDifferencesVocabulary:
1876
class DistroSeriesDifferencesVocabulary(FilteredVocabularyBase):
1875
1877
"""A vocabulary source for differences relating to a series.
1877
1879
Specifically, all `DistroSeriesDifference`s relating to a derived series.
1929
1931
"""Return the term for a `DistroSeriesDifference`."""
1930
1932
return SimpleTerm(dsd, dsd.id)
1932
def searchForTerms(self, query=None):
1934
def searchForTerms(self, query=None, vocab_filter=None):
1933
1935
"""See `IHugeVocabulary`."""
1934
1936
results = self.searchForDifferences()
1935
1937
return CountableIterator(results.count(), results, self.toTerm)
1942
1944
return DistroSeriesDifference.getForDistroSeries(self.distroseries)
1947
class VocabularyFilterProject(VocabularyFilter):
1948
# A filter returning just projects.
1951
return super(VocabularyFilter, cls).__new__(
1952
cls, 'PROJECT', 'Product',
1953
'Display search results associated with products')
1956
def filter_terms(self):
1957
return [PillarName.product != None]
1960
class VocabularyFilterProjectGroup(VocabularyFilter):
1961
# A filter returning just project groups.
1964
return super(VocabularyFilter, cls).__new__(
1965
cls, 'PROJECTGROUP', 'Project',
1966
'Display search results associated with projects')
1969
def filter_terms(self):
1970
return [PillarName.project != None]
1973
class VocabularyFilterDistribution(VocabularyFilter):
1974
# A filter returning just distros.
1977
return super(VocabularyFilter, cls).__new__(
1978
cls, 'DISTRO', 'Distribution',
1979
'Display search results associated with distributions')
1982
def filter_terms(self):
1983
return [PillarName.distribution != None]
1945
1986
class PillarVocabularyBase(NamedSQLObjectHugeVocabulary):
1946
1987
"""Active `IPillar` objects vocabulary."""
1947
1988
displayname = 'Needs to be overridden'
1948
1989
_table = PillarName
1992
PROJECT_FILTER = VocabularyFilterProject()
1993
PROJECTGROUP_FILTER = VocabularyFilterProjectGroup()
1994
DISTRO_FILTER = VocabularyFilterDistribution()
1996
def supportedFilters(self):
1997
return [self.ALL_FILTER]
1951
1999
def toTerm(self, obj):
1952
2000
"""See `IVocabulary`."""
1953
2001
if type(obj) == int:
1972
2020
def __contains__(self, obj):
1973
2021
raise NotImplementedError
1975
def searchForTerms(self, query=None):
2023
def searchForTerms(self, query=None, vocab_filter=None):
1977
2025
return self.emptySelectResults()
1978
2026
query = ensure_unicode(query).lower()
1983
2031
if self._filter:
1984
2032
equal_clauses.extend(self._filter)
1985
2033
like_clauses.extend(self._filter)
2035
equal_clauses.extend(vocab_filter.filter_terms)
2036
like_clauses.extend(vocab_filter.filter_terms)
1986
2037
ranked_results = store.execute(
2012
2063
return IDistribution.providedBy(obj)
2065
def supportedFilters(self):
2068
self.PROJECT_FILTER,
2015
2072
class DistributionOrProductOrProjectGroupVocabulary(PillarVocabularyBase):
2016
2073
"""Active `IProduct`, `IProjectGroup` or `IDistribution` vocabulary."""
2025
2082
return IDistribution.providedBy(obj)
2084
def supportedFilters(self):
2087
self.PROJECT_FILTER,
2088
self.PROJECTGROUP_FILTER,
2028
2092
class FeaturedProjectVocabulary(
2029
2093
DistributionOrProductOrProjectGroupVocabulary):
2149
2213
distribution, package_name = self.getDistributionAndPackageName(token)
2150
2214
return self.toTerm(package_name, distribution)
2152
def searchForTerms(self, query=None):
2216
def searchForTerms(self, query=None, vocab_filter=None):
2153
2217
"""See `IHugeVocabulary`."""
2155
2219
return EmptyResultSet()