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


Python Session.object_session方法代码示例

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


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

示例1: from_config

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import object_session [as 别名]
 def from_config(cls, library):
     _db = Session.object_session(library)
     integration = ExternalIntegration.lookup(
         _db, ExternalIntegration.MARC_EXPORT,
         ExternalIntegration.CATALOG_GOAL, library=library
     )
     if not integration:
         raise CannotLoadConfiguration(
             "No MARC export service is configured for this library"
         )
     return cls(_db, library, integration)
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:13,代码来源:marc.py

示例2: create_record

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import object_session [as 别名]
    def create_record(cls, work, annotator, force_create=False, integration=None):
        """Build a complete MARC record for a given work."""
        if callable(annotator):
            annotator = annotator()

        if isinstance(work, BaseMaterializedWork):
            pool = work.license_pool
        else:
            pool = work.active_license_pool()
        if not pool:
            return None

        edition = pool.presentation_edition
        identifier = pool.identifier

        _db = Session.object_session(work)

        record = None
        existing_record = getattr(work, annotator.marc_cache_field)
        if existing_record and not force_create:
            record = Record(data=existing_record.encode('utf-8'), force_utf8=True)

        if not record:
            record = Record(leader=annotator.leader(work), force_utf8=True)
            annotator.add_control_fields(record, identifier, pool, edition)
            annotator.add_isbn(record, identifier)

            # TODO: The 240 and 130 fields are for translated works, so they can be grouped even
            # though they have different titles. We do not group editions of the same work in
            # different languages, so we can't use those yet.

            annotator.add_title(record, edition)
            annotator.add_contributors(record, edition)
            annotator.add_publisher(record, edition)
            annotator.add_physical_description(record, edition)
            annotator.add_audience(record, work)
            annotator.add_series(record, edition)
            annotator.add_system_details(record)
            annotator.add_ebooks_subject(record)

            data = record.as_marc()
            if isinstance(work, BaseMaterializedWork):
                setattr(pool.work, annotator.marc_cache_field, data)
            else:
                setattr(work, annotator.marc_cache_field, data)

        # Add additional fields that should not be cached.
        annotator.annotate_work_record(work, pool, edition, identifier, record, integration)

        return record
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:52,代码来源:marc.py

示例3: add_isbn

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import object_session [as 别名]
 def add_isbn(cls, record, identifier):
     # Add the ISBN if we have one.
     isbn = None
     if identifier.type == Identifier.ISBN:
         isbn = identifier
     if not isbn:
         _db = Session.object_session(identifier)
         identifier_ids = identifier.equivalent_identifier_ids()[identifier.id]
         isbn = _db.query(Identifier).filter(
             Identifier.type==Identifier.ISBN).filter(
             Identifier.id.in_(identifier_ids)).order_by(
             Identifier.id).first()
     if isbn:
         record.add_field(
             Field(
                 tag="020",
                 indicators=[" "," "],
                 subfields=[
                     "a", isbn.identifier,
                 ]))
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:22,代码来源:marc.py

示例4: for_collection

# 需要导入模块: from model import Session [as 别名]
# 或者: from model.Session import object_session [as 别名]
    def for_collection(cls, collection, use_sitewide=False):
        """Create a MirrorUploader for the given Collection.

        :param collection: Use the mirror configuration for this Collection.

        :param use_sitewide: If there's no mirror for this specific Collection,
            should we return a sitewide mirror instead?

        :return: A MirrorUploader, or None if the Collection has no
            mirror integration.
        """
        integration = collection.mirror_integration
        if not integration:
            if use_sitewide:
                try:
                    from model import Session
                    _db = Session.object_session(collection)
                    return cls.sitewide(_db)
                except CannotLoadConfiguration, e:
                    return None
            else:
                return None
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:24,代码来源:mirror.py


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