From b590ee85776fbec404624eabb06e6c8fbfa7eaa6 Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sun, 23 Aug 2015 20:37:40 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=99=BB=E9=99=86?= =?UTF-8?q?=E5=90=8E=E8=B7=B3=E8=BD=AC=E5=9B=9E=E6=9D=A5=E6=BA=90=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/src/js/app/oj/account/login.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/static/src/js/app/oj/account/login.js b/static/src/js/app/oj/account/login.js index bc95cf5..0a05762 100644 --- a/static/src/js/app/oj/account/login.js +++ b/static/src/js/app/oj/account/login.js @@ -14,8 +14,15 @@ require(["jquery", "bsAlert", "csrfToken", "validator"], function ($, bsAlert, c //成功登陆 var ref = document.referrer; if(ref){ - if(ref.split("/")[2] == location.hostname){ + // 注册页和本页的来源的跳转回首页,防止死循环 + if(ref.indexOf("register") > -1 || ref.indexOf("login") > -1){ + location.href = "/"; + return; + } + // 判断来源,只有同域下才跳转 + if(ref.split("/")[2].split(":")[0] == location.hostname){ location.href = ref; + return; } } location.href = "/"; From f682aa1fb3cf4b7aab8aaee77b6bdca67658ce0d Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sun, 23 Aug 2015 20:45:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B2=A1=E6=9C=89=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E8=87=AA=E5=8A=A8=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=88=B0=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=9B=B8=E5=85=B3=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account/decorators.py | 6 +++--- account/test_urls.py | 2 ++ account/tests.py | 6 +++--- contest/decorators.py | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/account/decorators.py b/account/decorators.py index 33634e5..4113dd0 100644 --- a/account/decorators.py +++ b/account/decorators.py @@ -1,6 +1,6 @@ # coding=utf-8 from functools import wraps -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render from utils.shortcuts import error_response, error_page @@ -18,7 +18,7 @@ def login_required(func): if request.is_ajax(): return error_response(u"请先登录") else: - return error_page(request, u"请先登录") + return HttpResponseRedirect("/login/") return check @@ -31,5 +31,5 @@ def admin_required(func): if request.is_ajax(): return error_response(u"需要管理员权限") else: - return error_page(request, u"需要管理员权限") + return error_page(request, u"需要管理员权限,如果没有登录,请先登录") return check diff --git a/account/test_urls.py b/account/test_urls.py index 9757d90..5d2bdcc 100644 --- a/account/test_urls.py +++ b/account/test_urls.py @@ -1,5 +1,6 @@ # coding=utf-8 from django.conf.urls import include, url +from django.views.generic import TemplateView from .tests import (LoginRequiredCBVTestWithArgs, LoginRequiredCBVTestWithoutArgs, AdminRequiredCBVTestWithArgs, AdminRequiredCBVTestWithoutArgs) @@ -15,4 +16,5 @@ urlpatterns = [ url(r'^admin_required_test/fbv/(?P\d+)/$', "account.tests.admin_required_FBC_test_with_args"), url(r'^admin_required_test/cbv/1/$', AdminRequiredCBVTestWithoutArgs.as_view()), url(r'^admin_required_test/cbv/(?P\d+)/$', AdminRequiredCBVTestWithArgs.as_view()), + url(r'^login/$', TemplateView.as_view(template_name="oj/account/login.html"), name="user_login_page"), ] diff --git a/account/tests.py b/account/tests.py index a84911c..0b7a8bb 100644 --- a/account/tests.py +++ b/account/tests.py @@ -260,7 +260,7 @@ class LoginRequiredDecoratorTest(TestCase): def test_fbv_without_args(self): # 没登陆 response = self.client.get("/login_required_test/fbv/1/") - self.assertTemplateUsed(response, "utils/error.html") + self.assertRedirects(response, "/login/") # 登陆后 self.client.login(username="test", password="test") @@ -270,7 +270,7 @@ class LoginRequiredDecoratorTest(TestCase): def test_fbv_with_args(self): # 没登陆 response = self.client.get("/login_required_test/fbv/1024/") - self.assertTemplateUsed(response, "utils/error.html") + self.assertRedirects(response, "/login/") # 登陆后 self.client.login(username="test", password="test") @@ -353,7 +353,7 @@ class AdminRequiredDecoratorTest(TestCase): def test_cbv_without_args(self): # 没登陆 response = self.client.get("/admin_required_test/cbv/1/") - self.assertTemplateUsed(response, "utils/error.html") + self.assertRedirects(response, "/login/") # 登陆后 self.client.login(username="test", password="test") diff --git a/contest/decorators.py b/contest/decorators.py index 06a8b70..0b25759 100644 --- a/contest/decorators.py +++ b/contest/decorators.py @@ -1,7 +1,7 @@ # coding=utf-8 from functools import wraps -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render from django.utils.timezone import now @@ -30,7 +30,7 @@ def check_user_contest_permission(func): if request.is_ajax(): return error_response(u"请先登录") else: - return error_page(request, u"请先登录") + return HttpResponseRedirect("/login/") # kwargs 就包含了url 里面的播或参数 if "contest_id" in kwargs: From f58c1e6d9e920d8b2a7f8a7c77328d9550633bfe Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Sun, 23 Aug 2015 20:45:51 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contest/views.py | 14 +++++++++++--- submission/views.py | 5 ++--- template/oj/contest/contest_problem.html | 4 ++++ template/oj/contest/contest_problems_list.html | 13 +++++++------ template/oj/contest/problems.html | 15 --------------- template/oj/problem/problem_list.html | 6 +++--- 6 files changed, 27 insertions(+), 30 deletions(-) delete mode 100644 template/oj/contest/problems.html diff --git a/contest/views.py b/contest/views.py index ae288cc..42ecd62 100644 --- a/contest/views.py +++ b/contest/views.py @@ -17,7 +17,7 @@ from account.decorators import login_required from group.models import Group from announcement.models import Announcement -from .models import Contest, ContestProblem +from .models import Contest, ContestProblem, ContestSubmission from .decorators import check_user_contest_permission from .serializers import (CreateContestSerializer, ContestSerializer, EditContestSerializer, CreateContestProblemSerializer, ContestProblemSerializer, @@ -263,17 +263,25 @@ def contest_page(request, contest_id): return render(request, "oj/contest/contest_index.html", {"contest": contest}) +@check_user_contest_permission def contest_problem_page(request, contest_id, contest_problem_id): try: - Contest.objects.get(id=contest_id) + contest = Contest.objects.get(id=contest_id) except Contest.DoesNotExist: return error_page(request, u"比赛不存在") try: contest_problem = ContestProblem.objects.get(id=contest_problem_id, visible=True) except ContestProblem.DoesNotExist: return error_page(request, u"比赛题目不存在") + show_warning = False + try: + submission = ContestSubmission.objects.get(user=request.user, contest=contest, problem=contest_problem) + show_warning = submission.ac + except ContestSubmission.DoesNotExist: + pass return render(request, "oj/contest/contest_problem.html", {"contest_problem": contest_problem, - "samples": json.loads(contest_problem.samples)}) + "samples": json.loads(contest_problem.samples), + "show_warning": show_warning}) @check_user_contest_permission diff --git a/submission/views.py b/submission/views.py index eb4a3bb..6399e22 100644 --- a/submission/views.py +++ b/submission/views.py @@ -93,8 +93,7 @@ def contest_problem_my_submissions_list_page(request, contest_id, contest_proble contest_problem = ContestProblem.objects.get(id=contest_problem_id, visible=True) except Problem.DoesNotExist: return error_page(request, u"比赛问题不存在") - submissions = Submission.objects.filter(user_id=request.user.id, problem_id=contest_problem.id).order_by( - "-create_time"). \ + submissions = Submission.objects.filter(user_id=request.user.id, problem_id=contest_problem.id).order_by("-create_time"). \ values("id", "result", "create_time", "accepted_answer_time", "language") return render(request, "oj/contest/my_submissions_list.html", {"submissions": submissions, "contest_problem": contest_problem}) @@ -160,7 +159,7 @@ def my_submission_list_page(request, page=1): class ContestSubmissionAPIView(APIView): - # @check_user_contest_permission + @check_user_contest_permission def post(self, request): """ 创建比赛的提交 diff --git a/template/oj/contest/contest_problem.html b/template/oj/contest/contest_problem.html index 69991ad..32b0617 100644 --- a/template/oj/contest/contest_problem.html +++ b/template/oj/contest/contest_problem.html @@ -81,6 +81,7 @@
+
+ {% if show_warning %} + + {% endif %}
diff --git a/template/oj/contest/contest_problems_list.html b/template/oj/contest/contest_problems_list.html index 1b40095..23cefd7 100644 --- a/template/oj/contest/contest_problems_list.html +++ b/template/oj/contest/contest_problems_list.html @@ -21,8 +21,6 @@ 排名 - -
@@ -40,11 +38,14 @@ {% for item in contest_problems %} - - {{ item.sort_index }} + + - {{ item.title }} + + {{ item.sort_index }} + + + {{ item.title }} {{ item|accepted_radio }} diff --git a/template/oj/contest/problems.html b/template/oj/contest/problems.html deleted file mode 100644 index 0f4e49e..0000000 --- a/template/oj/contest/problems.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "oj_base.html" %} -{% block body %} -
- -

第一次比赛

- -

开始时间: 2015-6-8 19:00 结束时间: 2015-9-1 12:00

- -
-{% endblock %} \ No newline at end of file diff --git a/template/oj/problem/problem_list.html b/template/oj/problem/problem_list.html index 6c106e9..a26ae80 100644 --- a/template/oj/problem/problem_list.html +++ b/template/oj/problem/problem_list.html @@ -22,15 +22,15 @@ # 题目 难度 - 通过率 + 通过率 {% for item in problems %} - {{ item.id }} - {{ item.title }} + {{ item.id }} + {{ item.title }} {{ item.difficulty }} {{ item|accepted_radio }}