Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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