[后端]添加提交列表筛选功能,按语言,题目,测试还没写

This commit is contained in:
esp 2015-08-28 20:27:47 +08:00
parent 4bfbaf249f
commit 6d4d44430f
2 changed files with 39 additions and 6 deletions

View File

@ -140,6 +140,15 @@ def my_submission_list_page(request, page=1):
"""
submissions = Submission.objects.filter(user_id=request.user.id). \
values("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}
result = request.GET.get("result", None)
if result:
submissions = submissions.filter(result=int(result))
filter = {"name": "result", "content": result}
paginator = Paginator(submissions, 20)
try:
current_page = paginator.page(int(page))
@ -161,4 +170,4 @@ def my_submission_list_page(request, page=1):
return render(request, "oj/submission/my_submissions_list.html",
{"submissions": current_page, "page": int(page),
"previous_page": previous_page, "next_page": next_page, "start_id": int(page) * 20 - 20,
"announcements": announcements})
"announcements": announcements, "filter":filter})

View File

@ -8,12 +8,36 @@
{% if submissions %}
<table class="table table-bordered">
<thead>
<tr class="" success>
<tr>
<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="/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/">取消筛选</a></li>
</ul></div>
</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="/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/">取消筛选</a></li>
</ul></div>
</th>
</tr>
</thead>
<tbody>
@ -42,12 +66,12 @@
<ul class="pager">
{% if previous_page %}
<li class="previous"><a
href="/submissions/{{ previous_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if tag %}?tag={{ tag }}{% endif %}">
href="/submissions/{{ previous_page }}/{% if filter %}?{{ filter.name }}={{ filter.content }}{% endif %}">
<span aria-hidden="true">&larr;</span> 上一页</a></li>
{% endif %}
{% if next_page %}
<li class="next"><a
href="/submissions/{{ next_page }}/{% if keyword %}?keyword={{ keyword }}{% endif %}{% if tag %}?tag={{ tag }}{% endif %}">下一页 <span
href="/submissions/{{ next_page }}/{% if filter %}?{{ filter.name }}={{ filter.content }}{% endif %}">下一页 <span
aria-hidden="true">&rarr;</span></a></li>
{% endif %}
</ul>