本文整理汇总了Python中vdm.sqlalchemy.base.SQLAlchemySession.setattr方法的典型用法代码示例。如果您正苦于以下问题:Python SQLAlchemySession.setattr方法的具体用法?Python SQLAlchemySession.setattr怎么用?Python SQLAlchemySession.setattr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vdm.sqlalchemy.base.SQLAlchemySession
的用法示例。
在下文中一共展示了SQLAlchemySession.setattr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: purge_revision
# 需要导入模块: from vdm.sqlalchemy.base import SQLAlchemySession [as 别名]
# 或者: from vdm.sqlalchemy.base.SQLAlchemySession import setattr [as 别名]
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()
示例2: make_latest_pending_package_active
# 需要导入模块: from vdm.sqlalchemy.base import SQLAlchemySession [as 别名]
# 或者: from vdm.sqlalchemy.base.SQLAlchemySession import setattr [as 别名]
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()
示例3: make_latest_pending_package_active
# 需要导入模块: from vdm.sqlalchemy.base import SQLAlchemySession [as 别名]
# 或者: from vdm.sqlalchemy.base.SQLAlchemySession import setattr [as 别名]
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()