Skip to content

Instantly share code, notes, and snippets.

@jmelloy
Created June 19, 2013 16:54
Show Gist options
  • Save jmelloy/5815886 to your computer and use it in GitHub Desktop.
Save jmelloy/5815886 to your computer and use it in GitHub Desktop.
def create_auto_filters(query, result):
columns = [int(x) for x in query["auto_filter_columns"].split(",")]
data_columns = [int(x) for x in query["auto_filter_column_data"].split(",")]
conn = global_oms.connect()
for row in result["rows"]:
title = query["name"]
url_name = [query["url_name"]]
qry_filter = []
for c in columns:
title += " - " + result["columns"][c] + ":" + row[c]
qry_filter.append("%s=%s" % (result["columns"][c], row[c]))
url_name.append((result["columns"][c] + '.' + row[c]).replace(" ", "_"))
qry_filter = "&".join(qry_filter)
url_name = '.'.join(url_name)
print url_name, qry_filter, row
rs = conn.execute("""select 1 from dashboard_queries
where parent_query_id = ? and filter_string = ?
and complex_total_type = coalesce(?, 'rollup_last_row') and complex_column_index = ?
and auto_generated = 1""",
(query["id"], qry_filter, query["auto_filter_column_type"], query["auto_filter_column_data"]))
f = rs.fetchone()
print f
if not f:
conn.execute("""insert into dashboard_queries (name, url_name, parent_query_id, filter_string, enabled,
complex, complex_total_type, complex_column_index, auto_generated)
values (?, ?, ?, ?, ?, ?, ?, ?, ?)""", (title, url_name, query["id"], qry_filter,
1, 1, query["auto_filter_column_type"], query["auto_filter_column_data"], 1))
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment