Passed
Push — master ( ca67bc...5eab93 )
by dai
02:57
created

school_api.client.utils.ApiPermissions.__init__()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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():
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
20
    ''' 登录失败返回错误信息 '''
21
22
    def __init__(self, tip=''):
23
        self.tip = tip
24
25
    def __getattr__(self, name):
26
        def func(*args, **kwargs):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The argument kwargs seems to be unused.
Loading history...
Unused Code introduced by
The argument args seems to be unused.
Loading history...
27
            return {'error': self.tip}
28
        return func
29
30
    def __nonzero__(self):
31
        return True
32
33
34
def error_handle(func):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
35
    def wrapper(self, *args, **kwargs):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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():
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
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):
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
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