def api_view(): api_obj = build_api_obj() table = manager.find_table(api_obj) api_obj = crosswalk(table, api_obj) data = api.query(table, api_obj) return data
def multitable_value_filters(tables, api_obj): '''This method examines the values pased in query args (e.g. year=2014 or geo=04000US25), and applies the logic depending on the crosswalk mode. If the auto-crosswalk is not enabled, special logic (gen_combos) is required to preserve null values so the user will see that no value is available. Otherwise, if auto-crosswalk is enabled, treat each filter as an AND conjunction. Return the list of filters to be applied. ''' filts = [] for colname, val in api_obj.vars_and_vals.items(): related_tables = tables_by_col(tables, colname) if not api_obj.auto_crosswalk: filts += gen_combos(related_tables, colname, val) else: for table in related_tables: if colname == consts.YEAR and val in [ consts.LATEST, consts.OLDEST ]: years = TableManager.table_years[table_name(table)] my_year = years[val] filt = or_(table.year == my_year, table.year == None) api_obj.set_year(my_year) else: api_obj_tmp = crosswalk( table, ApiObject(vars_and_vals={colname: val}, limit=None, exclude=None)) new_vals = splitter(api_obj_tmp.vars_and_vals[colname]) mycol = getattr(table, colname) filt = mycol.in_(new_vals) filts.append(filt) return filts
def crosswalk(cls, table, api_obj): return crosswalker.crosswalk(table, api_obj)
def multi_crosswalk(cls, tables, api_obj): for tbl in tables: api_obj = crosswalker.crosswalk(tbl, api_obj) return api_obj