-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
executable file
·85 lines (77 loc) · 2.82 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
from django.shortcuts import render_to_response
from django.http import HttpResponse, HttpResponseRedirect
from client.models import Admin
import os
import time
def judgeadmin(test):
"""
判断是否登录,后台操作的全局判断,用作装饰器
:param test:
:return:
"""
def infun(req, *args, **kwargs):
if req.COOKIES.get('adminID', '') == '':
return HttpResponseRedirect('/client')
else:
adid = Admin.objects.filter(id=req.COOKIES.get('adminID', ''))
if adid.count() == 0:
return HttpResponse("<script type='text/javascript'>alert('该用户不存在');window.location.href='/client';</script>")
else:
ret = test(req, *args, **kwargs)
return ret
return infun
def adminskip(func):
"""
跳转异常装饰器
"""
def infun(req, *args, **kwargs):
basePath = os.path.dirname(os.path.dirname(__file__))
logPath = os.path.join(basePath, "index/log/skip.txt")
log_file = open(logPath, "a")
try:
ret = func(req, *args, **kwargs)
except Exception as err:
log_file.writelines(str(time.strftime('%Y/%m/%d %H:%M:%S')) + "\tview:" +
func.__name__ + "\nerror:[" + str(err) + "]\ndoc:" + func.__doc__ + "\n")
return render_to_response('404.html')
finally:
log_file.close()
return ret
return infun
def adminselect(func):
"""
查找异常装饰器
"""
def infun(req, *args, **kwargs):
basePath = os.path.dirname(os.path.dirname(__file__))
logPath = os.path.join(basePath, "index/log/select.txt")
log_file = open(logPath, "a")
try:
ret = func(req, *args, **kwargs)
except Exception as err:
log_file.writelines(str(time.strftime('%Y/%m/%d %H:%M:%S')) + "\tview:" +
func.__name__ + "\nerror:[" + str(err) + "]\ndoc:" + func.__doc__ + "\n")
return render_to_response('404.html')
finally:
log_file.close()
return ret
return infun
def adminupdate(func):
"""
增删改异常装饰器
"""
def infun(req, *args, **kwargs):
basePath = os.path.dirname(os.path.dirname(__file__))
logPath = os.path.join(basePath, "index/log/update.txt")
log_file = open(logPath, "a")
try:
ret = func(req, *args, **kwargs)
except Exception as err:
log_file.writelines(str(time.strftime('%Y/%m/%d %H:%M:%S')) + "\tview:" +
func.__name__ + "\nerror:[" + str(err) + "]\ndoc:" + func.__doc__ + "\n")
return render_to_response('404.html')
finally:
log_file.close()
return ret
return infun