1944
1944
"""Active `IPillar` objects vocabulary."""
1945
1945
displayname = 'Needs to be overridden'
1946
1946
_table = PillarName
1949
1949
def toTerm(self, obj):
1950
1950
"""See `IVocabulary`."""
1951
if type(obj) == int:
1952
return self.toTerm(PillarName.get(obj))
1951
1953
if IPillarName.providedBy(obj):
1952
1954
assert obj.active, 'Inactive object %s %d' % (
1953
1955
obj.__class__.__name__, obj.id)
1968
1970
def __contains__(self, obj):
1969
1971
raise NotImplementedError
1973
def searchForTerms(self, query=None):
1975
return self.emptySelectResults()
1976
query = ensure_unicode(query).lower()
1977
store = IStore(PillarName)
1978
equal_clauses = [PillarName.name == query]
1980
PillarName.name != query, PillarName.name.contains_string(query)]
1982
equal_clauses.extend(self._filter)
1983
like_clauses.extend(self._filter)
1984
ranked_results = store.execute(
1987
(PillarName.id, PillarName.name, SQL('100 AS rank')),
1988
tables=[PillarName],
1989
where=And(*equal_clauses)),
1991
(PillarName.id, PillarName.name, SQL('50 AS rank')),
1992
tables=[PillarName],
1993
where=And(*like_clauses)),
1994
limit=self._limit, order_by=(
1995
Desc(SQL('rank')), PillarName.name), all=True))
1996
results = [row[0] for row in list(ranked_results)]
1997
return self.iterator(len(results), results, self.toTerm)
1972
2000
class DistributionOrProductVocabulary(PillarVocabularyBase):
1973
2001
"""Active `IDistribution` or `IProduct` objects vocabulary."""
1974
2002
displayname = 'Select a project'
1976
-- An active product/distro.
1978
AND (product IS NOT NULL OR distribution IS NOT NULL)
1981
-- Or an alias for an active product/distro.
1983
SELECT id FROM PillarName
1984
WHERE active IS TRUE AND
1985
(product IS NOT NULL OR distribution IS NOT NULL))
2003
_filter = [PillarName.project == None, PillarName.active == True]
1989
2005
def __contains__(self, obj):
1990
2006
if IProduct.providedBy(obj):
1997
2013
class DistributionOrProductOrProjectGroupVocabulary(PillarVocabularyBase):
1998
2014
"""Active `IProduct`, `IProjectGroup` or `IDistribution` vocabulary."""
1999
2015
displayname = 'Select a project'
2000
_filter = PillarName.q.active == True
2016
_filter = [PillarName.active == True]
2002
2018
def __contains__(self, obj):
2003
2019
if IProduct.providedBy(obj) or IProjectGroup.providedBy(obj):