Commit b251ff0c authored by HERBERT Ryan's avatar HERBERT Ryan
Browse files

controllers/log.py, index.html log filters

Added log filters in order to limit log output to specific patients/runs
parent 63bd1a46
......@@ -6,18 +6,45 @@ if request.env.http_origin:
response.headers['Access-Control-Max-Age'] = 86400
def index():
user_log = db.user_log
id_list = []
groups = []
table_name = 'all'
id_value = 0
if auth.is_admin():
query = db(db.user_log).select(orderby=~db.user_log.created)
query = (user_log.id > 0)
else:
user_groups = auth.get_user_groups()
parent_groups = auth.get_user_group_parents()
group_list = [g.id for g in user_groups]
parent_list = [g.id for g in parent_groups]
groups = list(set(group_list + parent_list))
query = db(
(db.user_log.table_name == db.auth_permission.table_name) &
(db.user_log.record_id == db.auth_permission.record_id) &
query = ((user_log.table_name == db.auth_permission.table_name) &
(user_log.record_id == db.auth_permission.record_id) &
(db.auth_permission.name == PermissionEnum.access.value) &
(db.auth_permission.group_id.belongs(groups))
).select(db.user_log.ALL, orderby=~db.user_log.created)
return dict(query=query)
(db.auth_permission.group_id.belongs(groups)))
if 'table' in request.vars and request.vars['table'] != 'all':
table_name = request.vars['table']
table = db[table_name]
query &= user_log.table_name == table_name
if auth.is_admin():
ids = db(table).select(table.id, orderby=table.id)
else:
ids = db(
(table.id == user_log.record_id) &
(table_name == user_log.table_name) &
(db.auth_permission.record_id == user_log.record_id) &
(db.auth_permission.name == PermissionEnum.access.value) &
(db.auth_permission.group_id.belongs(groups))
).select(table.id, orderby=table.id)
id_list = [row.id for row in ids]
if 'id' in request.vars and request.vars['id'] != 0:
id_value = request.vars['id']
query &= user_log.record_id == request.vars['id']
log.debug(db(query)._select(orderby=~db.user_log.created))
return dict(query=db(query).select(user_log.ALL, orderby=~db.user_log.created),
id_list=id_list,
stable=table_name,
sid=id_value)
......@@ -3,6 +3,12 @@
<h3></h3>
<div id="block_left">
table:
{{=SELECT(*[OPTION(elem) for elem in ['all', 'patient', 'run']], _id="table_selector", _name="table", _onchange="db.call('log/index', {'table': this.value})", value=stable)}}
id:
{{=SELECT(*[OPTION(id) for id in ([0] + id_list)], _id="id_selector", _name="id", _onchange="db.call('log/index', {'table': $('#table_selector').val(), 'id': this.value})", value=sid)}}
</div>
<div id="db_table_container">
<table class="db_table" id="table">
<thead>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment