-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_list.py
66 lines (62 loc) · 2.36 KB
/
key_list.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
#!/usr/bin/python
"""
Created on Wed Jan 14 18:21:14 2015
@author: mints
"""
from .prettiesttable import from_db_cursor
from .globals import get_conn, JINJA
def key_list():
t = JINJA.get_template('key_list.template')
t1 = from_db_cursor(get_conn().execute("""
select key, ifnull(subkey, '') as subkey, description, data_format
from keys k"""))
select_key = []
for row in t1._rows:
if row[0] not in select_key:
select_key.append(row[0])
return t.render({'key_list': t1.get_html_string(attributes={'border': 1,
'id': 'key_list'}),
'select_key': select_key})
def key_list_update(key, subkey, description, format):
conn = get_conn()
if subkey == '':
subkey_cond = 'subkey is null'
else:
subkey_cond = "subkey = '%s'" % subkey
check = conn.execute("""select count(*)
from keys
where key = '%s'
and %s""" % (key, subkey_cond)).fetchone()[0]
print(subkey_cond)
if check > 0:
conn.execute("""update keys
set description = '%s',
data_format = '%s'
where key = '%s'
and %s""" % (description, format,
key, subkey_cond))
else:
conn.execute("""
insert into keys (key, subkey, description, data_format)
values ('%s', nullif('%s', ''), '%s', '%s');
""" % (key, subkey, description, format))
conn.commit()
return None
def key_list_delete(itemlist):
conn = get_conn()
for item in itemlist:
if item[1] == '':
subkey_cond = 'subkey is null'
else:
subkey_cond = "subkey = '%s'" % item[1]
conn.execute("""delete from keys
where key = '%s'
and %s""" % (item[0], subkey_cond))
conn.execute("""delete from reference_tables_keys
where key = '%s'
and %s""" % (item[0], subkey_cond))
conn.execute("""delete from per_cluster_keys
where key = '%s'
and %s""" % (item[0], subkey_cond))
conn.commit()
return None