|
1
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
2
|
|
|
from __future__ import absolute_import, unicode_literals
|
|
3
|
|
|
from school_api.exceptions import SchoolException, LoginException, PermissionException
|
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
class UserType():
|
|
7
|
|
|
''' 用户类型参数 '''
|
|
8
|
|
|
STUDENT = 0
|
|
9
|
|
|
TEACHER = 1
|
|
10
|
|
|
DEPT = 2
|
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class ScheduleType():
|
|
14
|
|
|
''' 课表类型参数 '''
|
|
15
|
|
|
PERSON = 0
|
|
16
|
|
|
CLASS = 1
|
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
class LoginFail():
|
|
|
|
|
|
|
20
|
|
|
''' 登录失败返回错误信息 '''
|
|
21
|
|
|
|
|
22
|
|
|
def __init__(self, tip=''):
|
|
23
|
|
|
self.tip = tip
|
|
24
|
|
|
|
|
25
|
|
|
def __getattr__(self, name):
|
|
26
|
|
|
def func(*args, **kwargs):
|
|
|
|
|
|
|
27
|
|
|
return {'error': self.tip}
|
|
28
|
|
|
return func
|
|
29
|
|
|
|
|
30
|
|
|
def __nonzero__(self):
|
|
31
|
|
|
return True
|
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
def error_handle(func):
|
|
|
|
|
|
|
35
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
|
|
|
36
|
|
|
if not self.school.use_ex_handle:
|
|
37
|
|
|
result = func(self, *args, **kwargs)
|
|
38
|
|
|
else:
|
|
39
|
|
|
try:
|
|
40
|
|
|
result = func(self, *args, **kwargs)
|
|
41
|
|
|
|
|
42
|
|
|
except LoginException as reqe:
|
|
43
|
|
|
result = LoginFail(reqe)
|
|
44
|
|
|
|
|
45
|
|
|
except SchoolException as reqe:
|
|
46
|
|
|
result = {'error': reqe}
|
|
47
|
|
|
|
|
48
|
|
|
return result
|
|
49
|
|
|
return wrapper
|
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
class ApiPermissions():
|
|
|
|
|
|
|
53
|
|
|
''' 接口权限判断 '''
|
|
54
|
|
|
|
|
55
|
|
|
def __init__(self, permission_list):
|
|
56
|
|
|
self.permission_list = permission_list
|
|
57
|
|
|
|
|
58
|
|
|
def __call__(self, func):
|
|
59
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
|
|
|
60
|
|
|
func_object = args[0]
|
|
61
|
|
|
if func_object.user_type not in self.permission_list:
|
|
62
|
|
|
raise PermissionException(func_object.school.code, '暂无该接口权限')
|
|
63
|
|
|
return func(*args, **kwargs)
|
|
64
|
|
|
return wrapper
|
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
def get_time_list(class_time):
|
|
68
|
|
|
''' 上课时间处理 '''
|
|
69
|
|
|
time_list = {1: [], 2: [], 3: [], 4: []}
|
|
70
|
|
|
time_text = "{} ~ {}"
|
|
71
|
|
|
for index, times in enumerate(class_time):
|
|
72
|
|
|
if index % 2 == 0:
|
|
73
|
|
|
time_list[1].append(time_text.format(times[0], times[1]))
|
|
74
|
|
|
time_list[2].append(time_text.format(times[0], class_time[index+1][1]))
|
|
75
|
|
|
|
|
76
|
|
|
if index < 8:
|
|
77
|
|
|
time_list[3].append(time_text.format(times[0], class_time[index+2][1]))
|
|
78
|
|
|
time_list[4].append(time_text.format(times[0], class_time[index+3][1]))
|
|
79
|
|
|
return time_list
|
|
80
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.