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()}
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()}
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]
Beispiel #4
0
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]
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()}
Beispiel #6
0
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]
Beispiel #7
0
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()
        }
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()}
    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
    def create_secret_link(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))

        internal_link = urlencode(self.request.params)
        monitor = MonitorLink(author_id=author_id,
                              link=random_string,
                              internal_link=internal_link)

        with transaction.manager:
            DBSession.add(monitor)

        response = {'link': random_string}

        return response
Beispiel #11
0
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()
        }
Beispiel #12
0
def add(request):
    try:
        if (not RequestCheckUserCapability(request,
                                           'moodle/ejudge_submits:comment')):
            raise Exception("Auth Error")
        run = Run.get_by(run_id=request.params['run_id'],
                         contest_id=request.params['contest_id'])
        if not run:
            raise Exception("Object not found")
        user = DBSession.query(User).filter(
            User.id == RequestGetUserId(request)).first()
        comment = Comment(run, user, html.escape(request.params['lines']),
                          html.escape(request.params['comment']))
        with transaction.manager:
            DBSession.add(comment)
        return {"result": "ok"}
    except Exception as e:
        return {
            "result": "error",
            "message": e.__str__(),
            "stack": traceback.format_exc()
        }
Beispiel #13
0
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()
        }
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]