def __call__(self, request): system = ResourceTreeTraverser.__call__(self, request) context = system['context'] view_name = system['view_name'] if IResource.providedBy(context) and '.' in view_name: # pylint: disable=E1101 rc_name, repr_name = view_name.split('.') try: child_rc = context[rc_name] except KeyError: pass else: if IResource.providedBy(child_rc): # pylint: disable=E1101 system['context'] = child_rc system['view_name'] = repr_name return system
def __call__(self, request): system = ModelGraphTraverser.__call__(self, request) context = system['context'] view_name = system['view_name'] if IResource.providedBy(context) and '.' in view_name: # pylint: disable=E1101 rc_name, repr_name = view_name.split('.') try: child_rc = context[rc_name] except KeyError: pass else: if IResource.providedBy(child_rc): # pylint: disable=E1101 system['context'] = child_rc system['view_name'] = repr_name return system
def is_satisfied_by(self, candidate): cand_value = self._get_candidate_value(candidate) if IResource.providedBy(self.__attr_value): # pylint: disable=E1101 attr_value = self.__attr_value.get_entity() else: attr_value = self.__attr_value return self.operator.apply(cand_value, attr_value)
def __preprocess_value(self, value): if isinstance(value, basestring): result = '"%s"' % value elif IResource.providedBy(value): # pylint: disable=E1101 result = resource_to_url(value) else: result = str(value) return result
def __preprocess_value(self, value): if isinstance(value, string_types): result = '"%s"' % value elif IResource.providedBy(value): # pylint: disable=E1101 result = '"%s"' % resource_to_url(value) else: result = str(value) return result
def make_relationship(self, relator, direction=RELATIONSHIP_DIRECTIONS.BIDIRECTIONAL): """ Create a relationship object for this attribute from the given relator and relationship direction. """ if IEntity.providedBy(relator): # pylint:disable=E1101 rel = DomainRelationship(relator, self, direction=direction) elif IResource.providedBy(relator): # pylint:disable=E1101 rel = ResourceRelationship(relator, self, direction=direction) else: raise ValueError( 'Invalid relator argument "%s" for ' "relationship; must provide IEntity or " "IResource." % relator ) return rel
def make_relationship(self, relator, direction=RELATIONSHIP_DIRECTIONS.BIDIRECTIONAL): """ Create a relationship object for this attribute from the given relator and relationship direction. """ if IEntity.providedBy(relator): # pylint:disable=E1101 rel = DomainRelationship(relator, self, direction=direction) elif IResource.providedBy(relator): # pylint:disable=E1101 rel = ResourceRelationship(relator, self, direction=direction) else: raise ValueError('Invalid relator argument "%s" for ' 'relationship; must provide IEntity or ' 'IResource.' % relator) return rel
def __build(self, attribute_name, sql_op, *values): # Builds an SQL expression from the given (possibly dotted) # attribute name, SQL operation name, and values. exprs = [] infos = OrmAttributeInspector.inspect(self._entity_class, attribute_name) count = len(infos) for idx, info in enumerate(infos): kind, entity_attr = info if idx == count - 1: # args = \ [val.get_entity() if IResource.providedBy(val) else val # pylint: disable=E1101 for val in values] expr = getattr(entity_attr, sql_op)(*args) elif kind == RESOURCE_ATTRIBUTE_KINDS.MEMBER: expr = entity_attr.has exprs.insert(0, expr) elif kind == RESOURCE_ATTRIBUTE_KINDS.COLLECTION: expr = entity_attr.any exprs.insert(0, expr) return func_reduce(lambda g, h: h(g), exprs, expr)