55
55
spec.target == self.context.target
56
56
and spec not in self.context.all_blocked)]
58
def _doSearch(self, query):
59
"""Return terms where query is in the text of name
60
or title, or matches the full text index.
58
def toTerm(self, obj):
59
return SimpleTerm(obj, obj.name, obj.title)
61
def getTermByToken(self, token):
62
"""See `zope.schema.interfaces.IVocabularyTokenized`.
64
The tokens for specifications are just the name of the spec.
66
spec = self.context.target.getSpecification(token)
68
filtered = self._filter_specs([spec])
70
return self.toTerm(filtered[0])
71
raise LookupError(token)
73
def search(self, query):
74
"""See `SQLObjectVocabularyBase.search`.
76
We find specs where query is in the text of name or title, or matches
77
the full text index and then filter out ineligible specs using
81
return CountableIterator(0, [])
66
82
quoted_query = quote_like(query)
68
84
(Specification.name LIKE %s OR
72
88
% (quoted_query, quoted_query, quoted_query))
73
89
all_specs = Specification.select(sql_query, orderBy=self._orderBy)
75
return self._filter_specs(all_specs)
77
def toTerm(self, obj):
78
return SimpleTerm(obj, obj.name, obj.title)
80
def getTermByToken(self, token):
81
search_results = self._doSearch(token)
82
for search_result in search_results:
83
if search_result.name == token:
84
return self.toTerm(search_result)
85
raise LookupError(token)
87
def search(self, query):
88
candidate_specs = self._doSearch(query)
89
return CountableIterator(len(candidate_specs),
90
candidate_specs = self._filter_specs(all_specs)
91
return CountableIterator(len(candidate_specs), candidate_specs)
92
94
def _all_specs(self):
93
all_specs = self.context.target.specifications(
95
return self.context.target.specifications(
94
96
filter=[SpecificationFilter.ALL],
95
97
prejoin_people=False)
96
return self._filter_specs(all_specs)
98
99
def __iter__(self):
99
return (self.toTerm(spec) for spec in self._all_specs())
100
return (self.toTerm(spec)
101
for spec in self._filter_specs(self._all_specs))
101
103
def __contains__(self, obj):
102
# We don't use self._all_specs here, since it will call
103
# self._filter_specs(all_specs) which will cause all the specs
104
# to be loaded, whereas obj in all_specs will query a single object.
105
all_specs = self.context.target.specifications(
106
filter=[SpecificationFilter.ALL],
107
prejoin_people=False)
108
return obj in all_specs and len(self._filter_specs([obj])) > 0
104
return obj in self._all_specs and len(self._filter_specs([obj])) > 0