• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python base.SQLAlchemySession类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vdm.sqlalchemy.base.SQLAlchemySession的典型用法代码示例。如果您正苦于以下问题:Python SQLAlchemySession类的具体用法?Python SQLAlchemySession怎么用?Python SQLAlchemySession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: purge_revision

    def purge_revision(self, revision, leave_record=False):
        """Purge all changes associated with a revision.

        @param leave_record: if True leave revision in existence but
        change message to "PURGED: {date-time-of-purge}". If false
        delete revision object as well.

        Summary of the Algorithm
        ------------------------

        1. list all RevisionObjects affected by this revision
        2. check continuity objects and cascade on everything else ?
        3. crudely get all object revisions associated with this
        4. then check whether this is the only revision and delete
           the continuity object

        5. ALTERNATIVELY delete all associated object revisions then
           do a select on continutity to check which have zero
           associated revisions (should only be these ...) """

        to_purge = []
        SQLAlchemySession.setattr(self.session, "revisioning_disabled", True)
        self.session.autoflush = False
        for o in self.versioned_objects:
            revobj = o.__revision_class__
            items = self.session.query(revobj).filter_by(revision=revision).all()
            for item in items:
                continuity = item.continuity

                if continuity.revision == revision:  # must change continuity
                    trevobjs = (
                        self.session.query(revobj)
                        .join("revision")
                        .filter(revobj.continuity == continuity)
                        .order_by(Revision.timestamp.desc())
                        .all()
                    )
                    if len(trevobjs) == 0:
                        raise Exception("Should have at least one revision.")
                    if len(trevobjs) == 1:
                        to_purge.append(continuity)
                    else:
                        self.revert(continuity, trevobjs[1])
                        for num, obj in enumerate(trevobjs):
                            if num == 0:
                                continue
                            if "pending" not in obj.state:
                                obj.current = True
                                obj.expired_timestamp = datetime(9999, 12, 31)
                                self.session.add(obj)
                                break
                # now delete revision object
                self.session.delete(item)
            for cont in to_purge:
                self.session.delete(cont)
        if leave_record:
            revision.message = u"PURGED: %s" % datetime.now()
        else:
            self.session.delete(revision)
        self.commit_and_remove()
开发者ID:robert-chiniquy,项目名称:ckan,代码行数:60,代码来源:__init__.py


示例2: make_latest_pending_package_active

def make_latest_pending_package_active(context, data_dict):
    '''

    .. todo:: What does this function do?

    You must be authorized to update the dataset.

    :param id: the name or id of the dataset, e.g. ``'warandpeace'``
    :type id: string

    '''
    model = context['model']
    session = model.Session
    SQLAlchemySession.setattr(session, 'revisioning_disabled', True)
    id = _get_or_bust(data_dict, "id")
    pkg = model.Package.get(id)

    _check_access('make_latest_pending_package_active', context, data_dict)

    #packages
    q = session.query(model.PackageRevision).filter_by(id=pkg.id)
    _make_latest_rev_active(context, q)

    #resources
    for resource in pkg.resource_groups_all[0].resources_all:
        q = session.query(model.ResourceRevision).filter_by(id=resource.id)
        _make_latest_rev_active(context, q)

    #tags
    for tag in pkg.package_tag_all:
        q = session.query(model.PackageTagRevision).filter_by(id=tag.id)
        _make_latest_rev_active(context, q)

    #extras
    for extra in pkg.extras_list:
        q = session.query(model.PackageExtraRevision).filter_by(id=extra.id)
        _make_latest_rev_active(context, q)

    latest_revision = context.get('latest_revision')
    if not latest_revision:
        return

    q = session.query(model.Revision).filter_by(id=latest_revision)
    revision = q.first()
    revision.approved_timestamp = datetime.datetime.now()
    session.add(revision)

    if not context.get('defer_commit'):
        session.commit()
开发者ID:Caregivers,项目名称:ckan,代码行数:49,代码来源:update.py


示例3: make_latest_pending_package_active

def make_latest_pending_package_active(context, data_dict):

    model = context['model']
    session = model.Session
    SQLAlchemySession.setattr(session, 'revisioning_disabled', True)
    id = data_dict["id"]
    pkg = model.Package.get(id)

    check_access('make_latest_pending_package_active', context, data_dict)

    #packages
    q = session.query(model.PackageRevision).filter_by(id=pkg.id)
    _make_latest_rev_active(context, q)

    #resources
    for resource in pkg.resource_groups_all[0].resources_all:
        q = session.query(model.ResourceRevision).filter_by(id=resource.id)
        _make_latest_rev_active(context, q)

    #tags
    for tag in pkg.package_tag_all:
        q = session.query(model.PackageTagRevision).filter_by(id=tag.id)
        _make_latest_rev_active(context, q)

    #extras
    for extra in pkg.extras_list:
        q = session.query(model.PackageExtraRevision).filter_by(id=extra.id)
        _make_latest_rev_active(context, q)

    latest_revision = context.get('latest_revision')
    if not latest_revision:
        return

    q = session.query(model.Revision).filter_by(id=latest_revision)
    revision = q.first()
    revision.approved_timestamp = datetime.datetime.now()
    session.add(revision)

    if not context.get('defer_commit'):
        session.commit()
    session.remove()
开发者ID:slmnhq,项目名称:ckan,代码行数:41,代码来源:update.py


示例4: __create_sparl_resource

 def __create_sparl_resource(self, packagedb, endpoint_url):
     self.__delete_sparl_resource(packagedb)
     # Little hack to create a Revision for the SQLAlchemy Session provided by CKAN. Otherwise resource insertion fails because "No revision is currently set for this Session".
     SQLAlchemySession.set_revision(model.Session, Revision())
     packagedb.add_resource(url=endpoint_url, format=u'api/sparql', description=u'SPARQL endpoint', name=u'SPARQL endpoint', resource_type=u'api', extras={'generated_by_ckanextsparql': True})
     model.Session.commit()
开发者ID:jonlazaro,项目名称:ckanext-sparql,代码行数:6,代码来源:controller.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python commands.execCmd函数代码示例发布时间:2022-05-26
下一篇:
Python sync.sync函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap