def __get__(self, resource, resource_class): if resource is None: # Class level access. obj = self else: obj = get_nested_attribute(resource.get_entity(), self.entity_attr) return obj
def __make_specification(self): ref_attr, backref_attr = self._get_specification_attributes() #: Builds the filter specification. spec_fac = get_filter_specification_factory() crd = self.descriptor.cardinality if backref_attr is None: relatee = get_nested_attribute(self.relator, ref_attr) if crd.relatee == CARDINALITY_CONSTANTS.MANY: # This is potentially expensive as we may need to iterate over # a large collection to create the "contained" specification. if len(relatee) > 0: ids = [related.id for related in relatee] spec = spec_fac.create_contained('id', ids) else: # Create impossible search criterion. spec = spec_fac.create_equal_to('id', -1) else: if not relatee is None: spec = spec_fac.create_equal_to('id', relatee.id) else: # Create impossible search criterion. spec = spec_fac.create_equal_to('id', -1) else: if crd.relator == CARDINALITY_CONSTANTS.MANY: spec = spec_fac.create_contains(backref_attr, self.relator) else: spec = spec_fac.create_equal_to(backref_attr, self.relator) return spec
def relatee(self): ref_attr = self._get_specification_attributes()[0] try: rel = get_nested_attribute(self.relator, ref_attr) except AttributeError: rel = None return rel
def get_state_data(cls, entity): """ Returns the state data for the given entity. This also works for unmanaged entities. """ attrs = get_domain_class_attribute_iterator(type(entity)) return dict([(attr, get_nested_attribute(entity, attr.entity_attr)) for attr in attrs if not attr.entity_attr is None])
def __get__(self, resource, resource_class): if not resource is None: ent = get_nested_attribute(resource.get_entity(), self.entity_attr) if not ent is None: fac = get_member_class(self.attr_type).as_related_member member = fac(ent, self.make_relationship(resource)) else: member = None else: # class level access member = self return member
def __action_one_direction(self, cardinality_relatee, rel_op, relator, related, attr_name, safe): if cardinality_relatee == CARDINALITY_CONSTANTS.ONE: if rel_op == RELATION_OPERATIONS.ADD: set_nested_attribute(relator, attr_name, related) elif rel_op == RELATION_OPERATIONS.REMOVE: set_nested_attribute(relator, attr_name, None) else: relatee = get_nested_attribute(relator, attr_name) if rel_op == RELATION_OPERATIONS.ADD: if not (safe and related in relatee): # FIXME: Assuming a list here. relatee.append(related) elif rel_op == RELATION_OPERATIONS.REMOVE: # FIXME: Assuming a list here. if safe: try: relatee.remove(related) except ValueError: pass else: relatee.remove(related)
def _get_proxied_attribute_value(self, attribute): return get_nested_attribute(self._data, attribute.entity_attr)
def _get_relation_attribute_value(self, attribute): return get_nested_attribute(self._data, attribute.entity_attr)