From 821b6fb8a0cc384f4a5bd757d6c79565cce7296f Mon Sep 17 00:00:00 2001 From: zhenchaozhu Date: Tue, 29 Nov 2016 17:15:51 +0800 Subject: [PATCH] remove pyqccr --- decrators.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/decrators.py b/decrators.py index 51c2a40..268bbd2 100644 --- a/decrators.py +++ b/decrators.py @@ -4,8 +4,6 @@ import django.http from functools import wraps from django.conf import settings from django.utils.decorators import available_attrs -from pyqccr.http.response_code import REQUEST_FORBIDDEN -from pyqccr.http.status import HTTP_403_FORBIDDEN from django.shortcuts import resolve_url from django.utils.six.moves.urllib.parse import urlparse @@ -50,15 +48,12 @@ import json from django.http import JsonResponse -from pyqccr.http.response_code import REQUEST_SUCCESS, REQUEST_FAILURE_UNIVERSAL -from pyqccr.http.status import HTTP_200_OK, HTTP_400_BAD_REQUEST - class QCCRJsonResponse(JsonResponse): """ 封装了返回码和信息的JsonResponse类 """ - def __init__(self, obj=None, code=REQUEST_SUCCESS, msg="success", status=HTTP_200_OK, **kwargs): + def __init__(self, obj=None, code=200, msg="success", status=200, **kwargs): data = {"code": code, "msg": msg, "result": json.loads(obj) if isinstance(obj, (str, unicode)) else obj} super(QCCRJsonResponse, self).__init__(data=data, status=status, **kwargs) @@ -67,7 +62,7 @@ class QCCRErrorResponse(QCCRJsonResponse): """ 请求错误 """ - def __init__(self, obj=None, code=REQUEST_FAILURE_UNIVERSAL, msg="failure", status=HTTP_400_BAD_REQUEST, **kwargs): + def __init__(self, obj=None, code=400, msg="failure", status=400, **kwargs): super(QCCRErrorResponse, self).__init__(obj=obj, code=code, msg=msg, status=status, **kwargs) def user_passes_test(test_func, login_url=None, @@ -83,7 +78,7 @@ def user_passes_test(test_func, login_url=None, return view_func(request, *args, **kwargs) # 如果未通过检查,且为ajax请求,返回403 if request.is_ajax(): - return QCCRErrorResponse(code=REQUEST_FORBIDDEN, msg="用户身份检查失败", status=HTTP_403_FORBIDDEN) + return QCCRErrorResponse(code=403, msg="用户身份检查失败", status=403) # 非ajax请求,跳转到登录页面 path = request.build_absolute_uri() resolved_login_url = resolve_url(login_url or getattr(settings, "QCCR_LOGIN_URL", '/login/')) -- 2.0.0