def is_satisfied_by(self, candidate): cand_value = self._get_candidate_value(candidate) if IMemberResource.providedBy(self.attr_value): # pylint: disable=E1101 attr_value = self.attr_value.get_entity() elif ICollectionResource.providedBy(self.attr_value): # pylint: disable=E1101 attr_value = self.attr_value.get_aggregate() else: attr_value = self.attr_value return self.operator.apply(cand_value, attr_value)
def add(self, member): """ Adds the given member to this collection. :param member: Member to add. :type member: Object implementing :class:`everest.resources.interfaces.IMemberResource` :raise ValueError: if a member with the same name exists """ if IMemberResource.providedBy(member): #pylint: disable=E1101 member.__parent__ = self data = member.get_entity() else: data = member self.__aggregate.add(data)
def remove(self, member): """ Removes the given member from this collection. :param member: Member to remove. :type member: Object implementing :class:`everest.resources.interfaces.IMemberResource` :raise ValueError: if the member can not be found in this collection """ is_member = IMemberResource.providedBy(member) #pylint: disable=E1101 if is_member: data = member.get_entity() else: data = member self.__aggregate.remove(data) if is_member: member.__parent__ = None
def __prepare_criterion(self, attr, op, val): if op is None: # (None, '$exists'): if IMemberResource.providedBy(val): # pylint: disable=E1101 attr = '%s.$id' % attr val = getattr(val.get_entity(), '_id') crit = {attr:val} # if op is None: # crit = {attr:val} # else: # crit = {attr:{op:val}} elif op == '$in': if ICollectionResource.providedBy(val): # pylint: disable=E1101 val = [getattr(mb.get_entity(), '_id') for mb in val] attr = '%s.$id' % attr crit = {attr:{op:val}} elif op == IN_RANGE.name: from_value, to_value = val crit = {'$and':[{attr:{'$gte':from_value}}, {attr:{'$lte':to_value}}]} else: crit = {attr:{op:val}} return crit