本文整理汇总了Python中lmkp.models.meta.DBSession.delete方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.delete方法的具体用法?Python DBSession.delete怎么用?Python DBSession.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lmkp.models.meta.DBSession
的用法示例。
在下文中一共展示了DBSession.delete方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: comment_delete
# 需要导入模块: from lmkp.models.meta import DBSession [as 别名]
# 或者: from lmkp.models.meta.DBSession import delete [as 别名]
def comment_delete(request):
_ = request.translate
"""
Delete an existing comment
"""
ret = {'success': False}
# check if id of comment is available
if request.POST['id'] is None:
ret['message'] = 'No comment id provided.'
return ret
# check if user has permissions to delete comments
if not isinstance(has_permission(
'moderate', request.context, request), ACLAllowed):
ret['message'] = 'Permission denied.'
return ret
# query comment
comment = Session.query(Comment).get(request.POST['id'])
if comment is None:
ret['message'] = 'Comment not found.'
return ret
Session.delete(comment)
ret['message'] = _('Comment successfully deleted.')
# if we've come this far, set success to 'True'
ret['success'] = True
return ret
示例2: delete_all_values
# 需要导入模块: from lmkp.models.meta import DBSession [as 别名]
# 或者: from lmkp.models.meta.DBSession import delete [as 别名]
def delete_all_values(request):
stack = []
nbr_activities = 0
for activity in Session.query(Activity).all():
nbr_changesets = 0
for changeset in Session.query(A_Changeset).filter(A_Changeset.fk_activity == activity.id).all():
Session.delete(changeset)
nbr_changesets += 1
nbr_tag_groups = 0
for tag_group in Session.query(A_Tag_Group).filter(A_Tag_Group.fk_activity == activity.id).all():
tag_group.fk_a_tag = None
Session.flush()
nbr_tags = 0
for tag in Session.query(A_Tag).join(A_Tag_Group, A_Tag_Group.id == A_Tag.fk_a_tag_group).join(Activity).filter(and_(A_Tag.fk_a_tag_group == tag_group.id,
A_Tag_Group.fk_activity == activity.id)).all():
Session.delete(tag)
nbr_tags += 1
Session.flush()
Session.delete(tag_group)
nbr_tag_groups += 1
Session.delete(activity)
nbr_activities += 1
try:
stack.append(str(nbr_changesets) + ' changesets deleted.')
stack.append(str(nbr_tags) + ' tags deleted.')
stack.append(str(nbr_tag_groups) + ' tag groups deleted.')
stack.append(str(nbr_activities) + ' activities deleted.')
except UnboundLocalError:
pass
return {'messagestack': stack}
示例3: delete_sample_values
# 需要导入模块: from lmkp.models.meta import DBSession [as 别名]
# 或者: from lmkp.models.meta.DBSession import delete [as 别名]
def delete_sample_values(request):
# Trigger
delete_fix_data = True
stack = []
# BEGIN delete sample values ----------------------------------------------------------------------
stack.append('--- sample data ---')
inv_counter = 0
all_involvements_beneficiary = Session.query(Involvement).filter(Involvement.fk_stakeholder_role == 4).all()
for aib in all_involvements_beneficiary:
inv_counter += 1
Session.delete(aib)
if (inv_counter > 0):
stack.append(str(inv_counter) + ' involvements deleted.')
all_a_reviews = Session.query(A_Changeset_Review).filter(or_(A_Changeset_Review.comment.like('[active] Review_Comment %'), A_Changeset_Review.comment.like('[overwritten] Review_Comment %'), A_Changeset_Review.comment.like('[deleted] Review_Comment %'), A_Changeset_Review.comment.like('[overwritten] Review_Comment %'))).all()
rev_counter = 0
for aar in all_a_reviews:
rev_counter += 1
Session.delete(aar)
if (rev_counter > 0):
stack.append(str(rev_counter) + " a_changeset_reviews deleted.")
all_sh_reviews = Session.query(SH_Changeset_Review).filter(or_(SH_Changeset_Review.comment.like('[active] Review_Comment %'), SH_Changeset_Review.comment.like('[overwritten] Review_Comment %'), SH_Changeset_Review.comment.like('[deleted] Review_Comment %'), SH_Changeset_Review.comment.like('[overwritten] Review_Comment %'))).all()
rev_counter = 0
for asr in all_sh_reviews:
rev_counter += 1
Session.delete(asr)
if (rev_counter > 0):
stack.append(str(rev_counter) + " sh_changeset_reviews deleted.")
#all_activities = Session.query(Activity).join(A_Changeset).filter(or_(A_Changeset.source.like('[active] Source %'), A_Changeset.source.like('[pending] Source %'), A_Changeset.source.like('[overwritten] Source %'), A_Changeset.source.like('[deleted] Source %'), A_Changeset.source.like('[overwritten] Source %'))).all()
# Select all activities
all_activities = Session.query(Activity)
act_counter = 0
tag_counter = 0
ch_counter = 0
for aa in all_activities:
# delete tag groups
tag_groups = aa.tag_groups
tag_groups.main_tag = None
for tg in tag_groups:
tg.fk_a_tag = None
tags = tg.tags
for t in tags:
tag_counter += 1
Session.delete(t)
Session.delete(tg)
# delete changesets
changesets = aa.changesets
for ch in changesets:
ch_counter += 1
Session.delete(ch)
# delete activities
act_counter += 1
Session.delete(aa)
if (tag_counter > 0 or act_counter > 0 or ch_counter > 0):
stack.append(str(tag_counter) + " a_tags deleted.")
stack.append(str(ch_counter) + " a_changesets deleted.")
stack.append(str(act_counter) + " activities deleted.")
all_stakeholders = Session.query(Stakeholder).join(SH_Changeset).filter(or_(SH_Changeset.source.like('[active] Source %'), SH_Changeset.source.like('[pending] Source %'), SH_Changeset.source.like('[overwritten] Source %'), SH_Changeset.source.like('[deleted] Source %'), SH_Changeset.source.like('[overwritten] Source %'))).all()
sh_counter = 0
tag_counter = 0
ch_counter = 0
for alls in all_stakeholders:
# delete tag groups
tag_groups = alls.tag_groups
for tg in tag_groups:
tags = tg.tags
for t in tags:
tag_counter += 1
Session.delete(t)
Session.delete(tg)
# delete changesets
changesets = alls.changesets
for ch in changesets:
ch_counter += 1
Session.delete(ch)
# delete activities
sh_counter += 1
Session.delete(alls)
if (tag_counter > 0 or sh_counter > 0 or ch_counter > 0):
stack.append(str(tag_counter) + " sh_tags deleted.")
stack.append(str(ch_counter) + " sh_changesets deleted.")
stack.append(str(act_counter) + " stakeholders deleted.")
# END delete sample values ------------------------------------------------------------------------
# -- BEGIN delete fix data ------------------------------------------------------------------------
if (delete_fix_data):
stack.append('--- fix data ---')
# a_tags
counter = 0
all_a_keys = Session.query(A_Key).all()
for ak in all_a_keys:
Session.delete(ak)
counter += 1
if (counter > 0):
stack.append(str(counter) + " a_keys deleted.")
# a_values
counter = 0
all_a_values = Session.query(A_Value).all()
for av in all_a_values:
Session.delete(av)
#.........这里部分代码省略.........