Ejemplo n.º 1
0
    def _perform_delete_multiple(self, user_identifier, resources):
        """
        """
        oids = []
        ids = []

        for resource in resources:

            oids.append(ObjectId(resource.id))
            ids.append(resource.id)

            data = self.db[resource.rest_name].find_one({'_id': ObjectId(resource.id)})

            if not data:
                return ids

            for children_rest_name in resource.children_rest_names:

                children_key = '_%s' % children_rest_name

                if children_key not in data or not len(data[children_key]):  # pragma: no cover
                    continue

                klass = NURESTModelController.get_first_model_with_rest_name(children_rest_name)
                child_resources = [klass(id=identifier) for identifier in data[children_key]]

                # recursively delete children
                ids += self._perform_delete_multiple(user_identifier=user_identifier, resources=child_resources)

        self.db[resources[0].rest_name].remove({'_id': {'$in': oids}})

        return ids
Ejemplo n.º 2
0
    def from_dict(cls, data):
        """
        """
        instance = super(GAPushEvent, cls).from_dict(data=data)
        instance.entities = [NURESTModelController.get_first_model_with_rest_name(data['entityType'])(data=data['entities'][0])]

        return instance
Ejemplo n.º 3
0
    def from_dict(cls, data):
        """
        """
        instance = super(GAPushEvent, cls).from_dict(data=data)
        instance.entities = [
            NURESTModelController.get_first_model_with_rest_name(
                data['entityType'])(data=data['entities'][0])
        ]

        return instance
Ejemplo n.º 4
0
    def _perform_delete_multiple(self, user_identifier, resources):
        """
        """
        oids = []
        ids = []

        for resource in resources:

            oids.append(ObjectId(resource.id))
            ids.append(resource.id)

            data = self.db[resource.rest_name].find_one(
                {'_id': ObjectId(resource.id)})

            if not data:
                return ids

            for children_rest_name in resource.children_rest_names:

                children_key = '_%s' % children_rest_name

                if children_key not in data or not len(
                        data[children_key]):  # pragma: no cover
                    continue

                klass = NURESTModelController.get_first_model_with_rest_name(
                    children_rest_name)
                child_resources = [
                    klass(id=identifier) for identifier in data[children_key]
                ]

                # recursively delete children
                ids += self._perform_delete_multiple(
                    user_identifier=user_identifier, resources=child_resources)

        self.db[resources[0].rest_name].remove({'_id': {'$in': oids}})

        return ids
Ejemplo n.º 5
0
 def class_from_rest_name(self, rest_name):
     """
     """
     return NURESTModelController.get_first_model_with_rest_name(
         rest_name=rest_name)
Ejemplo n.º 6
0
 def class_from_rest_name(self, rest_name):
     """
     """
     return NURESTModelController.get_first_model_with_rest_name(rest_name=rest_name)
Ejemplo n.º 7
0
 def instantiate(self, resource_name):
     """
     """
     klass = NURESTModelController.get_first_model_with_rest_name(
         resource_name)
     return klass()
Ejemplo n.º 8
0
 def instantiate(self, resource_name):
     """
     """
     klass = NURESTModelController.get_first_model_with_rest_name(resource_name)
     return klass()