def search(self, request, key, cur_page, db_name=None, type_=None): if key == '': return render_with_menu(request, 'search.html') pri, *other = key.split() if type_ == "表名": search_info = self.engine.get_column_info(table_schema=db_name, tab=pri) elif type_ == "内容": if other: base_info = other else: base_info = pri search_info = self.engine.get_column_info(table_schema=db_name, col=base_info) else: return render_with_menu(request, 'result.html', {}) per_page_num = 12 paginator = Paginator(len(search_info), cur_page, per_page_num) context = { 'key': key, 'dbName': db_name, 'SType': type_, 'search_list': search_info[(cur_page - 1) * per_page_num:cur_page * per_page_num], 'paginator': paginator, } return render_with_menu(request, 'result.html', context)
def get(self, request, index=0): index = int(index) if index: menu = Menu.objects.filter(id=index).first() msg = { 'status': 'success', 'data': model_to_dict(menu, exclude=['created_time', 'updated_time']) } return jsonify(msg) else: menu_list = Menu.objects.all().order_by('parent_id', '-order').values() paginator = Paginator(menu_list, 15) # get 方法获取页数 page = request.GET.get('page', 1) try: # 获取某页 menu_list = paginator.page(page) except PageNotAnInteger: # 如果 page 参数不为正整数,显示第一页 menu_list = paginator.page(1) except EmptyPage: # 如果 page 参数为空页,跳到最后一页 menu_list = paginator.page(paginator.num_pages) context = {'menu_list': menu_list} if request.user.has_perm('user.write_menu'): context['writable'] = '1' return render_with_menu(request, 'menu.html', context)
def update_mongo_connector(request, index): connector = MongoConnector.objects.filter(id=index).first() databases = Mongo.objects.filter(is_deleted=0) context = { 'connector': connector, 'databases': databases, 'action': 'update', 'action_name': '修改', } if request.user.has_perm('user.write_mongo_connector'): context['writable'] = '1' return render_with_menu(request, 'mongo_connector_detail.html', context)
def copy_mysql_connector(request, index): connector = MySQLConnector.objects.filter(id=index).first() databases = Database.objects.filter(is_deleted=0) context = { 'connector': connector, 'databases': databases, 'action': 'copy', 'action_name': '复制', } if request.user.has_perm('user.write_mysql_connector'): context['writable'] = '1' return render_with_menu(request, 'connector_detail.html', context)
def get(self, request): key = request.GET.get('key') db_name = request.GET.get('dbName') db_name = None if db_name in ("全库检索", 'None') else db_name type_ = request.GET.get('type') # 表名 内容 if not key: return render_with_menu(request, 'search.html') else: cur_page = int(request.GET.get('p', 1)) return self.search(request, key, s2i(cur_page, 1), db_name=db_name, type_=type_)
def get(self, request, table_schema, table_name): column_info = self.engine.get_column_info(table_schema=table_schema, tab=table_name) statistics_info = self.engine.get_statistics_info( table_schema=table_schema, tab=table_name) comment = self.engine.get_comment(table_name, table_schema) if column_info and statistics_info: column_info[0]['statistics_info'] = statistics_info[0].get( 'statistics_info') if column_info and comment: column_info[0]['comment'] = comment[0].get('comment') return render_with_menu(request, 'detail.html', {'details': column_info})
def get(self, request): """ 根据以下请求参数,查询相应的数据并响应页面 page: int, 页码,可为空,为空时默认为第一页 sort_field: str 排序字段名,默认正向排序,若字段名前面加'-',则为倒序,可为空,为空时模式按主键id正向排序 query: str,搜素关键字,可为空,为空时模式无搜素 :param request: :return: """ # TODO 处理 table_data.html 中date表新增字段的weekday的相关更新 query = request.GET.get('query') path = self.get_path(request) model = self.current_model(request) if query == '': return redirect(path) cxt = dict() page = int(request.GET.get('page', 1)) sort_field = request.GET.get('sort_field', 'id') if sort_field[0] == '-': sort_ = { 'field': sort_field[1:], 'order': '-alt', 'next_order': '' } else: sort_ = {'field': sort_field, 'order': '', 'next_order': '-'} sort_['sort_field'] = sort_field sum_pages = model.sum_pages(query) cxt['table_names'] = model.table_names() cxt['page_data'] = model.find_by_page(page, query=query, sort_field=sort_field) cxt['verbose_columns'] = model.table_columns() cxt['pages'] = make_page_info(page, sum_pages) cxt['write_perm'] = self.has_write_perm(request) cxt['sort'] = sort_ cxt['path'] = path if query is not None: cxt['query'] = query return render_with_menu(request, 'table_data.html', cxt)
def user_operation_log(request, index=0): index = int(index) if index: menu = OperationLog.objects.filter(id=index).first() msg = { 'status': 'success', 'data': model_to_dict(menu, exclude=['created_time', 'updated_time']) } return jsonify(msg) else: log_size = OperationLog.objects.all().order_by('-created_time').count() cur_page = request.GET.get('page', 1) paginator = Paginator(log_size, cur_page) table_name = OperationLog._meta.db_table sql = f""" select * from {table_name} a, ( select id from {table_name} order by id desc limit {paginator.limit} offset {paginator.offset} ) b where a.id=b.id order by a.id desc ; """ # No QA log_list = OperationLog.objects.raw(sql) context = { 'log_list': log_list, 'paginator': paginator, } return render_with_menu(request, 'log.html', context)
def get(self, request): connectors = MongoConnector.objects.filter() context = {'connectors': connectors} if request.user.has_perm('user.write_mongo_connector'): context['writable'] = '1' return render_with_menu(request, 'mongo_connectors.html', context)
def get(self, request): return render_with_menu(request, 'user.html', {'key': DES_KEY})
def show_dashboard(request): return render_with_menu(request, 'dashboard.html')