Ejemplo n.º 1
0
def get_attrs_by_table(request):
    if request.is_ajax():
        if request.method == "GET":
            db_id = request.GET.get('db_id')
            table_name = request.GET.get('table')
            if db_id is None or table_name is None:
                return HttpResponseBadRequest()
            try:
                db = Database.objects.get(id=db_id, user=request.user)
            except Database.DoesNotExist:
                return JsonResponse({'status': 'bad'})
            conn = utils.check_mysql_connection(db.db_address, db.db_user, db.db_password, db.db_name)
            if not conn:
                return JsonResponse({'status': 'bad'})
            attrs = utils.get_attrs_by_table(conn, table_name)
            return JsonResponse({'status': 'ok', 'attrs': attrs})
        else:
            return HttpResponseBadRequest()
    else:
        return HttpResponseBadRequest()
Ejemplo n.º 2
0
def get_tables_by_db(request):
    if request.is_ajax():
        if request.method == "GET":
            db_id = request.GET.get('db_id')
            if db_id is None:
                return HttpResponseBadRequest()
            try:
                db = Database.objects.get(id=db_id)
            except Database.DoesNotExist:
                return JsonResponse({'status': 'bad'})
            if db.user != request.user:
                return JsonResponse({'status': 'bad'})
            conn = utils.check_mysql_connection(db.db_address, db.db_user, db.db_password, db.db_name)
            if not conn:
                return JsonResponse({'status': 'bad'})
            table_names = utils.get_table_names_by_connection(conn)
            return JsonResponse({'status': 'ok', 'tables': table_names})
        else:
            return HttpResponseBadRequest()
    else:
        return HttpResponseBadRequest()