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] =?UTF-8?q?=E6=B2=A1=E6=9C=89=E7=99=BB=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E8=87=AA=E5=8A=A8=E8=B7=B3=E8=BD=AC=E5=88=B0?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=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: