def _search_elements(self, query) -> IResultSet: interfaces = normalize_to_tuple(query.interfaces) if not interfaces: interfaces = (IResource,) interfaces_index = self._get_index("interfaces") if interfaces_index is None: # pragma: no branch return ResultSet(set(), 0, None) index_query = interfaces_index.all(interfaces) if query.root is not None: depth = query.depth or None path_index = self._get_index("path") index_query &= path_index.eq(query.root, depth=depth, include_origin=False) if query.indexes: for name, value in query.indexes.items(): index = self._get_index(name) index_query &= index.eq(value) if query.only_visible: visibility_index = self._get_index("private_visibility") index_query &= visibility_index.eq("visible") if query.allows: allowed_index = self._get_index("allowed") principals, permission = query.allows index_query &= allowed_index.allows(principals, permission) elements = index_query.execute(resolver=None) if query.references: index = self._get_index("reference") for reference in query.references: referencence_elements = index.search_with_order(reference) referencence_elements.resolver = elements.resolver elements = referencence_elements.intersect(elements) return elements
def validator(node, value): child_node_value = node.get_value(value, child_node.name) referenced = normalize_to_tuple(child_node_value) for resource in referenced: sheet = get_sheet(resource, isheet, registry=registry) post_pool_type = _get_post_pool_type(sheet.schema) post_pool = _get_post_pool(resource, post_pool_type) _validate_post_pool(node, (context,), post_pool)
def _get_interfaces_index_query(self, query) -> Query: interfaces_value = self._get_query_value(query.interfaces) if not interfaces_value: return None interfaces_comparator = self._get_query_comparator(query.interfaces) interfaces_index = self.get_index("interfaces") if interfaces_comparator is None: interfaces_value = normalize_to_tuple(interfaces_value) index_query = interfaces_index.all(interfaces_value) else: index_comparator = getattr(interfaces_index, interfaces_comparator) index_query = index_comparator(interfaces_value) return index_query
def _get_interfaces_index_query(self, query) -> Query: interfaces_value = self._get_query_value(query.interfaces) if not interfaces_value: return None interfaces_comparator = self._get_query_comparator(query.interfaces) interfaces_index = self.get_index('interfaces') if interfaces_comparator is None: interfaces_value = normalize_to_tuple(interfaces_value) index_query = interfaces_index.all(interfaces_value) else: index_comparator = getattr(interfaces_index, interfaces_comparator) index_query = index_comparator(interfaces_value) return index_query
def _search_elements(self, query) -> IResultSet: interfaces_index = self.get_index('interfaces') if interfaces_index is None: # pragma: no branch return ResultSet(set(), 0, None) interfaces_value = self._get_query_value(query.interfaces) if not interfaces_value: interfaces_value = (IResource, ) interfaces_comparator = self._get_query_comparator(query.interfaces) if interfaces_comparator is None: interfaces_value = normalize_to_tuple(interfaces_value) index_query = interfaces_index.all(interfaces_value) else: index_comparator = getattr(interfaces_index, interfaces_comparator) index_query = index_comparator(interfaces_value) if query.root is not None: depth = query.depth or None path_index = self.get_index('path') index_query &= path_index.eq(query.root, depth=depth, include_origin=False) if query.indexes: for index_name, value in query.indexes.items(): index = self.get_index(index_name) comparator = self._get_query_comparator(value) if comparator is None: index_comparator = index.eq else: index_comparator = getattr(index, comparator) index_value = self._get_query_value(value) index_query &= index_comparator(index_value) if query.only_visible: visibility_index = self.get_index('private_visibility') index_query &= visibility_index.eq('visible') if query.allows: allowed_index = self.get_index('allowed') principals, permission = query.allows index_query &= allowed_index.allows(principals, permission) elements = index_query.execute(resolver=None) if query.references: index = self.get_index('reference') for reference in query.references: referencence_elements = index.search_with_order(reference) referencence_elements.resolver = elements.resolver elements = referencence_elements.intersect(elements) return elements
def _search_elements(self, query) -> IResultSet: interfaces_index = self.get_index('interfaces') if interfaces_index is None: # pragma: no branch return ResultSet(set(), 0, None) interfaces_value = self._get_query_value(query.interfaces) if not interfaces_value: interfaces_value = (IResource,) interfaces_comparator = self._get_query_comparator(query.interfaces) if interfaces_comparator is None: interfaces_value = normalize_to_tuple(interfaces_value) index_query = interfaces_index.all(interfaces_value) else: index_comparator = getattr(interfaces_index, interfaces_comparator) index_query = index_comparator(interfaces_value) if query.root is not None: depth = query.depth or None path_index = self.get_index('path') index_query &= path_index.eq(query.root, depth=depth, include_origin=False) if query.indexes: for index_name, value in query.indexes.items(): index = self.get_index(index_name) comparator = self._get_query_comparator(value) if comparator is None: index_comparator = index.eq else: index_comparator = getattr(index, comparator) index_value = self._get_query_value(value) index_query &= index_comparator(index_value) if query.only_visible: visibility_index = self.get_index('private_visibility') index_query &= visibility_index.eq('visible') if query.allows: allowed_index = self.get_index('allowed') principals, permission = query.allows index_query &= allowed_index.allows(principals, permission) elements = index_query.execute(resolver=None) if query.references: index = self.get_index('reference') for reference in query.references: referencence_elements = index.search_with_order(reference) referencence_elements.resolver = elements.resolver elements = referencence_elements.intersect(elements) return elements
def _omit_omit_keys(self, appstruct: dict, omit): omit_keys = normalize_to_tuple(omit) return remove_keys_from_dict(appstruct, keys_to_remove=omit_keys)
def call_fut(self, value): from adhocracy_core.utils import normalize_to_tuple return normalize_to_tuple(value)