mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
将dev-hohoTT中的修改更改到hohoTT-dev,用于合并dev
This commit is contained in:
parent
aab770b8bf
commit
69b80ef448
@ -1,6 +1,5 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import redis
|
import redis
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
@ -9,16 +8,15 @@ from rest_framework.views import APIView
|
|||||||
|
|
||||||
from judge.judger_controller.tasks import judge
|
from judge.judger_controller.tasks import judge
|
||||||
from judge.judger_controller.settings import redis_config
|
from judge.judger_controller.settings import redis_config
|
||||||
|
|
||||||
from account.decorators import login_required
|
from account.decorators import login_required
|
||||||
from account.models import SUPER_ADMIN
|
from account.models import SUPER_ADMIN
|
||||||
|
|
||||||
from contest.decorators import check_user_contest_permission
|
from contest.decorators import check_user_contest_permission
|
||||||
|
|
||||||
from problem.models import Problem
|
from problem.models import Problem
|
||||||
from contest.models import Contest, ContestProblem
|
from contest.models import Contest, ContestProblem
|
||||||
|
|
||||||
from utils.shortcuts import serializer_invalid_response, error_response, success_response, error_page, paginate
|
from utils.shortcuts import serializer_invalid_response, error_response, success_response, error_page, paginate
|
||||||
|
|
||||||
from submission.models import Submission
|
from submission.models import Submission
|
||||||
from .serializers import CreateContestSubmissionSerializer
|
from .serializers import CreateContestSubmissionSerializer
|
||||||
from submission.serializers import SubmissionSerializer
|
from submission.serializers import SubmissionSerializer
|
||||||
@ -43,20 +41,16 @@ class ContestSubmissionAPIView(APIView):
|
|||||||
problem.save()
|
problem.save()
|
||||||
except ContestProblem.DoesNotExist:
|
except ContestProblem.DoesNotExist:
|
||||||
return error_response(u"题目不存在")
|
return error_response(u"题目不存在")
|
||||||
|
|
||||||
submission = Submission.objects.create(user_id=request.user.id, language=int(data["language"]),
|
submission = Submission.objects.create(user_id=request.user.id, language=int(data["language"]),
|
||||||
contest_id=contest.id, code=data["code"], problem_id=problem.id)
|
contest_id=contest.id, code=data["code"], problem_id=problem.id)
|
||||||
try:
|
try:
|
||||||
judge.delay(submission.id, problem.time_limit, problem.memory_limit, problem.test_case_id)
|
judge.delay(submission.id, problem.time_limit, problem.memory_limit, problem.test_case_id)
|
||||||
except Exception:
|
except Exception:
|
||||||
return error_response(u"提交判题任务失败")
|
return error_response(u"提交判题任务失败")
|
||||||
|
|
||||||
# 增加redis 中判题队列长度的计数器
|
# 增加redis 中判题队列长度的计数器
|
||||||
r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
|
r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
|
||||||
r.incr("judge_queue_length")
|
r.incr("judge_queue_length")
|
||||||
|
|
||||||
return success_response({"submission_id": submission.id})
|
return success_response({"submission_id": submission.id})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return serializer_invalid_response(serializer)
|
return serializer_invalid_response(serializer)
|
||||||
|
|
||||||
@ -92,8 +86,26 @@ def contest_problem_submissions_list_page(request, contest_id, page=1):
|
|||||||
return error_page(request, u"比赛不存在")
|
return error_page(request, u"比赛不存在")
|
||||||
# 以下是本场比赛中所有的提交
|
# 以下是本场比赛中所有的提交
|
||||||
submissions = Submission.objects.filter(contest_id=contest_id). \
|
submissions = Submission.objects.filter(contest_id=contest_id). \
|
||||||
values("id", "result", "create_time", "accepted_answer_time", "language", "user_id").order_by("-create_time")
|
values("id", "contest_id", "problem_id", "result", "create_time", "accepted_answer_time", "language", "user_id").order_by("-create_time")
|
||||||
|
language = request.GET.get("language", None)
|
||||||
|
filter = None
|
||||||
|
if language:
|
||||||
|
submissions = submissions.filter(language=int(language))
|
||||||
|
filter = {"name": "language", "content": language}
|
||||||
|
result = request.GET.get("result", None)
|
||||||
|
if result:
|
||||||
|
submissions = submissions.filter(result=int(result))
|
||||||
|
filter = {"name": "result", "content": result}
|
||||||
paginator = Paginator(submissions, 20)
|
paginator = Paginator(submissions, 20)
|
||||||
|
|
||||||
|
# 为查询题目标题创建新字典
|
||||||
|
title = {}
|
||||||
|
contest_problems = ContestProblem.objects.filter(contest=contest)
|
||||||
|
for item in contest_problems:
|
||||||
|
title[item.id] = item.title
|
||||||
|
for item in submissions:
|
||||||
|
item['title'] = title[item['problem_id']]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
current_page = paginator.page(int(page))
|
current_page = paginator.page(int(page))
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -107,11 +119,10 @@ def contest_problem_submissions_list_page(request, contest_id, page=1):
|
|||||||
next_page = current_page.next_page_number()
|
next_page = current_page.next_page_number()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return render(request, "oj/contest/submissions_list.html",
|
return render(request, "oj/contest/submissions_list.html",
|
||||||
{"submissions": current_page, "page": int(page),
|
{"submissions": current_page, "page": int(page),
|
||||||
"previous_page": previous_page, "next_page": next_page, "start_id": int(page) * 20 - 20,
|
"previous_page": previous_page, "next_page": next_page, "start_id": int(page) * 20 - 20,
|
||||||
"contest": contest})
|
"contest": contest, "filter":filter})
|
||||||
|
|
||||||
|
|
||||||
class ContestSubmissionAdminAPIView(APIView):
|
class ContestSubmissionAdminAPIView(APIView):
|
||||||
@ -144,6 +155,4 @@ class ContestSubmissionAdminAPIView(APIView):
|
|||||||
return error_response(u"参数错误!")
|
return error_response(u"参数错误!")
|
||||||
if problem_id:
|
if problem_id:
|
||||||
submissions = submissions.filter(problem_id=problem_id)
|
submissions = submissions.filter(problem_id=problem_id)
|
||||||
|
|
||||||
return paginate(request, submissions, SubmissionSerializer)
|
return paginate(request, submissions, SubmissionSerializer)
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ def my_submission_list_page(request, page=1):
|
|||||||
我的所有提交的列表页
|
我的所有提交的列表页
|
||||||
"""
|
"""
|
||||||
submissions = Submission.objects.filter(user_id=request.user.id, contest_id__isnull=True). \
|
submissions = Submission.objects.filter(user_id=request.user.id, contest_id__isnull=True). \
|
||||||
values("id", "result", "create_time", "accepted_answer_time", "language").order_by("-create_time")
|
values("id", "problem_id", "result", "create_time", "accepted_answer_time", "language").order_by("-create_time")
|
||||||
language = request.GET.get("language", None)
|
language = request.GET.get("language", None)
|
||||||
filter = None
|
filter = None
|
||||||
if language:
|
if language:
|
||||||
|
@ -18,17 +18,19 @@
|
|||||||
<tr class="" success>
|
<tr class="" success>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>提交时间</th>
|
<th>提交时间</th>
|
||||||
<th>结果</th>
|
|
||||||
<th>运行时间</th>
|
|
||||||
<th>语言</th>
|
<th>语言</th>
|
||||||
|
<th>运行时间</th>
|
||||||
|
<th>结果</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for item in submissions %}
|
{% for item in submissions %}
|
||||||
<tr class="{{ item.result|translate_result_class }}">
|
<tr>
|
||||||
<th scope="row"><a href="/submission/{{ item.id }}/">{{ forloop.counter }}</a></th>
|
<th scope="row"><a href="/submission/{{ item.id }}/">{{ forloop.counter }}</a></th>
|
||||||
<td>{{ item.create_time }}</td>
|
<td>{{ item.create_time }}</td>
|
||||||
<td>{{ item.result|translate_result }}</td>
|
<td>
|
||||||
|
{{ item.language|translate_language }}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if item.accepted_answer_time %}
|
{% if item.accepted_answer_time %}
|
||||||
{{ item.accepted_answer_time }}ms
|
{{ item.accepted_answer_time }}ms
|
||||||
@ -36,8 +38,8 @@
|
|||||||
--
|
--
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td class="alert-{{ item.result|translate_result_class }}">
|
||||||
{{ item.language|translate_language }}
|
<strong>{{ item.result|translate_result }}</strong>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -26,28 +26,61 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr class="" success>
|
<tr class="" success>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<td>用户</td>
|
<th>题目名称</th>
|
||||||
|
<th>用户</th>
|
||||||
<th>提交时间</th>
|
<th>提交时间</th>
|
||||||
<th>结果</th>
|
<th>
|
||||||
|
<div class="dropdown">
|
||||||
|
<a href="#" class="dropdown-toggle" id="languageFilter" data-toggle="dropdown"
|
||||||
|
aria-haspopup="true" aria-expanded="true">
|
||||||
|
语言<span class="caret"></span>
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="languageFilter">
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/?language=1">C</a></li>
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/?language=2">C++</a></li>
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/?language=3">Java</a></li>
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/">取消筛选</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
<th>运行时间</th>
|
<th>运行时间</th>
|
||||||
<th>语言</th>
|
<th>
|
||||||
|
<div class="dropdown">
|
||||||
|
<a href="#" class="dropdown-toggle" id="resultFilter" data-toggle="dropdown"
|
||||||
|
aria-haspopup="true" aria-expanded="true">
|
||||||
|
结果<span class="caret"></span>
|
||||||
|
</a>
|
||||||
|
<ul class="dropdown-menu" aria-labelledby="resultFilter">
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/?result=0">Accepted</a></li>
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/?result=6">Wrong Answer</a></li>
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/?result=1">Runtime Error</a></li>
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/?result=2">Time Limit Exceeded</a></li>
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/?result=3">Memory Limit Exceeded</a></li>
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/?result=4">Compile Error</a></li>
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/?result=5">Format Error</a></li>
|
||||||
|
<li><a href="/contest/{{ contest.id }}/submissions/">取消筛选</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for item in submissions %}
|
{% for item in submissions %}
|
||||||
<tr class="{{ item.result|translate_result_class }}">
|
<tr>
|
||||||
|
|
||||||
{% ifequal item.user_id request.user.id %}
|
{% ifequal item.user_id request.user.id %}
|
||||||
<th scope="row"><a href="/submission/{{ item.id }}/" id="id_{{ forloop.counter }}">
|
<th scope="row"><a href="/submission/{{ item.id }}/">
|
||||||
{{ forloop.counter |add:start_id }}</a></th>
|
{{ forloop.counter |add:start_id }}</a></th>
|
||||||
{% else %}
|
{% else %}
|
||||||
<th scope="row">{{ forloop.counter |add:start_id }}</th>
|
<th scope="row">{{ forloop.counter |add:start_id }}</th>
|
||||||
{% endifequal %}
|
{% endifequal %}
|
||||||
|
<th scope="row">
|
||||||
|
<a href="/contest/{{ item.contest_id }}/problem/{{ item.problem_id }}/">{{ item.title }}</a>
|
||||||
|
</th>
|
||||||
<td>{{ item.user_id|get_username }}</td>
|
<td>{{ item.user_id|get_username }}</td>
|
||||||
|
|
||||||
<td>{{ item.create_time }}</td>
|
<td>{{ item.create_time }}</td>
|
||||||
<td>{{ item.result|translate_result }}</td>
|
<td>
|
||||||
|
{{ item.language|translate_language }}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if item.accepted_answer_time %}
|
{% if item.accepted_answer_time %}
|
||||||
{{ item.accepted_answer_time }}ms
|
{{ item.accepted_answer_time }}ms
|
||||||
@ -55,12 +88,11 @@
|
|||||||
--
|
--
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td class="alert-{{ item.result|translate_result_class }}">
|
||||||
{{ item.language|translate_language }}
|
<strong>{{ item.result|translate_result }}</strong>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -70,13 +102,13 @@
|
|||||||
<ul class="pager">
|
<ul class="pager">
|
||||||
{% if previous_page %}
|
{% if previous_page %}
|
||||||
<li class="previous"><a
|
<li class="previous"><a
|
||||||
href="/contest/{{ contest.id }}/submissions/{{ previous_page }}/">
|
href="/contest/{{ contest.id }}/submissions/{{ previous_page }}/{% if filter %}?{{ filter.name }}={{ filter.content }}{% endif %}">
|
||||||
<span aria-hidden="true">←</span> 上一页</a></li>
|
<span aria-hidden="true">←</span> 上一页</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if next_page %}
|
{% if next_page %}
|
||||||
<li class="next">
|
<li class="next">
|
||||||
<a href="/contest/{{ contest.id }}/submissions/{{ next_page }}/">下一页 <span
|
<a href="/contest/{{ contest.id }}/submissions/{{ next_page }}/{% if filter %}?{{ filter.name }}={{ filter.content }}{% endif %}">
|
||||||
aria-hidden="true">→</span></a></li>
|
下一页 <span aria-hidden="true">→</span></a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -4,8 +4,14 @@
|
|||||||
<div class="container main">
|
<div class="container main">
|
||||||
<ul class="nav nav-tabs nav-tabs-google">
|
<ul class="nav nav-tabs nav-tabs-google">
|
||||||
<li role="presentation" class="active">
|
<li role="presentation" class="active">
|
||||||
<a href="/problem/{{ problem.id }}/">题目</a></li>
|
<a href="/problem/{{ problem.id }}/">题目</a>
|
||||||
<li role="presentation"><a href="/problem/{{ problem.id }}/submissions/">我的提交</a></li>
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="/problem/{{ problem.id }}/submissions/">我的提交</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation">
|
||||||
|
<a href="/problems/">返回</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{% include "oj/problem/_problem_header.html" %}
|
{% include "oj/problem/_problem_header.html" %}
|
||||||
|
|
||||||
@ -33,7 +39,6 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="problem-section">
|
<div class="problem-section">
|
||||||
|
|
||||||
<label class="problem-label">样例输出{{ forloop.counter }}</label>
|
<label class="problem-label">样例输出{{ forloop.counter }}</label>
|
||||||
<pre>
|
<pre>
|
||||||
{{ item.output }}</pre>
|
{{ item.output }}</pre>
|
||||||
@ -45,23 +50,19 @@
|
|||||||
{% if problem.hint %}
|
{% if problem.hint %}
|
||||||
<div class="problem-section hide">
|
<div class="problem-section hide">
|
||||||
<label class="problem-label">提示</label>
|
<label class="problem-label">提示</label>
|
||||||
|
|
||||||
<p class="problem-detail">{{ problem.hint|safe }}</p>
|
<p class="problem-detail">{{ problem.hint|safe }}</p>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="problem-section hide">
|
<div class="problem-section hide">
|
||||||
<label class="problem-label">标签</label>
|
<label class="problem-label">标签</label>
|
||||||
|
|
||||||
<p class="problem-detail">
|
<p class="problem-detail">
|
||||||
{% for tag in problem.tags.all %}
|
{% for tag in problem.tags.all %}
|
||||||
<span class="label label-success">{{ tag.name }}</span>
|
<span class="label label-success">{{ tag.name }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label>选择语言</label>
|
<label>选择语言</label>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="radio-inline">
|
<label class="radio-inline">
|
||||||
<input type="radio" name="language" value="1" checked> C (gcc 4.8)
|
<input type="radio" name="language" value="1" checked> C (gcc 4.8)
|
||||||
@ -74,7 +75,6 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="code-field">
|
<div id="code-field">
|
||||||
<label class="problem-label">提交代码</label>
|
<label class="problem-label">提交代码</label>
|
||||||
<textarea id="code-editor"></textarea>
|
<textarea id="code-editor"></textarea>
|
||||||
@ -85,9 +85,7 @@
|
|||||||
提交代码
|
提交代码
|
||||||
</button>
|
</button>
|
||||||
<img src="/static/img/loading.gif" id="loading-gif">
|
<img src="/static/img/loading.gif" id="loading-gif">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="result">
|
<div id="result">
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
|
<th>题目名称</th>
|
||||||
<th>提交时间</th>
|
<th>提交时间</th>
|
||||||
<th>
|
<th>
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
@ -47,8 +48,12 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
{% for item in submissions %}
|
{% for item in submissions %}
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><a href="/submission/{{ item.id }}/" id="id_{{ forloop.counter }}">
|
<th scope="row">
|
||||||
{{ forloop.counter |add:start_id }}</a></th>
|
<a href="/submission/{{ item.id }}/">{{ forloop.counter |add:start_id }}</a>
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<a href="/problem/{{ item.problem_id }}/">{{ item.problem_id }}</a>
|
||||||
|
</td>
|
||||||
<td>{{ item.create_time }}</td>
|
<td>{{ item.create_time }}</td>
|
||||||
<td>
|
<td>
|
||||||
{{ item.language|translate_language }}
|
{{ item.language|translate_language }}
|
||||||
|
Loading…
Reference in New Issue
Block a user