Exemple #1
0
def _getData(request, spec):
  """
  Helper function to query for data.

  Args:
    request: A Django request object; for querying tables.
    spec: A data spec object. See 'abstract.DataSourceConnection.queryTable' for
      more details.

  Returns:
    A dictionary with fields 'data' and 'meta' representing a Polychart2.js formatted
    data object.
  """
  tableName, dsKey = getDsInfo(spec)[0]
  connection       = getConnection(request, dsKey)
  return connection.queryTable(tableName, spec, 1000)
Exemple #2
0
def _getData(request, spec):
    """
  Helper function to query for data.

  Args:
    request: A Django request object; for querying tables.
    spec: A data spec object. See 'abstract.DataSourceConnection.queryTable' for
      more details.

  Returns:
    A dictionary with fields 'data' and 'meta' representing a Polychart2.js formatted
    data object.
  """
    tableName, dsKey = getDsInfo(spec)[0]
    connection = getConnection(request, dsKey)
    return connection.queryTable(tableName, spec, 1000)
Exemple #3
0
def tableQuery(request, _):
  """View Handler for performing a query on a table."""
  spec = json.loads(urllib.unquote(request.POST.get('spec', None)))
  assert spec, "Invalid query specification!"

  tableName, dsKey = getDsInfo(spec)[0]
  limit            = int(request.POST.get('limit', 1000))
  try:
    connection = getConnection(request, dsKey)
    result     = runConnectionMethod(
      connection,
      'queryTable',
      tableName,
      spec,
      limit
    )
  except ValueError as err:
    if len(err.args) > 0:
      return jsonResponse({'message': str(err.args[0])}, status=500)
    return jsonResponse({'message': None}, status=500)
  return jsonResponse(result) #saneEncoded already in queryTable
Exemple #4
0
def tableMeta(request, dsKey):
  """View Handler for returning table meta data."""
  tableName  = request.POST.get('tableName', None)
  columnExpr = json.loads(urllib.unquote(request.POST.get('columnExpr', None)))
  dataType   = request.POST.get('type', None)
  if None in [tableName, columnExpr, dataType]:
    raise ValueError("views.dataSource.tableMeta",
                     "Invalid request; missing data.")
  try:
    connection = getConnection(request, dsKey)
    result     = runConnectionMethod(
      connection,
      'getColumnMetadata',
      tableName,
      columnExpr,
      dataType
    )
  except ValueError as err:
    if len(err.args) > 0:
      return jsonResponse({'message': str(err.args[0])}, status=500)
    return jsonResponse({'message': None}, status=500)
  return jsonResponse(saneEncode(result))
Exemple #5
0
def tableList(request, dsKey):
  """View Handler for listing tables in a dashboard."""
  connection = getConnection(request, dsKey)
  tables     = runConnectionMethod(connection, 'listTables')
  return jsonResponse(saneEncode(tables))