本文整理汇总了Python中pynformatics.models.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pynformatics.models.DBSession
的用法示例。
在下文中一共展示了DBSession.add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from pynformatics.models import DBSession [as 别名]
# 或者: from pynformatics.models.DBSession import add [as 别名]
def add(request):
try:
if (not RequestCheckUserCapability(request, 'moodle/ejudge_submits:comment')):
raise Exception("Auth Error")
author_id = RequestGetUserId(request)
run_id = request.params['run_id']
user_id = request.params['user_id']
# Это XSS
lines = html.escape(request.params['lines'])
comment = html.escape(request.params['comment'])
date = datetime.datetime.now()
commentary = Comment(date=date,
run_id=0, # TODO: 0 - заглушка. Новые run_id теперь кладуться в py_run_id.
contest_id=0, # TODO: Теперь contest_id всегда 0.
user_id=user_id,
author_user_id=author_id,
lines=lines,
comment=comment,
is_read=False,
py_run_id=run_id)
with transaction.manager:
DBSession.add(commentary)
return {"result": "ok"}
except Exception as e:
return {"result": "error", "message": e.__str__(), "stack": traceback.format_exc()}
示例2: add_hint
# 需要导入模块: from pynformatics.models import DBSession [as 别名]
# 或者: from pynformatics.models.DBSession import add [as 别名]
def add_hint(request):
try:
problem_id = int(html.escape(request.params['problem_id']))
contest_id = int(html.escape(request.params['contest_id']))
signature = html.escape(request.params['signature'])
comment = html.escape(request.params['comment'])
hint = Hint(problem_id, contest_id, 0, signature, comment)
with transaction.manager:
DBSession.add(hint)
return {"result" : "ok"}
except Exception as e:
return {"result" : "error", "message" : e.__str__(), "stack" : traceback.format_exc()}
示例3: getOrCreateContest
# 需要导入模块: from pynformatics.models import DBSession [as 别名]
# 或者: from pynformatics.models.DBSession import add [as 别名]
def getOrCreateContest(request, ejudge_contest_id):
strId = getContestStrId(ejudge_contest_id);
ejudgeCfg = EjudgeContestCfg("/home/judges/" + strId + "/conf/serve.cfg");
contest = DBSession.query(EjudgeContest).filter(EjudgeContest.ejudge_int_id == ejudge_contest_id).first()
tree = ElementTree()
tree.parse("/home/judges/data/contests/" + strId + ".xml")
contestName = tree.find("name").text
if (contest == None):
contest = EjudgeContest(contestName, request.matchdict['contest_id']);
with transaction.manager:
DBSession.add(contest);
return [contest, ejudgeCfg]
示例4: add
# 需要导入模块: from pynformatics.models import DBSession [as 别名]
# 或者: from pynformatics.models.DBSession import add [as 别名]
def add(request):
try:
link = html.escape(request.params['link'])
user_id = DBSession.query(User).filter(User.id == RequestGetUserId(request)).first()
stars = DBSession.query(Stars).filter_by(user_id=user_id.id).filter_by(link=link).all()
for star in stars:
DBSession.delete(star)
title = html.escape(request.params['title'])
stars = Stars(user_id, title, link)
with transaction.manager:
DBSession.add(stars);
return {"result" : "ok"}
except Exception as e:
return {"result" : "error", "message" : e.__str__(), "stack" : traceback.format_exc()}
示例5: add
# 需要导入模块: from pynformatics.models import DBSession [as 别名]
# 或者: from pynformatics.models.DBSession import add [as 别名]
def add(request):
try:
author_id = RequestGetUserId(request) # TODO: 0 - not logged in, 1 - guest
problem_id = int(html.escape(request.params['problem_id']))
contest_id = int(html.escape(request.params['contest_id']))
run_id = int(html.escape(request.params['run_id']))
comment = html.escape(request.params.get('comment', ''))
if is_admin(request):
status = 1
else:
status = 0
ideal = Ideal(problem_id, run_id, contest_id, author_id, comment, status)
with transaction.manager:
DBSession.add(ideal)
return HTTPFound(location="/mod/statements/view3.php?chapterid=" + str(problem_id))
except Exception as e:
return {"result" : "error", "message" : e.__str__(), "stack" : traceback.format_exc()}
示例6: create
# 需要导入模块: from pynformatics.models import DBSession [as 别名]
# 或者: from pynformatics.models.DBSession import add [as 别名]
def create(self):
if not RequestCheckUserCapability(self.request, 'moodle/ejudge_submits:comment'):
raise Exception("Auth Error")
author_id = RequestGetUserId(self.request)
random_string = ''.join(random.SystemRandom().choice(
string.ascii_lowercase + string.digits) for _ in range(20))
encoded_url = urlencode(self.request.params)
monitor = MonitorLink(author_id=author_id,
link=random_string, internal_link=encoded_url)
with transaction.manager:
DBSession.add(monitor)
response = {
'link': random_string
}
return response
示例7: updateOrAddProblem
# 需要导入模块: from pynformatics.models import DBSession [as 别名]
# 或者: from pynformatics.models.DBSession import add [as 别名]
def updateOrAddProblem(problem_id, contest, ejudgeCfg, update_statement = False):
problem = DBSession.query(EjudgeProblem).filter(EjudgeProblem.contest_id == contest.id).filter(EjudgeProblem.problem_id == problem_id).first()
problemCfg = ejudgeCfg.getProblem(problem_id)
if problem == None:
ejudge_problem = EjudgeProblemDummy(problemCfg.long_name, contest.id, problem_id, problemCfg.short_name, contest.ejudge_int_id)
with transaction.manager:
DBSession.add(ejudge_problem)
transaction.commit()
ejudge_problem = DBSession.query(EjudgeProblemDummy).filter(EjudgeProblemDummy.contest_id == contest.id).filter(EjudgeProblemDummy.problem_id == problem_id).first()
problem = Problem(problemCfg.long_name, problemCfg.time_limit, problemCfg.memory_limit, problemCfg.output_only, "<p>Условие пока не опубликовано...</p>", pr_id=ejudge_problem.ejudge_prid)
with transaction.manager:
DBSession.add(problem)
transaction.commit()
problem = DBSession.query(EjudgeProblem).filter(EjudgeProblem.contest_id == contest.id).filter(EjudgeProblem.problem_id == problem_id).first()
action = "add"
content = ""
else:
session = DBSession()
problem.ejudge_name = "" + problemCfg.long_name
problem.name = "" + problemCfg.long_name
if problem.name == "":
problem.name = " " #мы не хотим иметь пустые имена
problem.timelimit = problemCfg.time_limit
problem.memorylimit = problemCfg.memory_limit
problem.output_only = problemCfg.output_only
problem.short_id = problemCfg.short_name
if update_statement:
content = updateStatement(problem, problemCfg, contest, ejudgeCfg)
session.flush()
#session.commit()
transaction.commit()
# DBSession.commit()
action = "edit"
return [problem, problemCfg, action, content]