def add_table_query_criteria(self, orig_criteria): criteria = {} # add criteria from get params filters = util.get_filters() for key, val in filters.items(): if key in self.fc.fields: field = self.fc.fields[key] criteria_key = (field.TableObject.name, field.Field.display_name) criteria[criteria_key] = val # add criteria from db res = self.rac.table_query_criteria( self.id ) for row in res: criteria_key = (row.TableObject.name, row.Field.display_name) if row.TableQueryCriteria.comparator != None: criteria[criteria_key] = { 'compare': row.TableQueryCriteria.comparator, 'value': row.TableQueryCriteria.value } else: criteria[criteria_key] = row.TableQueryCriteria.value criteria.update(orig_criteria) return criteria
def _get_queries(self): filters = util.get_filters() table_queries_info = [] if not 'all' in filters: # all overrides table_query, shows all fields route = util.get_path(2) table_queries_info = self.rac.table_queries(route, self.table_name) queries = [] if table_queries_info: # if table_query defined, use id for query in table_queries_info: # page can have multiple query = TableQuery( query.TableQuery.id, query.TableQuery.order, query.TableQuery.display_name, None, self.criteria ) queries.append(query) elif self.table_name: # use table_name, show all fields, one table_query table_object_row = self.rac.get_role_row('table_object', {'name': self.table_name}) if table_object_row.TableObjectRole.display_name: display_name = table_object_row.TableObjectRole.display_name else: display_name = table_object_row.TableObject.display_name query = TableQuery( None, 1, display_name, self.table_name, self.criteria) queries.append(query) return queries
def build_summary_ajax(table_name, criteria = {}): start = time.time() route = util.get_path(util.ROUTE) # TODO: we don't want oac instantiated multiple times oac = g_helper.get_org_access_control() ret = None filters = util.get_filters() key = current_app.cache.make_key( route, g.rac.role.id, oac.current_org_id, table_name ) if (not criteria and 'no_cache' not in filters): print('checking cache') ret = current_app.cache.get(key) ret = None if not ret: print('cache miss') tqc = TableQueryCollection(table_name, criteria) current = time.time() print(str(current - start)) tqc.get_results() current = time.time() print(str(current - start)) tqc.format_results() current = time.time() print(str(current - start)) table_query = tqc.get_first() current = time.time() print(str(current - start)) json_rows = table_query.get_row_list() current = time.time() print(str(current - start)) ret = jsonify({'data': json_rows}) if not criteria: print('caching') current_app.cache.set(key, ret, (24 * 60 * 60), [table_name]) else: print('cache hit') return ret