-
Notifications
You must be signed in to change notification settings - Fork 2
/
modules.py
69 lines (56 loc) · 1.5 KB
/
modules.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
# -*- coding: utf-8 -*-
#
# Author: jimin.huang
#
# Created Time: 2015年09月16日 星期三 20时36分43秒
#
'''
Define and load frontend modules.
Modules
----------------------------
Load in ``_MODULES`` constraint, automatically generate the ``ui_modules``
for options.
.. note::
The name of module follow the name rule of python variables.
.. note::
The import error will raise if the module name is not correct.
Once the module list is updated, restart the server.
'''
_MODULE_ROOT = 'module'
_MODULES = [
'pagination',
]
def name_rule_translation(name):
'''
Translate the name to camel rule.
:returns: a new name in camel rule
'''
# First letter of each word capitalize
return ''.join(
word[0].upper() + word[1:]
for word in name.split('_') if word
)
def get_ui_modules(module_list=None):
'''
Return the generated ui_modules
:returns: ``ui_modules``, a list variable for options
'''
if module_list is None:
module_list = _MODULES
return dict(
[
(
mod,
getattr(getattr(
__import__(
'.'.join((
_MODULE_ROOT,
mod,
))
),
mod),
name_rule_translation(mod)+'Module',
)
) for mod in module_list
]
)