def card(request, repo_base, repo, card_name): username = request.user.get_username() # if the user is actually executing a query current_page = 1 if request.POST.get('page'): current_page = request.POST.get('page') url_path = reverse('browser-query', args=(repo_base, repo)) manager = DataHubManager(user=username, repo_base=repo_base) card = manager.get_card(repo=repo, card_name=card_name) res = manager.paginate_query(query=card.query, current_page=current_page, rows_per_page=50) # get annotation to the table: annotation, created = Annotation.objects.get_or_create(url_path=url_path) annotation_text = annotation.annotation_text data = { 'login': username, 'repo_base': repo_base, 'repo': repo, 'annotation': annotation_text, 'current_page': current_page, 'next_page': current_page + 1, # the template should relaly do this 'prev_page': current_page - 1, # the template should relaly do this 'url_path': url_path, 'query': card.query, 'select_query': res['select_query'], 'column_names': res['column_names'], 'tuples': res['rows'], 'total_pages': res['total_pages'], 'pages': range(res['start_page'], res['end_page'] + 1), # template 'num_rows': res['num_rows'], 'time_cost': res['time_cost'] } data.update(csrf(request)) return render_to_response("card-browse.html", data)
def card(request, repo_base, repo, card_name): username = request.user.get_username() # if the user is actually executing a query current_page = 1 if request.POST.get('page'): current_page = request.POST.get('page') url_path = reverse('browser-query', args=(repo_base, repo)) manager = DataHubManager(user=username, repo_base=repo_base) card = manager.get_card(repo=repo, card_name=card_name) res = manager.paginate_query( query=card.query, current_page=current_page, rows_per_page=50) # get annotation to the table: annotation, created = Annotation.objects.get_or_create(url_path=url_path) annotation_text = annotation.annotation_text data = { 'login': username, 'repo_base': repo_base, 'repo': repo, 'annotation': annotation_text, 'current_page': current_page, 'next_page': current_page + 1, # the template should relaly do this 'prev_page': current_page - 1, # the template should relaly do this 'url_path': url_path, 'query': card.query, 'select_query': res['select_query'], 'column_names': res['column_names'], 'tuples': res['rows'], 'total_pages': res['total_pages'], 'pages': range(res['start_page'], res['end_page'] + 1), # template 'num_rows': res['num_rows'], 'time_cost': res['time_cost'] } data.update(csrf(request)) return render_to_response("card-browse.html", data)