def view(environ, start_response): """ View comment all users. :param environ: :param start_response: :return: """ try: status, result = query_to_db(sql_show_info, out='all') except Exception as ex: result = '' html = """ <tr class="view__tbody_row"> <td class="view__tbody_cell hidden">{0}</td> <td class="view__tbody_cell">{1}</td> <td class="view__tbody_cell">{2}</td> <td class="view__tbody_cell view__tbody_delete"><a href="{3}" class="delete">удалить</a></td> """ html_table = [html.format(ru_encode(name), ru_encode(lastname), ru_encode(cmt), user_id, ) for name, lastname, cmt, user_id in result] mapping = { 'data': ''.join(html_table), } start_response('200 OK', [('Content-Type', 'text/html')]) return render('view.html', mapping)
def stat(environ, start_response): """ View info of region :param environ: :param start_response: :return: """ try: status, result = query_to_db(sql_show_statistic, out='all') except Exception as ex: result = '' html = """ <tr class="statistic__tbody_row"> <td class="statistic__tbody_cell"> <a class="statistic__link" href="{2}"> {0}</a> </td> <td class="statistic__tbody_cell"> {1}</td> """ html_table = [html.format(ru_encode(name), count, region_id, ) for name, count, region_id in result] mapping = { 'data': ''.join(html_table), } start_response('200 OK', [('Content-Type', 'text/html')]) return render('stat.html', mapping)
def city_search(environ, start_response): """ POST REQUEST remove comment from database. :param environ: environ :param start_response: :return: if post when return json request, if is GET """ query_str = parse_qs(environ['QUERY_STRING']) user_query = query_str.get('term', [''])[0] result = '' if user_query: # TODO: Это костыль, костылянский, но sqlite не может не ascii символы переводить в lower или upper. u_user_query = ru_decode(user_query) search_query = ''.join([u_user_query[0].upper(), u_user_query[1:].lower()]) status, result = query_to_db(sql_city_autocomplete.format(ru_encode(search_query)), out='all') start_response('200 OK', [('Content-Type', 'text/html')]) return [json.dumps({'data': zip(*result)[0] if result else ''})]