Example #1
0
 def create_member(self, entity):
     """
     Creates a new member resource from the given entity and adds it to
     this collection.
     """
     member = as_member(entity)
     self.add(member)
     return member
Example #2
0
 def __iter__(self):
     """
     Returns an iterator over the (possibly filtered and ordered)
     collection.
     """
     for obj in self.__aggregate.iterator():
         rc = as_member(obj, parent=self)
         yield rc
Example #3
0
 def __iter__(self):
     """
     Returns an iterator over the (possibly filtered and ordered)
     collection.
     """
     for obj in self.__aggregate.iterator():
         rc = as_member(obj, parent=self)
         yield rc
Example #4
0
 def create_member(self, entity):
     """
     Creates a new member resource from the given entity and adds it to
     this collection.
     """
     member = as_member(entity)
     self.add(member)
     return member
Example #5
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
Example #6
0
    def update(self, data, target=None):
        """
        Updates this collection from the given data.

        :param data: Any object that can be adapted to
          :class:`everest.interfaces.IDataTraversalProxyAdapter`.
        :returns: New updated member.
        """
        if not target is None:
            target = target.get_entity()
        updated_entity = self.__aggregate.update(data, target=target)
        return as_member(updated_entity, parent=self)
Example #7
0
    def update(self, data, target=None):
        """
        Updates this collection from the given data.

        :param data: Any object that can be adapted to
          :class:`everest.interfaces.IDataTraversalProxyAdapter`.
        :returns: New updated member.
        """
        if not target is None:
            target = target.get_entity()
        updated_entity = self.__aggregate.update(data, target=target)
        return as_member(updated_entity, parent=self)
Example #8
0
    def __getitem__(self, key):
        """
        Gets a member (by name).

        :param key: the name of the member
        :type key: :class:`string` or :class:`unicode`
        :raises: :class:`everest.exceptions.DuplicateException` if more than
          one member is found for the given key value.
        :returns: object implementing
          :class:`everest.resources.interfaces.IMemberResource`
        """
        ent = self.__aggregate.get_by_slug(key)
        if ent is None:
            raise KeyError(key)
        rc = as_member(ent, parent=self)
        return rc