本文整理汇总了Python中cms.db.Session.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Session.delete方法的具体用法?Python Session.delete怎么用?Python Session.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cms.db.Session
的用法示例。
在下文中一共展示了Session.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AddTestcasesHandler
# 需要导入模块: from cms.db import Session [as 别名]
# 或者: from cms.db.Session import delete [as 别名]
class AddTestcasesHandler(BaseHandler):
"""Add several testcases to a dataset.
"""
@require_permission(BaseHandler.PERMISSION_ALL)
def get(self, dataset_id):
dataset = self.safe_get_item(Dataset, dataset_id)
task = dataset.task
self.r_params = self.render_params()
self.r_params["task"] = task
self.r_params["dataset"] = dataset
self.render("add_testcases.html", **self.r_params)
@require_permission(BaseHandler.PERMISSION_ALL)
def post(self, dataset_id):
fallback_page = "/dataset/%s/testcases/add_multiple" % dataset_id
# TODO: this method is quite long, some splitting is needed.
dataset = self.safe_get_item(Dataset, dataset_id)
task = dataset.task
try:
archive = self.request.files["archive"][0]
except KeyError:
self.application.service.add_notification(
make_datetime(),
"Invalid data",
"Please choose tests archive.")
self.redirect(fallback_page)
return
public = self.get_argument("public", None) is not None
overwrite = self.get_argument("overwrite", None) is not None
# Get input/output file names templates, or use default ones.
input_template = self.get_argument("input_template", "input.*")
output_template = self.get_argument("output_template", "output.*")
input_re = re.compile(re.escape(input_template).replace("\\*",
"(.*)") + "$")
output_re = re.compile(re.escape(output_template).replace("\\*",
"(.*)") + "$")
task_name = task.name
self.sql_session.close()
fp = StringIO(archive["body"])
try:
with zipfile.ZipFile(fp, "r") as archive_zfp:
tests = dict()
# Match input/output file names to testcases' codenames.
for filename in archive_zfp.namelist():
match = input_re.match(filename)
if match:
codename = match.group(1)
if codename not in tests:
tests[codename] = [None, None]
tests[codename][0] = filename
else:
match = output_re.match(filename)
if match:
codename = match.group(1)
if codename not in tests:
tests[codename] = [None, None]
tests[codename][1] = filename
skipped_tc = []
overwritten_tc = []
added_tc = []
for codename, testdata in tests.iteritems():
# If input or output file isn't found, skip it.
if not testdata[0] or not testdata[1]:
continue
self.sql_session = Session()
# Check, whether current testcase already exists.
dataset = self.safe_get_item(Dataset, dataset_id)
task = dataset.task
if codename in dataset.testcases:
# If we are allowed, remove existing testcase.
# If not - skip this testcase.
if overwrite:
testcase = dataset.testcases[codename]
self.sql_session.delete(testcase)
if not self.try_commit():
skipped_tc.append(codename)
continue
overwritten_tc.append(codename)
else:
skipped_tc.append(codename)
continue
# Add current testcase.
try:
input_ = archive_zfp.read(testdata[0])
output = archive_zfp.read(testdata[1])
except Exception as error:
self.application.service.add_notification(
make_datetime(),
#.........这里部分代码省略.........