def get(self): """ Perform a search """ args = flask.request.args.to_dict() if args is None: args = {} db_name = args.pop('db_name', None) page = int(args.pop('page', 0)) limit = int(args.pop('limit', 20)) sort = args.pop('sort', None) sort_asc = args.pop('sort_asc', 'true').lower() == 'true' # Special cases from_ticket = args.pop('ticket', None) if db_name == 'requests' and from_ticket: ticket_database = Database('tickets') ticket = ticket_database.get(from_ticket) created_requests = ','.join(ticket['created_requests']) prepid_query = args.pop('prepid', '') args['prepid'] = ('%s,%s' % (prepid_query, created_requests)).strip(',') limit = max(1, min(limit, 500)) query_string = '&&'.join(['%s=%s' % (pair) for pair in args.items()]) database = Database(db_name) query_string = database.build_query_with_types(query_string, self.classes[db_name]) results, total_rows = database.query_with_total_rows( query_string=query_string, page=page, limit=limit, sort_attr=sort, sort_asc=sort_asc, ignore_case=True) return self.output_text({ 'response': { 'results': results, 'total_rows': total_rows }, 'success': True, 'message': '' })
def get(self): """ Perform a search """ args = flask.request.args.to_dict() if args is None: args = {} db_name = args.pop('db_name', None) page = int(args.pop('page', 0)) limit = int(args.pop('limit', 20)) sort = args.pop('sort', None) sort_asc = args.pop('sort_asc', None) # Special cases from_ticket = args.pop('ticket', None) if db_name == 'relvals' and from_ticket: ticket_database = Database('tickets') tickets = ticket_database.query( query_string=f'prepid={from_ticket}', limit=100, ignore_case=True) created_relvals = [] for ticket in tickets: created_relvals.extend(ticket['created_relvals']) created_relvals = ','.join(created_relvals) prepid_query = args.pop('prepid', '') args['prepid'] = ('%s,%s' % (prepid_query, created_relvals)).strip(',') # Sorting logic: by default sort dsc by cration time if sort is None: sort = 'created_on' if sort == 'created_on' and sort_asc is None: sort_asc = False if sort_asc is None: sort_asc = True limit = max(1, min(limit, 500)) sort_asc = str(sort_asc).lower() == 'true' query_string = '&&'.join(['%s=%s' % (pair) for pair in args.items()]) database = Database(db_name) query_string = database.build_query_with_types(query_string, self.classes[db_name]) results, total_rows = database.query_with_total_rows( query_string=query_string, page=page, limit=limit, sort_attr=sort, sort_asc=sort_asc, ignore_case=True) return self.output_text({ 'response': { 'results': results, 'total_rows': total_rows }, 'success': True, 'message': '' })