当前位置: 首页>>代码示例>>Python>>正文


Python Document.by_keys方法代码示例

本文整理汇总了Python中aleph.model.Document.by_keys方法的典型用法代码示例。如果您正苦于以下问题:Python Document.by_keys方法的具体用法?Python Document.by_keys怎么用?Python Document.by_keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aleph.model.Document的用法示例。


在下文中一共展示了Document.by_keys方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ingest_upload

# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import by_keys [as 别名]
def ingest_upload(collection_id):
    require(request.authz.can(collection_id, request.authz.WRITE))
    sync = get_flag('sync')
    meta, foreign_id = _load_metadata()
    parent_id = _load_parent(collection_id, meta)
    upload_dir = mkdtemp(prefix='aleph.upload.')
    try:
        path = None
        content_hash = None
        for storage in request.files.values():
            path = safe_filename(storage.filename, default='upload')
            path = os.path.join(upload_dir, path)
            storage.save(path)
            content_hash = checksum(path)
        document = Document.by_keys(collection_id=collection_id,
                                    parent_id=parent_id,
                                    foreign_id=foreign_id,
                                    content_hash=content_hash)
        document.update(meta)
        document.schema = Document.SCHEMA
        if content_hash is None:
            document.schema = Document.SCHEMA_FOLDER
        ingest_document(document, path,
                        role_id=request.authz.id,
                        content_hash=content_hash)
    finally:
        shutil.rmtree(upload_dir)

    if document.collection.casefile:
        # Make sure collection counts are always accurate.
        update_document(document, sync=sync)
    return jsonify({
        'status': 'ok',
        'id': stringify(document.id)
    }, status=201)
开发者ID:pudo,项目名称:aleph,代码行数:37,代码来源:ingest_api.py

示例2: test_load_sample_directory

# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import by_keys [as 别名]
 def test_load_sample_directory(self):
     samples_path = self.get_fixture_path('samples')
     document = Document.by_keys(collection_id=self.collection.id,
                                 foreign_id='samples')
     db.session.commit()
     db.session.refresh(document)
     ingest_document(document, samples_path)
     assert Document.all().count() == 5, Document.all().count()
开发者ID:pudo,项目名称:aleph,代码行数:10,代码来源:test_ingest.py

示例3: test_load_pdf_file

# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import by_keys [as 别名]
 def test_load_pdf_file(self):
     pdf_path = self.get_fixture_path('demo.pdf')
     document = Document.by_keys(collection_id=self.collection.id,
                                 foreign_id='demo.pdf')
     db.session.commit()
     db.session.refresh(document)
     ingest_document(document, pdf_path)
     assert Document.all().count() == 1, Document.all().count()
开发者ID:pudo,项目名称:aleph,代码行数:10,代码来源:test_ingest.py

示例4: test_load_csv_file

# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import by_keys [as 别名]
    def test_load_csv_file(self):
        csv_path = self.get_fixture_path('experts.csv')
        document = Document.by_keys(collection_id=self.collection.id,
                                    foreign_id='experts.csv')
        document.file_name = 'experts.csv'
        db.session.commit()
        db.session.refresh(document)
        ingest_document(document, csv_path)
        assert Document.all().count() == 1, Document.all().count()
        records = db.session.query(DocumentRecord).all()
        assert len(records) == 14, len(records)
        rec0 = records[0]
        assert str(rec0.id) in repr(rec0), repr(rec0)
        assert 'nationality' in rec0.data, rec0.data
        assert 'name' in rec0.data, rec0.data

        doc = rec0.document
        doc.delete_records()
        records = db.session.query(DocumentRecord).all()
        assert len(records) == 0, len(records)
开发者ID:pudo,项目名称:aleph,代码行数:22,代码来源:test_ingest.py


注:本文中的aleph.model.Document.by_keys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。