コード例 #1
0
ファイル: descriptors.py プロジェクト: papagr/everest
 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
コード例 #2
0
ファイル: descriptors.py プロジェクト: b8va/everest
 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
コード例 #3
0
ファイル: relationship.py プロジェクト: b8va/everest
 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
コード例 #4
0
 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
コード例 #5
0
 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
コード例 #6
0
    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])
コード例 #7
0
ファイル: state.py プロジェクト: b8va/everest
    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])
コード例 #8
0
ファイル: descriptors.py プロジェクト: helixyte/everest
 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
コード例 #9
0
ファイル: descriptors.py プロジェクト: papagr/everest
 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
コード例 #10
0
ファイル: relationship.py プロジェクト: b8va/everest
 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)
コード例 #11
0
ファイル: relationship.py プロジェクト: papagr/everest
 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)
コード例 #12
0
ファイル: traversal.py プロジェクト: papagr/everest
 def _get_proxied_attribute_value(self, attribute):
     return get_nested_attribute(self._data, attribute.entity_attr)
コード例 #13
0
ファイル: traversal.py プロジェクト: papagr/everest
 def _get_relation_attribute_value(self, attribute):
     return get_nested_attribute(self._data, attribute.entity_attr)
コード例 #14
0
ファイル: traversal.py プロジェクト: b8va/everest
 def _get_proxied_attribute_value(self, attribute):
     return get_nested_attribute(self._data, attribute.entity_attr)
コード例 #15
0
ファイル: traversal.py プロジェクト: b8va/everest
 def _get_relation_attribute_value(self, attribute):
     return get_nested_attribute(self._data, attribute.entity_attr)