def get_home_variables(request): p = fns.get_conn_params(request) variables = {'user': p['username'], 'host': p['host']} variables['dialect'] = 'PostgreSQL' if p['dialect'] == 'postgresql' else 'MySQL' result = sa.full_query( p, sql.stored_query('variables', p['dialect'])) if p['dialect'] == 'postgresql': variables['version'] = result['rows'][0] return variables elif p['dialect'] == 'mysql': if type(result) == dict: ll = result['rows'] d = {} for i in range( len(ll) ): d[ll[i][0]] = ll[i][1] variables.update(d) return variables else: return fns.http_500(result)
def generate_sidebar(request): ret_string = '' # store the string representation to be generated by this function static_addr = fns.render_template(request, '{{STATIC_URL}}') conn_params = fns.get_conn_params(request, update_db=True) db_list = qry.common_query(conn_params, 'db_list', request.GET)['rows'] # if sctn is 'home' give list of database # if sctn is overview give list of schema if postgresql or leave as above # if sctn is not 'home' or 'oveview' give a list of all the objects described by sctn if request.GET.get('sctn') == 'hm' or \ (conn_params['dialect'] == 'mysql' and request.GET.get('sctn') == 'db'): li_list = [] for db_row in db_list: sufx = "&schm=%s" % sa.get_default_schema(conn_params) if conn_params['dialect'] == 'postgresql' else '' a = "<a class='icon-database' href='#sctn=db&v=ov&db={0}{1}'>{0}</a>".format(db_row[0],sufx) active_li = ' class="active"' if request.GET.get('db') == db_row[0] else '' # this would mark an item for hightlighting # occurs in the 'db' section of MySQL dialect # and it selects the currently displayed db li_list.append('<li{1}>{0}</li>'.format(a, active_li)) ret_string += '<h6>Databases</h6><ul>' + ''.join(li_list) + '</ul>' elif request.GET.get('sctn') == 'db': # decide on what to do _dict = {'db': request.GET.get('db')} # get a dropdown of databases from db_list with its initial set to what is in request.GET db_selection_form = select_input(db_list, desc={'id':'db_select'}, initial= _dict['db']) schema_list = qry.common_query(conn_params, 'schema_list', request.GET)['rows'] _list = [] for schm_row in schema_list: a = '<a class="icon-schema schm-link" href="#">%s</a>' % schm_row[0] # decide selected schema link li_pfx = " class='active'" if request.GET.get('schm', sa.get_default_schema(conn_params) ) == schm_row[0] else '' # append whole li element _list.append("<li{0}>{1}</li>".format(li_pfx, a)) placeholder = '<h6 class="placeholder">%ss:</h6>' % fns._abbr['schm'] sfx = "<ul>{0}</ul>".format( ''.join(_list) ) ret_string = '<h6><a class="icon-back" href="#sctn=hm&v=hm">back home</a></h6>\ <h6>quick nav:</h6><div class="sidebar-item"><img src="{3}/tt_img/databases.png" />{0}</div>{1}{2}'.format( db_selection_form, placeholder, sfx, static_addr ) elif request.GET.get('sctn') in ('tbl', 'seq', 'views') : _dict = {'db': request.GET.get('db')} # get a dropdown of databases from db_list with its initial set to what is in request.GET db_selection_form = select_input(db_list, desc={'id':'db_select'}, initial= _dict['db']) s = '' if conn_params['dialect'] == 'postgresql': _dict['schm'] = request.GET.get('schm') # append schema selection with default to public schema_list = qry.common_query(conn_params, 'schema_list', request.GET)['rows'] schema_selection_form = select_input(schema_list,desc={'id':'schema_select'},initial=_dict['schm']) # s = '<div class="sidebar-item"><img class="icon-schemas" />' + schema_selection_form + "</div>" s = '<div class="sidebar-item"><img src="{1}/tt_img/schemas.png" />{0}</div>'.format( schema_selection_form, static_addr) # table selection ul # table_list = qry.rpr_query(conn_params, 'existing_tables', fns.qd(request.GET)) table_list = sa.get_table_names(conn_params, request.GET) table_list.sort() # noted that the list is sometimes not sorted from postgresql sfx_list = [] pg_sfx = '&schm=' + _dict['schm'] if conn_params['dialect']=='postgresql' else '' for tbl_row in table_list: # decide selected table li_pfx = " class='active'" if request.GET.get('tbl') == tbl_row else '' a = '<a class="icon-table tbl-link" href="#">%s</a>' % tbl_row sfx_list.append("<li{0}>{1}</li>".format(li_pfx, a)) # generate the string to be returned. It has the following order # 1. h6 saying 'quick navigation' # 2. db selection select element and schm selection select element if dialect is postgresql # 3. a h6.placeholder element shouting 'object types:' # 4. a ul having li > a each saying the specific 'object type' and linking to its appropriate view # ret_string = '<h6>quick nav:</h6><div><a class="james pull-right" href="">overview</a></div><br />\ bck_lnk = '<h6><a class="icon-back" href="#sctn=db&v=ov&db={0}{1}">back to overview</a>'.format( request.GET.get('db'), '&schm=%s' % request.GET.get('schm') if request.GET.get('schm') else '' ) ret_string = bck_lnk + '</h6>\ <h6>quick nav:</h6><div class="sidebar-item"><img src="{url}/tt_img/databases.png" /> {db_select}</div>\ {schema_select}{placeholder_html}{tbl_list}'.format( db_select = db_selection_form, schema_select = s, placeholder_html = '<h6 class="placeholder">%ss:</h6>' % fns._abbr[request.GET.get('sctn')], # 2 tbl_list = "<ul>{0}</ul>".format( ''.join(sfx_list) ), url = static_addr ) # return ret_string return HttpResponse(ret_string)