Exemplo n.º 1
0
 def as_related_collection(cls, aggregate, relationship):
     """
     Creates a new relationship collection with a relationship aggregate
     and the relationship's relator as a parent.
     """
     rel_coll = cls.create_from_aggregate(aggregate,
                                          relationship=relationship)
     # The member at the origin of the relationship is the parent.
     rel_coll.__parent__ = relationship.relator
     # Set the collection's name to the descriptor's resource
     # attribute name.
     rel_coll.__name__ = \
         slug_from_identifier(relationship.descriptor.resource_attr)
     return rel_coll
Exemplo n.º 2
0
 def as_related_collection(cls, aggregate, relationship):
     """
     Creates a new relationship collection with a relationship aggregate
     and the relationship's relator as a parent.
     """
     rel_coll = cls.create_from_aggregate(aggregate,
                                          relationship=relationship)
     # The member at the origin of the relationship is the parent.
     rel_coll.__parent__ = relationship.relator
     # Set the collection's name to the descriptor's resource
     # attribute name.
     rel_coll.__name__ = \
         slug_from_identifier(relationship.descriptor.resource_attr)
     return rel_coll
Exemplo n.º 3
0
 def __get__(self, resource, resource_class):
     if not resource is None:
         obj = self._get_nested(resource.get_entity(), self.entity_attr)
         if not obj is None:
             if not self.is_nested:
                 member = as_member(obj)
                 coll = get_root_collection(member)
                 member.__parent__ = coll
             else:
                 member = as_member(obj, parent=resource)
                 member.__name__ = slug_from_identifier(self.resource_attr)
         else:
             member = obj
     else:
         # class level access
         member = self
     return member
Exemplo n.º 4
0
    def __make_collection(self, resource, parent, children):
        # Create a new collection.
        rc_parent = resource.__parent__
        rc_repo = None
        while not rc_parent is None:
            rc_repo = getattr(rc_parent, '__repository__', None)
            if not rc_repo is None:
                break
            else:
                rc_parent = rc_parent.__parent__
        # Create a new collection.
#        if not resource.__parent__ is None:
#            # Use the resource repository that created this resource's
#            # root collection to create the new collection.
#            rc_repo = getattr(resource.__parent__, '__repository__', None)
#            if rc_repo is None:
#                for rc in lineage(resource.__parent__):
#                    rc_repo = getattr(rc, '__repository__', None)
#                    if not rc_repo is None:
#                        break
        if not rc_repo is None:
            coll = rc_repo.get_collection(self.attr_type)
        else:
            # This is a floating member.
            coll = create_staging_collection(self.attr_type)
        # Set up entity access in the new collection.
        agg_relationship = Relationship(parent, children,
                                        backref=self.__entity_backref)
        agg = coll.get_aggregate()
        agg.set_relationship(agg_relationship)
        # Set up URL generation.
        if self.is_nested:
            # Make URL generation relative to the resource.
            coll.__parent__ = resource
            # Set the collection's name to the descriptor's resource
            # attribute name.
            coll.__name__ = slug_from_identifier(self.resource_attr)
        else:
            # Add a filter specification for the root collection through
            # a relationship.
            coll_relationship = Relationship(resource, coll,
                                             backref=self.__resource_backref)
            coll.set_relationship(coll_relationship)
        return coll
Exemplo n.º 5
0
 def __preprocess_attribute(self, attr_name):
     return slug_from_identifier(attr_name)
Exemplo n.º 6
0
 def _as_string(self):
     return self.__cql_format % dict(attr=self.attr_name,
                                     op=slug_from_identifier(self.op_name),
                                     val=self.value)
Exemplo n.º 7
0
 def _as_string(self):
     #: Returns this CQL expression as a string.
     return self.__cql_format % dict(attr=self.attr_name,
                                     op=slug_from_identifier(self.op_name),
                                     val=self.value)
Exemplo n.º 8
0
 def test_get_slug_from_identifier(self):
     self.assert_equal(slug_from_identifier('a_b'), 'a-b')
Exemplo n.º 9
0
 def _as_string(self):
     #: Returns this CQL expression as a string.
     return self.__cql_format % dict(attr=self.attr_name,
                                     op=slug_from_identifier(self.op_name),
                                     val=self.value)
Exemplo n.º 10
0
 def test_get_slug_from_identifier(self):
     self.assert_equal(slug_from_identifier('a_b'), 'a-b')
Exemplo n.º 11
0
 def test_get_slug_from_identifier(self):
     self.assert_equal(slug_from_identifier("a_b"), "a-b")