Example #1
0
    def get_file_guids(cls, materialized_path, provider, node=None):
        guids = []
        path = materialized_path.strip('/')
        file_obj = cls.load(path)
        if not file_obj:
            file_obj = TrashedFileNode.load(path)

        # At this point, file_obj may be an OsfStorageFile, an OsfStorageFolder, or a
        # TrashedFileNode. TrashedFileNodes do not have *File and *Folder subclasses, since
        # only osfstorage trashes folders. To search for children of TrashFileNodes
        # representing ex-OsfStorageFolders, we will reimplement the `children` method of the
        # Folder class here.
        if not file_obj.is_file:
            children = []
            if isinstance(file_obj, TrashedFileNode):
                children = file_obj.trashed_children.all()
            else:
                children = file_obj.children

            for item in children:
                guids.extend(cls.get_file_guids(item.path, provider, node=node))
        else:
            try:
                guid = Guid.find(Q('referent', 'eq', file_obj))[0]
            except IndexError:
                guid = None
            if guid:
                guids.append(guid._id)

        return sorted(guids)
Example #2
0
    def get_file_guids(cls, materialized_path, provider, node=None):
        guids = []
        path = materialized_path.strip('/')
        file_obj = cls.load(path)
        if not file_obj:
            file_obj = TrashedFileNode.load(path)

        # At this point, file_obj may be an OsfStorageFile, an OsfStorageFolder, or a
        # TrashedFileNode. TrashedFileNodes do not have *File and *Folder subclasses, since
        # only osfstorage trashes folders. To search for children of TrashFileNodes
        # representing ex-OsfStorageFolders, we will reimplement the `children` method of the
        # Folder class here.
        if not file_obj.is_file:
            children = []
            if isinstance(file_obj, TrashedFileNode):
                children = file_obj.trashed_children.all()
            else:
                children = file_obj.children

            for item in children:
                guids.extend(cls.get_file_guids(item.path, provider, node=node))
        else:
            try:
                guid = Guid.find(Q('referent', 'eq', file_obj))[0]
            except IndexError:
                guid = None
            if guid:
                guids.append(guid._id)

        return sorted(guids)
Example #3
0
    def test_querying_on_referent(self):
        user = UserFactory()

        guids = Guid.find(Q('referent', 'eq', user))
        assert user._id in guids.values_list('_id', flat=True)