コード例 #1
0
def scoreboard(sheet):
    if pathsep in sheet or not isdir('scoreboard/' +
                                     sheet) or not config.allow_scoreboard:
        return file("forbidden.html", 403)
#       response.status = 403
#       return '<html><head><title>Таблица результатов</title></head><body><h3>'\
#              'Замечание для умных</h3><p>Не пытайтесь меня крякнуть!</p></body></html>'
    with open('tasksheets/{}/name.txt'.format(sheet)) as f:
        name = f.readline().strip()
    ans = '<html><head><title>{{scoreboard}} - {name}</title></head><body>'\
          '<h3>{{scoreboard}} - {name}</h3>'.format(name=escape(name))
    if authenticate(request.get_cookie('credentials', default='invalid')):
        ans += '<a href="../submit/{sheet}">{{submit_sol}}</a>&nbsp;'\
               '<a href="../submissions/{sheet}">{{yours}}</a>&nbsp;'\
               '<a href="../logout">{{logout}}</a><br />'.format(sheet=sheet)
    ans += '<table cellspacing=0 border=1><tr><td></td>'
    user_scores = [
        get_user_score(sheet, user) for user in listdir('scoreboard/' + sheet)
    ]
    user_scores.sort(key=lambda x: x[0])
    user_scores.reverse()
    tester = import_tester(sheet)
    for task in tester.tasks:
        ans += '<td>' + task + '</td>'
    ans += '</tr>'
    for i, (garbage, user, tasks) in enumerate(user_scores):
        with open('users/{}.real_name'.format(user)) as f:
            real_name = f.read()
        ans += '<tr><td>{no}. {name}</td>{fmt}'.format(name=escape(real_name),
                                                       fmt=format_user(
                                                           user, tasks,
                                                           tester.tasks),
                                                       no=i + 1)
    ans += '</table></body></html>'
    return ans.format(**locale.get_locale())
コード例 #2
0
ファイル: tester.py プロジェクト: sleirsgoevy/dk-careglaz
def show_result(id):
    if not isfile('submissions/{}.finished'.format(id)):
        return '<html><head><title>{{protocol}}{id}</title></head><body>'\
               '<a href="javascript:history.back()">{{back}}</a>&nbsp;'\
               '<a href="/dk-careglaz/logout">{{logout}}</a><br />'\
               '<p>{{not_finished}}</p>'\
               '<script>setTimeout(function(){{{{'\
               'document.location.href=document.location.href;'\
               '}}}}, 1000)</script>'\
               '</body></html>'.format(id=id).format(**locale.get_locale())
    ans = '<html><head><title>{{protocol}}{}</title></head><body>'\
          '<a href="javascript:history.back()">{{back}}</a>&nbsp;'\
          '<a href="../logout">{{logout}}</a><br /><pre>\n'.format(id)
    with open('submissions/{}.log'.format(id)) as file:
        ans += file.read().replace('{', '{{').replace('}', '}}')
    ans += '\n</pre></body></html>'
    return ans.format(**locale.get_locale())
コード例 #3
0
ファイル: tester.py プロジェクト: sleirsgoevy/dk-careglaz
def task_route(sheet):
    if pathsep in sheet or not isfile('tasksheets/{}/tester.py'.format(sheet)):
        return file("forbidden.html", 403)
    credentials = request.get_cookie('credentials', default='invalid')
    if credentials == 'invalid':
        return redirect("../../login/" + sheet)
    if not authenticate(credentials):
        return file("login_error.html", 401, True)


#       response.status = 403
#       return '<html><head><title>Не удалось авторизоваться</title></head><body>'\
#              '<h3>Не удалось авторизоваться</h3><p>Неверный пароль, попробуйте '\
#              '<a href="https://newsgoevy.pythonanywhere.com/dk-careglaz/login/{}">'\
#              'перезайти</a>.</p></body></html>'.format(sheet)
#       response.status = 403
#       return '<html><head><title>Сдать задачу</title></head><body><h3>'\
#              'Замечание для умных</h3><p>Не пытайтесь меня крякнуть!</p></body></html>'
    tester = import_tester(sheet)
    with open('tasksheets/{}/name.txt'.format(sheet)) as f:
        name = f.readline().strip()
    ans = '<html><head><title>{{submit_sol}} - {name}</title></head><body>'\
          '<a href="../submissions/{sheet}">{{submissions}}</a>&nbsp;'
    if config.allow_scoreboard:
        ans += '<a href="../scoreboard/{sheet}">{{scoreboard}}</a>&nbsp;'
    ans += '<a href="../logout">{{logout}}</a><br />'
    if hasattr(tester, 'intro'):
        ans += tester.intro
    ans += '<form action="#" method=post enctype="multipart/form-data">'\
           '<select name=task><option disabled selected style="display: none">'\
           '{{select_task}}</option>'
    ans = ans.format(sheet=sheet, name=name)
    for id, (name, do_test, *args) in tester.tasks.items():
        if args and args[0].get('hidden', False): continue
        ans += '<option value={id}>{name}</option>'.format(name=escape(name),
                                                           id=id)
    ans += '</select><input type=file name=solution /><input type=submit value="Отправить!" />'\
           '</form></body></html>'
    response.set_cookie('credentials', credentials, max_age=86400, path="/")
    return ans.format(**locale.get_locale())
コード例 #4
0
ファイル: tester.py プロジェクト: sleirsgoevy/dk-careglaz
def view_submissions(sheet):
    credentials = request.get_cookie('credentials', default='invalid')
    if credentials == 'invalid':
        return redirect("../../login-result/" + sheet)
#       response.status = 302
#       response['Location'] = 'https://newsgoevy.pythonanywhere.com/dk-careglaz/login-result/'+id
#       return ''
    user = authenticate(credentials)
    if not user:
        return file("login_error.html", 401, True)
#       response.status = 403
#       return '<html><head><title>Не удалось авторизоваться</title></head><body>'\
#              '<h3>Не удалось авторизоваться</h3><p>Неверный пароль, попробуйте '\
#              '<a href="https://newsgoevy.pythonanywhere.com/dk-careglaz/login">перезайти</a>.</p></body></html>'
    if pathsep in sheet or not isdir(
            'scoreboard/{sheet}'.format(sheet=sheet)) or not isfile(
                'users/{user}.real_name'.format(user=user)):
        return file("forbidden.html", 403)


#       response.status = 403
#       return '<html><head><title>Протокол</title></head><body><h3>'\
#              'Замечание для умных</h3><p>Не пытайтесь меня крякнуть!</p></body></html>'
    ans = '<html><head><title>{{yours}}</title></head><body>'\
          '<a href="../submit/{sheet}">{{submit_sol}}</a>&nbsp;'
    if config.allow_scoreboard:
        ans += '<a href="../scoreboard/{sheet}">{{scoreboard}}</a>&nbsp;'
    ans += '<a href="../logout">{{logout}}</a><br />'
    ans = ans.format(sheet=sheet)
    if isfile('scoreboard/{sheet}/{user}'.format(sheet=sheet, user=user)):
        with open('scoreboard/{sheet}/{user}'.format(sheet=sheet,
                                                     user=user)) as f:
            for line in f:
                i, task = line.split()
                ans += '<a href="../result/{i}">{{solution}}{i} ({{task}} {task})</a><br />'.format(
                    i=i, task=task)
    ans += '</body></html>'
    return ans.format(**locale.get_locale())
コード例 #5
0
def dkcareglaz():
    if not config.allow_main_page:
        return shower.file("forbidden.html", 403)
    ans = '<html><head><title>{testsys}</title></head><body>'\
          '<table sellspacing=0 border=1>'
    ansl = []
    for i in listdir('tasksheets'):
        if not os.path.exists('tasksheets/{}/sortid.txt'.format(i)): continue
        with open('tasksheets/{}/name.txt'.format(i)) as file:
            with open('tasksheets/{}/sortid.txt'.format(i)) as file2: sortid = int(file2.read())
            name = file.readline().strip()
            ansl.append((sortid, ('<tr><td>{name}</td>'\
                    '<td><a href="theory/{i}">{{theory}}</a></td>'\
                    '<td><a href="tasks/{i}">{{tasks}}</a></td>'\
                    '<td><a href="submit/{i}">{{submit}}</a></td>'+
                    ('<td><a href="scoreboard/{i}">{{scoreboard}}</a></td>'
                    if config.allow_scoreboard else '')+'</tr>').format(name=escape(name), i=i)))
    ansl.sort()
    ansl.reverse()
    for i in ansl: ans += i[1]
    ans += '</table></body></html>'
#   print(ans)
    return ans.format(**locale.get_locale())