-
Notifications
You must be signed in to change notification settings - Fork 9
/
hotkeys.py
35 lines (30 loc) · 1.12 KB
/
hotkeys.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
from gluon.contrib import simplejson as json
def get():
assign = get_assign()
return assign.get_hotkeys(version_hotkeys(assign.version))
from cgi import FieldStorage
@valid_request(hki=FieldStorage)
def upload():
try:
hki_binary = request.vars.hki.value
hkfile = hotkeys.HotkeyFile(hki_binary)
except Exception as e:
raise HTTP(400, 'File format not recognized: {}'.format(e.message))
log.info('File version: {:s}'.format(hkfile.version))
set_assign(hkfile)
redirect(URL('default', 'editor'))
def save():
update_assign(json.loads(request.vars.hotkeys))
return ''
def download():
response.headers['Content-Type'] = 'application/octet-stream'
assign = update_assign(json.loads(request.vars.hotkeys))
hkfile = load_file(assign.version)
for hotkey, value in assign.hotkeys.items():
if hotkey in hkfile:
hkfile[hotkey].update(value)
return hkfile.serialize()
def version():
if request.vars.version not in [v[0] for v in hotkeys.hk_versions]:
raise HTTP(400, 'Bad version specified')
get_assign().version = request.vars.version