def __init__(self, context, schema): if not IComposedQuery.providedBy(context): raise ValueError('context must provide IComposedQuery') if not IInterface.providedBy(schema): raise ValueError('schema provided must be interface') self.context = context self.schema = schema
def get_query(self, name): attr = '_v_query_%s' % name q = getattr(self, attr, None) if q is None: schema = self.form_definition().schema composed = queryAdapter(self, IComposedQuery, name=name) if not IComposedQuery.providedBy(composed): return None q = composed.build(schema) if not is_query_complete(q): return None # cannot perform query that is incomplete setattr(self, attr, q) # cache success return q
def grouped_query(group, schema): """ Given group as either an IFilterGroup or IComposedQuery, and a schema context to apply to, compose a repoze.catalog query using the set operator for the group/query object. """ if len(group) == 1: # avoid unneccessary wrapping when only one item in group if IComposedQuery.providedBy(group): return grouped_query(group[0], schema) else: return filter_query(group[0], schema) return setop_query(group.operator)(*[item.build(schema) for item in group])