當前位置: 首頁>>代碼示例>>Python>>正文


Python DBSession.add方法代碼示例

本文整理匯總了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()}
開發者ID:InformaticsMskRu,項目名稱:informatics-mccme-ru,代碼行數:33,代碼來源:comment.py

示例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()}
開發者ID:InformaticsMskRu,項目名稱:informatics-mccme-ru,代碼行數:14,代碼來源:hint.py

示例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]
開發者ID:InformaticsMskRu,項目名稱:informatics-mccme-ru,代碼行數:16,代碼來源:contest.py

示例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()}
開發者ID:InformaticsMskRu,項目名稱:informatics-mccme-ru,代碼行數:16,代碼來源:stars.py

示例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()}
開發者ID:InformaticsMskRu,項目名稱:informatics-mccme-ru,代碼行數:19,代碼來源:ideal_solution.py

示例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
開發者ID:InformaticsMskRu,項目名稱:informatics-mccme-ru,代碼行數:21,代碼來源:team_monitor.py

示例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]
開發者ID:InformaticsMskRu,項目名稱:informatics-mccme-ru,代碼行數:39,代碼來源:contest.py


注:本文中的pynformatics.models.DBSession.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。