def id_to_path( par_id ): '''Change parent id of a node in dbtree to name, description and label of all antecedants. Direct parent is the last element in the list.''' if par_id is None: return [] db_tree = sqldb.get_db_tree() # dict: id -> name id_dict = dict( zip([ n['id'] for n in db_tree ], db_tree) ) # move to next parents to get their info until top parent is reached path = [] parent_id = int( par_id ) while True: parent = id_dict[ parent_id ] path.append({ 'name': parent['name'], 'description': parent['description'], 'label': None }) try: parent_id = int( parent['parent'] ) except: break path.reverse() return path
def get_parent_id_tree(): flat_tree = sqldb.get_db_tree() parent_id_tree = {} for el in flat_tree: try: parent_id_tree[ el['parent'] ].append( el ) except KeyError: parent_id_tree[ el['parent'] ] = [ el ] return parent_id_tree
def get_parent_id_tree(): flat_tree = sqldb.get_db_tree() parent_id_tree = {} for el in flat_tree: try: parent_id_tree[el['parent']].append(el) except KeyError: parent_id_tree[el['parent']] = [el] return parent_id_tree
def collection_data_validated( data ): '''Check if collection with such a name and parent does not collide with the other potential siblings.''' db_tree = sqldb.get_db_tree() parent_id = data['parents'][0] siblings = filter( lambda e: e['parent'] == parent_id, db_tree ) name = data['name'] if len( data['parents'] ) == 1 else data['parents'][1]['name'] return name.encode('utf-8') not in [ sib['name'] for sib in siblings ]
def get_collections( req ): '''Get the navigation tree for all database collections''' # create a navigator for the db collections format = req.GET.get( 'format', 'list' ) collections = [] if format == 'list': collections = sqldb.get_db_tree() else: raise Exception('Bad format type') return HttpResponse( json.dumps( collections ) )
def init_restore( request, id ): '''Init application prepared to handle restore data''' dbtree = sqldb.get_db_tree() data = { 'dbtree': dbtree, 'id': id, 'endpoints': sqldb.get_permalink_endpoints( id ) } return render_to_response( 'app.html', data )
def get_collections(req): '''Get the navigation tree for all database collections''' # create a navigator for the db collections format = req.GET.get('format', 'list') collections = [] if format == 'list': collections = sqldb.get_db_tree() else: raise Exception('Bad format type') return HttpResponse(json.dumps(collections))
def init_restore(request, id): '''Init application prepared to handle restore data''' dbtree = sqldb.get_db_tree() data = { 'dbtree': dbtree, 'id': id, 'endpoints': sqldb.get_permalink_endpoints(id) } return render_to_response('app.html', data)
def get_search_count( uri, endpoint, query ): if endpoint == 'all_endpoints': db_tree = sqldb.get_db_tree() endpoints = [ el['endpoint'] for el in db_tree if el['endpoint'] is not None ] else: endpoints = [ endpoint ] data = sqldb.search_count( query, endpoints ) for result in data: result['search_data_uri'] = create_search_uri( uri, result['endpoint'] ) return data
def get_search_count(uri, endpoint, query): if endpoint == 'all_endpoints': db_tree = sqldb.get_db_tree() endpoints = [ el['endpoint'] for el in db_tree if el['endpoint'] is not None ] else: endpoints = [endpoint] data = sqldb.search_count(query, endpoints) for result in data: result['search_data_uri'] = create_search_uri(uri, result['endpoint']) return data
def get_endpoint_parents( endpoint ): flat_tree = sqldb.get_db_tree() id_tree = get_id_tree( flat_tree ) endpoint_id = filter( lambda el: el['endpoint'] == endpoint, flat_tree )[0]['id'] parents = [] act_node = id_tree[ endpoint_id ] while act_node['parent'] is not None: act_node = id_tree[ act_node['parent'] ] parents.append({ 'name': act_node['name'], 'descripition': act_node['description'] }) parents.reverse() return parents
def get_endpoint_parents(endpoint): flat_tree = sqldb.get_db_tree() id_tree = get_id_tree(flat_tree) endpoint_id = filter(lambda el: el['endpoint'] == endpoint, flat_tree)[0]['id'] parents = [] act_node = id_tree[endpoint_id] while act_node['parent'] is not None: act_node = id_tree[act_node['parent']] parents.append({ 'name': act_node['name'], 'descripition': act_node['description'] }) parents.reverse() return parents