优化所有提交页面的翻页显示

This commit is contained in:
virusdefender 2016-05-30 14:35:16 +08:00
parent 3b6cbc51a1
commit df4db5141f
No known key found for this signature in database
GPG Key ID: 1686FB5677979E61
7 changed files with 61 additions and 28 deletions

View File

@ -14,6 +14,11 @@ SMTP_CONFIG = {"smtp_server": "smtp.domain.com",
"password": "your_password",
"tls": False}
# 是否显示所有人的提交, False就只显示自己的
SHOW_ALL_SUBMISSIONS_LIST = False
# please set your own SECRET_KEY to a long random string
# SECRET_KEY = ""

View File

@ -189,6 +189,3 @@ TOKEN_BUCKET_DEFAULT_CAPACITY = 50
# 单位:每分钟
TOKEN_BUCKET_FILL_RATE = 2
# 是否显示所有人的提交, False就只显示自己的
SHOW_ALL_SUBMISSIONS_LIST = False

View File

@ -104,8 +104,8 @@ urlpatterns = [
url(r'^api/open/submission/$', OpenAPISubmitCodeAPI.as_view(), name="openapi_submit_code"),
url(r'^submission/(?P<submission_id>\w+)/$', "submission.views.my_submission", name="my_submission_page"),
url(r'^submissions/$', "submission.views.my_submission_list_page", name="my_submission_list_page"),
url(r'^submissions/(?P<page>\d+)/$', "submission.views.my_submission_list_page", name="my_submission_list_page"),
url(r'^submissions/$', "submission.views.submission_list_page", name="submission_list_page"),
url(r'^submissions/(?P<page>\d+)/$', "submission.views.submission_list_page", name="my_submission_list_page"),
url(r'^contest/(?P<contest_id>\d+)/rank/$', "contest.views.contest_rank_page", name="contest_rank_page"),

View File

@ -15,7 +15,8 @@ from account.models import SUPER_ADMIN, User
from problem.models import Problem
from contest.models import ContestProblem, Contest
from contest.decorators import check_user_contest_permission
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, build_query_string)
from utils.throttling import TokenBucket, BucketController
from judge.result import result as judge_result
from .tasks import _judge
@ -238,28 +239,42 @@ class SubmissionAdminAPIView(APIView):
@login_required
def my_submission_list_page(request, page=1):
def submission_list_page(request, page=1):
"""
我的所有提交的列表页
所有提交的列表页
"""
# 是否显示所有人的提交
show_all = settings.SHOW_ALL_SUBMISSIONS_LIST or request.GET.get("show_all", False) == "true"
show_all = False
submission_filter = {"my": None}
# 兼容部分版本,设置中没有这一项
try:
show_all = settings.SHOW_ALL_SUBMISSIONS_LIST
except Exception:
pass
# url中my=true可以只显示自己的
if request.GET.get("my", None) == "true":
submission_filter["my"] = "true"
show_all = False
if show_all:
submissions = Submission.objects.filter(contest_id__isnull=True)
else:
submissions = Submission.objects.filter(user_id=request.user.id, contest_id__isnull=True)
submissions = submissions.values("id", "user_id", "problem_id", "result", "create_time", "accepted_answer_time",
"language").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}
submission_filter["language"] = language
result = request.GET.get("result", None)
if result:
submissions = submissions.filter(result=int(result))
filter = {"name": "result", "content": result}
submission_filter["result"] = result
paginator = Paginator(submissions, 20)
try:
@ -298,10 +313,12 @@ def my_submission_list_page(request, page=1):
except Exception:
pass
return render(request, "oj/submission/my_submissions_list.html",
return render(request, "oj/submission/submissions_list.html",
{"submissions": submissions, "page": int(page),
"previous_page": previous_page, "next_page": next_page, "start_id": int(page) * 20 - 20,
"filter": filter, "show_all": show_all})
"query": build_query_string(submission_filter),
"submission_filter": submission_filter,
"show_all": show_all})
class SubmissionShareAPIView(APIView):

View File

@ -20,9 +20,9 @@
语言<span class="caret"></span>
</a>
<ul class="dropdown-menu" aria-labelledby="languageFilter">
<li><a href="/submissions/?language=1">C</a></li>
<li><a href="/submissions/?language=2">C++</a></li>
<li><a href="/submissions/?language=3">Java</a></li>
<li><a href="/submissions/?language=1{% if not show_all %}&my=true{% endif %}">C</a></li>
<li><a href="/submissions/?language=2{% if not show_all %}&my=true{% endif %}">C++</a></li>
<li><a href="/submissions/?language=3{% if not show_all %}&my=true{% endif %}">Java</a></li>
<li><a href="/submissions/">取消筛选</a></li>
</ul>
</div>
@ -35,13 +35,13 @@
结果<span class="caret"></span>
</a>
<ul class="dropdown-menu" aria-labelledby="resultFilter">
<li><a href="/submissions/?result=0">Accepted</a></li>
<li><a href="/submissions/?result=6">Wrong Answer</a></li>
<li><a href="/submissions/?result=1">Runtime Error</a></li>
<li><a href="/submissions/?result=2">Time Limit Exceeded</a></li>
<li><a href="/submissions/?result=3">Memory Limit Exceeded</a></li>
<li><a href="/submissions/?result=4">Compile Error</a></li>
<li><a href="/submissions/?result=5">Format Error</a></li>
<li><a href="/submissions/?result=0{% if not show_all %}&my=true{% endif %}">Accepted</a></li>
<li><a href="/submissions/?result=6{% if not show_all %}&my=true{% endif %}">Wrong Answer</a></li>
<li><a href="/submissions/?result=1{% if not show_all %}&my=true{% endif %}">Runtime Error</a></li>
<li><a href="/submissions/?result=2{% if not show_all %}&my=true{% endif %}">Time Limit Exceeded</a></li>
<li><a href="/submissions/?result=3{% if not show_all %}&my=true{% endif %}">Memory Limit Exceeded</a></li>
<li><a href="/submissions/?result=4{% if not show_all %}&my=true{% endif %}">Compile Error</a></li>
<li><a href="/submissions/?result=5{% if not show_all %}&my=true{% endif %}">Format Error</a></li>
<li><a href="/submissions/">取消筛选</a></li>
</ul>
</div>
@ -86,12 +86,12 @@
<ul class="pager">
{% if previous_page %}
<li class="previous"><a
href="/submissions/{{ previous_page }}/{% if filter %}?{{ filter.name }}={{ filter.content }}{% endif %}">
href="/submissions/{{ previous_page }}/{{ query }}">
<span aria-hidden="true">&larr;</span> 上一页</a></li>
{% endif %}
{% if next_page %}
<li class="next"><a
href="/submissions/{{ next_page }}/{% if filter %}?{{ filter.name }}={{ filter.content }}{% endif %}">下一页 <span
href="/submissions/{{ next_page }}/{{ query }}">下一页 <span
aria-hidden="true">&rarr;</span></a></li>
{% endif %}
</ul>

View File

@ -70,7 +70,7 @@
<li role="separator" class="divider"></li>
{% endif %}
<li><a href="/user/{{ request.user.username }}/">我的主页</a></li>
<li><a href="/submissions/">我的提交</a></li>
<li><a href="/submissions/?my=true">我的提交</a></li>
<li><a href="/account/settings/">设置</a></li>
<li role="separator" class="divider"></li>
<li><a href="/logout/">退出</a></li>

View File

@ -110,4 +110,18 @@ def paginate(request, query_set, object_serializer=None):
def rand_str(length=32):
if length > 128:
raise ValueError("length must <= 128")
return hashlib.sha512(os.urandom(128)).hexdigest()[0:length]
return hashlib.sha512(os.urandom(128)).hexdigest()[0:length]
def build_query_string(kv_data, ignore_none=True):
# {"a": 1, "b": "test"} -> "?a=1&b=test"
query_string = ""
for k, v in kv_data.iteritems():
if ignore_none is True and kv_data[k] is None:
continue
if query_string != "":
query_string += "&"
else:
query_string = "?"
query_string += (k + "=" + str(v))
return query_string