def put(self, request, args=None): print(request.data) if args == 'connection': try: if request.data['permissions_type'] == 'user': info = DatabaseList.objects.all() print('1') con_name = Area(info, many=True).data print('2') dic = SqlDictionary.objects.all().values('Name') print('3') dic.query.distinct = ['Name'] else: con_name = [] _type = request.data['permissions_type'] + 'con' permission_spec = grained.objects.filter( username=request.user).first() for i in permission_spec.permissions[_type]: con_instance = DatabaseList.objects.filter( connection_name=i).first() if con_instance: con_name.append({ 'id': con_instance.id, 'connection_name': con_instance.connection_name, 'ip': con_instance.ip, 'computer_room': con_instance.computer_room }) dic = '' info = Account.objects.filter(is_staff=1).all() print('5') serializers = UserINFO(info, many=True) print('6') assigned = grained.objects.filter( username=request.user).first() print(assigned.permissions) return Response({ 'connection': con_name, 'person': serializers.data, 'dic': dic, 'assigend': assigned.permissions['person'] }) except Exception as e: print('dddddd') print(e) CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == "basename": try: con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port) as f: res = f.basename() return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'tablename': try: data = json.loads(request.data['data']) basename = data['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.tablename() return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'field': try: connection_info = json.loads(request.data['connection_info']) table = connection_info['tablename'] basename = connection_info['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: try: _connection = DatabaseList.objects.filter( id=con_id).first() with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.gen_alter(table_name=table) return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'indexdata': try: login = json.loads(request.data['login']) table = request.data['table'] basename = login['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: try: _connection = DatabaseList.objects.filter( id=con_id).first() with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.index(table_name=table) return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return Response(e)
def put(self, request, args=None): if args == 'connection': try: assigned = set_auth_group(request.user) un_init = util.init_conf() custom_com = ast.literal_eval(un_init['other']) if request.data['permissions_type'] == 'user' or request.data[ 'permissions_type'] == 'own_space': info = DatabaseList.objects.all() con_name = Area(info, many=True).data dic = SqlDictionary.objects.all().values('Name') dic.query.distinct = ['Name'] elif request.data['permissions_type'] == 'query': con_name = [] permission_spec = grained.objects.filter( username=request.user).first() if permission_spec.permissions['query'] == '1': for i in permission_spec.permissions['querycon']: con_instance = DatabaseList.objects.filter( connection_name=i).first() if con_instance: con_name.append({ 'id': con_instance.id, 'connection_name': con_instance.connection_name, 'ip': con_instance.ip, 'computer_room': con_instance.computer_room }) assigned = set_auth_group(request.user) return Response({ 'assigend': assigned['person'], 'connection': con_name, 'custom': custom_com['con_room'] }) else: con_name = [] _type = request.data['permissions_type'] + 'con' permission_spec = grained.objects.filter( username=request.user).first() for i in permission_spec.permissions[_type]: con_instance = DatabaseList.objects.filter( connection_name=i).first() if con_instance: con_name.append({ 'id': con_instance.id, 'connection_name': con_instance.connection_name, 'ip': con_instance.ip, 'computer_room': con_instance.computer_room }) dic = '' info = Account.objects.filter(group='admin').all() serializers = UserINFO(info, many=True) return Response({ 'connection': con_name, 'person': serializers.data, 'dic': dic, 'assigend': assigned['person'], 'custom': custom_com['con_room'], 'multi': custom_com['multi'] }) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == "basename": try: con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port) as f: res = f.baseItems(sql='show databases') return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'tablename': try: data = json.loads(request.data['data']) basename = data['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.baseItems(sql='show tables') return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'field': try: connection_info = json.loads(request.data['connection_info']) table = connection_info['tablename'] basename = connection_info['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: try: _connection = DatabaseList.objects.filter( id=con_id).first() with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.gen_alter(table_name=table) return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'indexdata': try: login = json.loads(request.data['login']) table = request.data['table'] basename = login['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: try: _connection = DatabaseList.objects.filter( id=con_id).first() with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.index(table_name=table) return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(e)
def put(self, request, args=None): if args == 'connection': try: assigned = grained.objects.filter( username=request.user).first() last_query = querypermissions.objects.filter( username=request.user).order_by('-id').first() un_init = util.init_conf() custom_com = ast.literal_eval(un_init['other']) if request.data['permissions_type'] == 'user' or request.data[ 'permissions_type'] == 'own_space': info = DatabaseList.objects.all() con_name = Area(info, many=True).data dic = SqlDictionary.objects.all().values('Name') dic.query.distinct = ['Name'] # elif request.data['permissions_type'] == 'query': # con_name = [] # permission_spec = grained.objects.filter(username=request.user).first() # if permission_spec.permissions['query'] == '1': # for i in permission_spec.permissions['querycon']: # con_instance = DatabaseList.objects.filter(connection_name=i).first() # if con_instance: # con_name.append( # { # 'id': con_instance.id, # 'connection_name': con_instance.connection_name, # 'ip': con_instance.ip , # 'computer_room': con_instance.computer_room # }) # assigned = grained.objects.filter(username=request.user).first() # return Response({'assigend': assigned.permissions['person'], 'connection': con_name, # 'custom': custom_com['con_room']}) else: con_name = [] _type = request.data['permissions_type'] + 'con' permission_spec = grained.objects.filter( username=request.user).first() for i in permission_spec.permissions[_type]: con_instance = DatabaseList.objects.filter( connection_name=i).first() if con_instance: con_name.append({ 'id': con_instance.id, 'connection_name': con_instance.connection_name, 'ip': con_instance.ip, 'computer_room': con_instance.computer_room }) dic = '' info = Account.objects.filter(group='admin').all() serializers = UserINFO(info, many=True) history = querypermissions.objects.filter( username=request.user).order_by('-id')[0:20] serializer_his = QueryPermissions(history, many=True) return Response({ 'connection': con_name, 'person': serializers.data, 'history': serializer_his.data, 'dic': dic, 'assigend': assigned.permissions['person'], 'custom': custom_com['con_room'], 'multi': custom_com['multi'], 'limit_num': custom_com['limit'], 'sql_display': custom_com['sql_display'], 'last_query': ast.literal_eval(last_query.db_info) if last_query else {}, 'last_sql': last_query.statements if last_query else "" }) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'optimizer': try: assigned = grained.objects.filter( username=request.user).first() last_query = sql_optimize_his.objects.filter( username=request.user).order_by('-id').first() un_init = util.init_conf() custom_com = ast.literal_eval(un_init['other']) if request.data['permissions_type'] == 'user' or request.data[ 'permissions_type'] == 'own_space': info = DatabaseList.objects.all() con_name = Area(info, many=True).data dic = SqlDictionary.objects.all().values('Name') dic.query.distinct = ['Name'] else: con_name = [] _type = request.data['permissions_type'] + 'con' permission_spec = grained.objects.filter( username=request.user).first() for i in permission_spec.permissions[_type]: con_instance = DatabaseList.objects.filter( connection_name=i).first() if con_instance: con_name.append({ 'id': con_instance.id, 'connection_name': con_instance.connection_name, 'ip': con_instance.ip, 'computer_room': con_instance.computer_room }) dic = '' info = Account.objects.filter(group='admin').all() serializers = UserINFO(info, many=True) history = sql_optimize_his.objects.filter( username=request.user).order_by('-id')[0:10] serializer_his = Sql_Optimize_His(history, many=True) return Response({ 'connection': con_name, 'person': serializers.data, 'history': serializer_his.data, 'dic': dic, 'assigend': assigned.permissions['person'], 'custom': custom_com['con_room'], 'multi': custom_com['multi'], 'limit_num': custom_com['limit'], 'last_query': ast.literal_eval(last_query.db_info) if last_query else {}, 'last_sql': last_query.statements if last_query else "" }) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == "basename": try: con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port) as f: res = f.basename() return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == "binlogs": try: con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port) as f: res = f.binlogs() return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == "table_names": try: con_id = request.data['id'] db_name = request.data['db'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=db_name) as f: res = f.table_names() return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == "column_names": try: con_id = request.data['id'] db_name = request.data['db'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=db_name) as f: res = f.column_names() return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'tablename': try: data = json.loads(request.data['data']) basename = data['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.tablename() return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'field': try: connection_info = json.loads(request.data['connection_info']) table = connection_info['tablename'] basename = connection_info['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: try: _connection = DatabaseList.objects.filter( id=con_id).first() with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.gen_alter(table_name=table) return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'indexdata': try: login = json.loads(request.data['login']) table = request.data['table'] basename = login['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: try: _connection = DatabaseList.objects.filter( id=con_id).first() with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.index(table_name=table) return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return Response(e) elif args == 'binlog2sql': try: assigned = grained.objects.filter( username=request.user).first() un_init = util.init_conf() custom_com = ast.literal_eval(un_init['other']) if request.data['permissions_type'] == 'admin': info = DatabaseList.objects.all() con_name = Area(info, many=True).data info = Account.objects.filter(group='admin').all() serializers = UserINFO(info, many=True) return Response({ 'connection': con_name, 'person': serializers.data, 'assigend': assigned.permissions['person'], 'custom': custom_com['con_room'], 'sql_display': custom_com['sql_display'], }) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'slowlog': try: assigned = grained.objects.filter( username=request.user).first() un_init = util.init_conf() custom_com = ast.literal_eval(un_init['other']) if request.data['permissions_type'] == 'query': con_name = [] _type = request.data['permissions_type'] + 'con' permission_spec = grained.objects.filter( username=request.user).first() for i in permission_spec.permissions[_type]: con_instance = DatabaseList.objects.filter( connection_name=i).first() if con_instance: con_name.append({ 'id': con_instance.id, 'connection_name': con_instance.connection_name, 'ip': con_instance.ip, 'computer_room': con_instance.computer_room }) dic = '' info = Account.objects.filter(group='admin').all() serializers = UserINFO(info, many=True) return Response({ 'connection': con_name, 'assigend': assigned.permissions['person'], 'custom': custom_com['con_room'], 'sql_display': custom_com['sql_display'], }) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'events': try: un_init = util.init_conf() custom_com = ast.literal_eval(un_init['other']) if request.data['permissions_type'] == 'query': con_name = [] res_data = [] _type = request.data['permissions_type'] + 'con' permission_spec = grained.objects.filter( username=request.user).first() for i in permission_spec.permissions[_type]: con_instance = DatabaseList.objects.filter( connection_name=i).first() if con_instance: con_name.append({ 'id': con_instance.id, 'connection_name': con_instance.connection_name, 'ip': con_instance.ip, 'computer_room': con_instance.computer_room }) # data_set=Event.get_data(self,con_instance) # for i in data_set['data']: # res_data.append(i) total = len(res_data) res = { 'connection': con_name, 'custom': custom_com['con_room'], 'sql_display': custom_com['sql_display'], 'sql_limit': custom_com['limit'], 'data': res_data, 'total': total } return HttpResponse( simplejson.dumps(res, cls=DateEncoder, bigint_as_string=True)) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500)
def put(self, request, args=None): if args == 'connection': try: assigned = set_auth_group(request.user) un_init = util.init_conf() custom_com = ast.literal_eval(un_init['other']) print("user:"******"basename": try: con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port) as f: res = f.baseItems(sql='show databases') exclude_db = serachsql.exclued_db_list() for db in exclude_db: if db in res: res.remove(db) return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'tablename': try: data = json.loads(request.data['data']) basename = data['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.baseItems(sql='show tables') return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'field': try: connection_info = json.loads(request.data['connection_info']) table = connection_info['tablename'] basename = connection_info['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: try: _connection = DatabaseList.objects.filter( id=con_id).first() with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: field = f.gen_alter(table_name=table) idx = f.index(table_name=table) return Response({'idx': idx, 'field': field}) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500)
def put(self, request, args=None): if args == 'connection': try: assigned = grained.objects.filter(username=request.user).first() un_init = util.init_conf() custom_com = ast.literal_eval(un_init['other']) if request.data['permissions_type'] == 'user' or request.data['permissions_type'] == 'own_space': info = DatabaseList.objects.all() con_name = Area(info, many=True).data dic = SqlDictionary.objects.all().values('Name') dic.query.distinct = ['Name'] elif request.data['permissions_type'] == 'query': con_name = [] permission_spec = grained.objects.filter(username=request.user).first() if permission_spec.permissions['query'] == '1': for i in permission_spec.permissions['querycon']: con_instance = DatabaseList.objects.filter(connection_name=i).first() if con_instance: con_name.append( { 'id': con_instance.id, 'connection_name': con_instance.connection_name, 'ip': con_instance.ip , 'computer_room': con_instance.computer_room }) assigned = grained.objects.filter(username=request.user).first() return Response({'assigend': assigned.permissions['person'], 'connection': con_name, 'custom': custom_com['con_room']}) else: con_name = [] _type = request.data['permissions_type'] + 'con' permission_spec = grained.objects.filter(username=request.user).first() for i in permission_spec.permissions[_type]: con_instance = DatabaseList.objects.filter(connection_name=i).first() if con_instance: con_name.append( { 'id': con_instance.id, 'connection_name': con_instance.connection_name, 'ip': con_instance.ip, 'computer_room': con_instance.computer_room }) dic = '' info = Account.objects.filter(group='admin').all() serializers = UserINFO(info, many=True) return Response( { 'connection': con_name, 'person': serializers.data, 'dic': dic, 'assigend': assigned.permissions['person'], 'custom': custom_com['con_room'], 'multi': custom_com['multi'] } ) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == "basename": try: con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo( ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port ) as f: res = f.basename() return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'tablename': try: data = json.loads(request.data['data']) basename = data['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: _connection = DatabaseList.objects.filter(id=con_id).first() try: with con_database.SQLgo( ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename ) as f: res = f.tablename() return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'field': try: connection_info = json.loads(request.data['connection_info']) table = connection_info['tablename'] basename = connection_info['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: try: _connection = DatabaseList.objects.filter(id=con_id).first() with con_database.SQLgo( ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename ) as f: res = f.gen_alter(table_name=table) return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'indexdata': try: login = json.loads(request.data['login']) table = request.data['table'] basename = login['basename'] con_id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: try: _connection = DatabaseList.objects.filter(id=con_id).first() with con_database.SQLgo( ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename ) as f: res = f.index(table_name=table) return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return Response(e)
def put(self, request, args=None): if args == 'connection': try: info = DatabaseList.objects.all() _serializers = Area(info, many=True) info = Account.objects.filter(is_staff=1).all() serializers = UserINFO(info, many=True) return Response({ 'connection': _serializers.data, 'person': serializers.data }) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == "basename": try: id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) else: _connection = DatabaseList.objects.filter(id=id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port) as f: res = f.basename() return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'tablename': try: data = json.loads(request.data['data']) basename = data['basename'] id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: _connection = DatabaseList.objects.filter(id=id).first() try: with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.tablename() return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'field': try: connection_info = json.loads(request.data['connection_info']) table = connection_info['tablename'] basename = connection_info['basename'] id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: try: _connection = DatabaseList.objects.filter(id=id).first() with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.gen_alter(table_name=table) return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return HttpResponse(status=500) elif args == 'indexdata': try: login = json.loads(request.data['login']) table = request.data['table'] basename = login['basename'] id = request.data['id'] except KeyError as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') else: try: _connection = DatabaseList.objects.filter(id=id).first() with con_database.SQLgo(ip=_connection.ip, user=_connection.username, password=_connection.password, port=_connection.port, db=basename) as f: res = f.index(table_name=table) return Response(res) except Exception as e: CUSTOM_ERROR.error(f'{e.__class__.__name__}: {e}') return Response(e)