def get(self): """ Retrieve a list of queries. :qparam number page_size: Number of queries to return :qparam number page: Page number to retrieve Responds with an array of :ref:`query <query-response-label>` objects. """ search_term = request.args.get('q') if search_term: results = models.Query.search(search_term, self.current_user.group_ids, include_drafts=True, limit=None) else: results = models.Query.all_queries(self.current_user.group_ids, self.current_user.id) results = filter_by_tags(results, models.Query.tags) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate(results, page, page_size, QuerySerializer, with_stats=True, with_last_modified_by=False) return response
def get(self): """ Retrieve a list of queries created by the current user. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by :qparam number search: Full text search term Responds with an array of :ref:`query <query-response-label>` objects. """ search_term = request.args.get('q', '') if search_term: results = models.Query.search_by_user(search_term, self.current_user) else: results = models.Query.by_user(self.current_user) results = filter_by_tags(results, models.Query.tags) # order results according to passed order parameter ordered_results = order_results(results) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) return paginate( ordered_results, page, page_size, QuerySerializer, with_stats=True, with_last_modified_by=False, )
def get(self): """ Lists all dashboards except archived and draft. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by """ results = models.Dashboard.get_all(self.current_org) results = filter_by_tags(results, models.Dashboard.tags) ordered_results = order_results(results) page = request.args.get("page", 1, type=int) page_size = request.args.get("page_size", 25, type=int) response = paginate( ordered_results, page=page, page_size=page_size, serializer=DashboardSerializer, ) self.record_event({"action": "list", "object_type": "dashboard"}) return response
def get(self): search_term = request.args.get('q') if search_term: base_query = models.Query.search(search_term, self.current_user.group_ids, include_drafts=True, limit=None) favorites = models.Query.favorites(self.current_user, base_query=base_query) else: favorites = models.Query.favorites(self.current_user) favorites = filter_by_tags(favorites, models.Query.tags) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate(favorites, page, page_size, QuerySerializer, with_stats=True, with_last_modified_by=False) self.record_event({ 'action': 'load_favorites', 'object_type': 'query', 'params': { 'q': search_term, 'tags': request.args.getlist('tags'), 'page': page } }) return response
def get(self): """ Retrieve a list of queries created by the current user. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by :qparam number search: Full text search term Responds with an array of :ref:`query <query-response-label>` objects. """ search_term = request.args.get('q', '') if search_term: results = models.Query.search_by_user(search_term, self.current_user) else: results = models.Query.by_user(self.current_user) results = filter_by_tags(results, models.Query.tags) # order results according to passed order parameter ordered_results = order_results(results) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) return paginate( ordered_results, page, page_size, QuerySerializer, with_stats=True, with_last_modified_by=False, )
def get(self): search_term = request.args.get('q') if search_term: base_query = models.Dashboard.search(self.current_org, self.current_user.group_ids, self.current_user.id, search_term) favorites = models.Dashboard.favorites(self.current_user, base_query=base_query) else: favorites = models.Dashboard.favorites(self.current_user) favorites = filter_by_tags(favorites, models.Dashboard.tags) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate(favorites, page, page_size, serialize_dashboard) self.record_event({ 'action': 'load_favorites', 'object_type': 'dashboard', 'params': { 'q': search_term, 'tags': request.args.getlist('tags'), 'page': page } }) return response
def get(self): search_term = request.args.get('q') if search_term: base_query = models.Dashboard.search(self.current_org, self.current_user.group_ids, self.current_user.id, search_term) favorites = models.Dashboard.favorites(self.current_user, base_query=base_query) else: favorites = models.Dashboard.favorites(self.current_user) favorites = filter_by_tags(favorites, models.Dashboard.tags) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate(favorites, page, page_size, serialize_dashboard) self.record_event({ 'action': 'load_favorites', 'object_type': 'dashboard', 'params': { 'q': search_term, 'tags': request.args.getlist('tags'), 'page': page } }) return response
def get(self): search_term = request.args.get('q') if search_term: base_query = models.Query.search(search_term, self.current_user.group_ids, include_drafts=True, limit=None) favorites = models.Query.favorites(self.current_user, base_query=base_query) else: favorites = models.Query.favorites(self.current_user) favorites = filter_by_tags(favorites, models.Query.tags) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate(favorites, page, page_size, QuerySerializer, with_stats=True, with_last_modified_by=False) self.record_event({ 'action': 'load_favorites', 'object_type': 'query', 'params': { 'q': search_term, 'tags': request.args.getlist('tags'), 'page': page } }) return response
def get(self): """ Retrieve a list of queries. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by :qparam number q: Full text search term Responds with an array of :ref:`query <query-response-label>` objects. """ # See if we want to do full-text search or just regular queries search_term = request.args.get('q', '') if search_term: results = models.Query.search( search_term, self.current_user.group_ids, self.current_user.id, include_drafts=True, ) else: results = models.Query.all_queries( self.current_user.group_ids, self.current_user.id, drafts=True, ) results = filter_by_tags(results, models.Query.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank ordered_results = order_results(results, fallback=bool(search_term)) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate( ordered_results, page=page, page_size=page_size, serializer=QuerySerializer, with_stats=True, with_last_modified_by=False ) if search_term: self.record_event({ 'action': 'search', 'object_type': 'query', 'term': search_term, }) else: self.record_event({ 'action': 'list', 'object_type': 'query', }) return response
def get(self): search_term = request.args.get('q') if search_term: base_query = models.Dashboard.search(self.current_org, self.current_user.group_ids, self.current_user.id, search_term) favorites = models.Dashboard.favorites(self.current_user, base_query=base_query) else: favorites = models.Dashboard.favorites(self.current_user) favorites = filter_by_tags(favorites, models.Dashboard.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank favorites = order_results(favorites, fallback=not bool(search_term)) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate(favorites, page, page_size, serialize_dashboard) self.record_event({ 'action': 'load_favorites', 'object_type': 'dashboard', 'params': { 'q': search_term, 'tags': request.args.getlist('tags'), 'page': page } }) return response
def get(self): search_term = request.args.get('q') if search_term: base_query = models.Dashboard.search(self.current_org, self.current_user.group_ids, self.current_user.id, search_term) favorites = models.Dashboard.favorites(self.current_user, base_query=base_query) else: favorites = models.Dashboard.favorites(self.current_user) favorites = filter_by_tags(favorites, models.Dashboard.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank favorites = order_results(favorites, fallback=not bool(search_term)) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate(favorites, page, page_size, serialize_dashboard) self.record_event({ 'action': 'load_favorites', 'object_type': 'dashboard', 'params': { 'q': search_term, 'tags': request.args.getlist('tags'), 'page': page } }) return response
def get(self): """ Retrieve a list of queries created by the current user. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by :qparam number search: Full text search term Responds with an array of :ref:`query <query-response-label>` objects. """ search_term = request.args.get("q", "") if search_term: results = models.Query.search_by_user(search_term, self.current_user) else: results = models.Query.by_user(self.current_user) results = filter_by_tags(results, models.Query.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank ordered_results = order_results(results, fallback=not bool(search_term)) page = request.args.get("page", 1, type=int) page_size = request.args.get("page_size", 25, type=int) return paginate( ordered_results, page, page_size, QuerySerializer, with_stats=True, with_last_modified_by=False, )
def get(self): """ Lists all accessible dashboards. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by :qparam number q: Full text search term Responds with an array of :ref:`dashboard <dashboard-response-label>` objects. """ search_term = request.args.get('q') if search_term: results = models.Dashboard.search( self.current_org, self.current_user.group_ids, self.current_user.id, search_term, ) else: results = models.Dashboard.all( self.current_org, self.current_user.group_ids, self.current_user.id, ) results = filter_by_tags(results, models.Dashboard.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank ordered_results = order_results(results, fallback=not bool(search_term)) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate( ordered_results, page=page, page_size=page_size, serializer=serialize_dashboard, ) if search_term: self.record_event({ 'action': 'search', 'object_type': 'dashboard', 'term': search_term, }) else: self.record_event({ 'action': 'list', 'object_type': 'dashboard', }) return response
def get(self): """ Retrieve a list of queries. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by :qparam number q: Full text search term Responds with an array of :ref:`query <query-response-label>` objects. """ # See if we want to do full-text search or just regular queries search_term = request.args.get('q', '') if search_term: results = models.Query.search( search_term, self.current_user.group_ids, self.current_user.id, include_drafts=True, ) else: results = models.Query.all_queries( self.current_user.group_ids, self.current_user.id, drafts=True, ) results = filter_by_tags(results, models.Query.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank ordered_results = order_results(results, fallback=bool(search_term)) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate(ordered_results, page=page, page_size=page_size, serializer=QuerySerializer, with_stats=True, with_last_modified_by=False) if search_term: self.record_event({ 'action': 'search', 'object_type': 'query', 'term': search_term, }) else: self.record_event({ 'action': 'list', 'object_type': 'query', }) return response
def get(self): """ Lists all accessible dashboards. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by :qparam number q: Full text search term Responds with an array of :ref:`dashboard <dashboard-response-label>` objects. """ search_term = request.args.get('q') if search_term: results = models.Dashboard.search( self.current_org, self.current_user.group_ids, self.current_user.id, search_term, ) else: results = models.Dashboard.all( self.current_org, self.current_user.group_ids, self.current_user.id, ) results = filter_by_tags(results, models.Dashboard.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank ordered_results = order_results(results, fallback=not bool(search_term)) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate( ordered_results, page=page, page_size=page_size, serializer=serialize_dashboard, ) if search_term: self.record_event({ 'action': 'search', 'object_type': 'dashboard', 'term': search_term, }) else: self.record_event({ 'action': 'list', 'object_type': 'dashboard', }) return response
def get_queries(self, search_term): if search_term: results = models.Query.search( search_term, self.current_user.group_ids, self.current_user.id, include_drafts=True, multi_byte_search=current_org.get_setting("multi_byte_search_enabled"), ) else: results = models.Query.all_queries( self.current_user.group_ids, self.current_user.id, include_drafts=True ) return filter_by_tags(results, models.Query.tags)
def get_queries(self, search_term): if search_term: results = models.Query.search( search_term, self.current_user.group_ids, self.current_user.id, include_drafts=True, ) else: results = models.Query.all_queries( self.current_user.group_ids, self.current_user.id, include_drafts=True, ) return filter_by_tags(results, models.Query.tags)
def get_queries(self, search_term): if search_term: results = models.Query.search( search_term, self.current_user.group_ids, self.current_user.id, include_drafts=True, ) else: results = models.Query.all_queries( self.current_user.group_ids, self.current_user.id, include_drafts=True, ) return filter_by_tags(results, models.Query.tags)
def get(self, query_id): """ Retrieve a query. :param query_id: ID of query to fetch Responds with the :ref:`query <query-response-label>` contents. """ q = get_object_or_404(models.Query.get_by_id_and_org, query_id, self.current_org) search_term = request.args.get('q') if search_term: results = models.Query.search_by_user(search_term, self.current_user) else: results = models.Query.by_user(self.current_user) results = filter_by_tags(results, models.Query.tags) ordered_results = order_results(results, fallback=not bool(search_term)) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate( ordered_results, page, page_size, QuerySerializer, with_stats=True, with_last_modified_by=False, ) ids = [] for r in response['results']: ids.append(r['id']) if q.id not in ids: require_access(q, self.current_user, view_only) result = QuerySerializer(q, with_visualizations=True).serialize() result['can_edit'] = can_modify(q, self.current_user) self.record_event({ 'action': 'view', 'object_id': query_id, 'object_type': 'query', }) return result
def get(self): """ Retrieve a list of queries. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by :qparam number q: Full text search term Responds with an array of :ref:`query <query-response-label>` objects. """ # See if we want to do full-text search or just regular queries search_term = request.args.get("q", "") queries = self.get_queries(search_term) results = filter_by_tags(queries, models.Query.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank ordered_results = order_results(results, fallback=not bool(search_term)) page = request.args.get("page", 1, type=int) page_size = request.args.get("page_size", 25, type=int) response = paginate( ordered_results, page=page, page_size=page_size, serializer=QuerySerializer, with_stats=True, with_last_modified_by=False, ) if search_term: self.record_event({ "action": "search", "object_type": "query", "term": search_term }) else: self.record_event({"action": "list", "object_type": "query"}) return response
def get(self): """ Lists all accessible dashboards. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by :qparam number q: Full text search term Responds with an array of :ref:`dashboard <dashboard-response-label>` objects. """ search_term = request.args.get('q') if search_term: results = models.Dashboard.search( self.current_org, self.current_user.group_ids, self.current_user.id, search_term, 'include_drafts' in request.args, ) else: results = models.Dashboard.all( self.current_org, self.current_user.group_ids, self.current_user.id, ) results = filter_by_tags(results, models.Dashboard.tags) # order results according to passed order parameter ordered_results = order_results(results) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate( ordered_results, page=page, page_size=page_size, serializer=serialize_dashboard, ) return response
def get(self): search_term = request.args.get("q") if search_term: base_query = models.Query.search( search_term, self.current_user.group_ids, include_drafts=True, limit=None, ) favorites = models.Query.favorites(self.current_user, base_query=base_query) else: favorites = models.Query.favorites(self.current_user) favorites = filter_by_tags(favorites, models.Query.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank ordered_favorites = order_results(favorites, fallback=not bool(search_term)) page = request.args.get("page", 1, type=int) page_size = request.args.get("page_size", 25, type=int) response = paginate( ordered_favorites, page, page_size, QuerySerializer, with_stats=True, with_last_modified_by=False, ) self.record_event( { "action": "load_favorites", "object_type": "query", "params": { "q": search_term, "tags": request.args.getlist("tags"), "page": page, }, } ) return response
def get(self): """ Lists all accessible dashboards. """ search_term = request.args.get('q') if search_term: results = models.Dashboard.search(self.current_org, self.current_user.group_ids, self.current_user.id, search_term, 'include_drafts' in request.args) else: results = models.Dashboard.all(self.current_org, self.current_user.group_ids, self.current_user.id) results = filter_by_tags(results, models.Dashboard.tags) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate(results, page, page_size, serialize_dashboard) return response
def get(self): """ Retrieve a list of queries. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by :qparam number q: Full text search term Responds with an array of :ref:`query <query-response-label>` objects. """ # See if we want to do full-text search or just regular queries search_term = request.args.get('q', '') if search_term: results = models.Query.search( search_term, self.current_user.group_ids, self.current_user.id, include_drafts=True, ) else: results = models.Query.all_queries( self.current_user.group_ids, self.current_user.id, drafts=True, ) results = filter_by_tags(results, models.Query.tags) # order results according to passed order parameter ordered_results = order_results(results) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate(ordered_results, page=page, page_size=page_size, serializer=QuerySerializer, with_stats=True, with_last_modified_by=False) return response
def get(self): """ Lists all accessible dashboards. :qparam number page_size: Number of queries to return per page :qparam number page: Page number to retrieve :qparam number order: Name of column to order by :qparam number q: Full text search term Responds with an array of :ref:`dashboard <dashboard-response-label>` objects. """ search_term = request.args.get('q') if search_term: results = models.Dashboard.search( self.current_org, self.current_user.group_ids, self.current_user.id, search_term, ) else: results = models.Dashboard.all( self.current_org, self.current_user.group_ids, self.current_user.id, ) results = filter_by_tags(results, models.Dashboard.tags) # order results according to passed order parameter ordered_results = order_results(results) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate( ordered_results, page=page, page_size=page_size, serializer=serialize_dashboard, ) return response
def get(self): search_term = request.args.get('q') if search_term: base_query = models.Query.search(search_term, self.current_user.group_ids, include_drafts=True, limit=None) favorites = models.Query.favorites(self.current_user, base_query=base_query) else: favorites = models.Query.favorites(self.current_user) favorites = filter_by_tags(favorites, models.Query.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank ordered_favorites = order_results(favorites, fallback=bool(search_term)) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate( ordered_favorites, page, page_size, QuerySerializer, with_stats=True, with_last_modified_by=False, ) self.record_event({ 'action': 'load_favorites', 'object_type': 'query', 'params': { 'q': search_term, 'tags': request.args.getlist('tags'), 'page': page } }) return response
def get(self): search_term = request.args.get("q") if search_term: base_query = models.Dashboard.search( self.current_org, self.current_user.group_ids, self.current_user.id, search_term, ) favorites = models.Dashboard.favorites( self.current_user, base_query=base_query ) else: favorites = models.Dashboard.favorites(self.current_user) favorites = filter_by_tags(favorites, models.Dashboard.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank favorites = order_results(favorites, fallback=not bool(search_term)) page = request.args.get("page", 1, type=int) page_size = request.args.get("page_size", 25, type=int) # TODO: we don't need to check for favorite status here response = paginate(favorites, page, page_size, DashboardSerializer) self.record_event( { "action": "load_favorites", "object_type": "dashboard", "params": { "q": search_term, "tags": request.args.getlist("tags"), "page": page, }, } ) return response
def get(self): """ Search query text, names, and descriptions. :qparam string q: Search term Responds with a list of :ref:`query <query-response-label>` objects. """ term = request.args.get('q', '') if not term: return [] include_drafts = request.args.get('include_drafts') is not None queries = models.Query.search(term, self.current_user.group_ids, include_drafts=include_drafts, limit=None) queries = filter_by_tags(queries, models.Query.tags) return QuerySerializer(queries, with_last_modified_by=False).serialize()
def get(self): search_term = request.args.get('q') if search_term: base_query = models.Query.search(search_term, self.current_user.group_ids, include_drafts=True, limit=None) favorites = models.Query.favorites(self.current_user, base_query=base_query) else: favorites = models.Query.favorites(self.current_user) favorites = filter_by_tags(favorites, models.Query.tags) # order results according to passed order parameter, # special-casing search queries where the database # provides an order by search rank ordered_favorites = order_results(favorites, fallback=bool(search_term)) page = request.args.get('page', 1, type=int) page_size = request.args.get('page_size', 25, type=int) response = paginate( ordered_favorites, page, page_size, QuerySerializer, with_stats=True, with_last_modified_by=False, ) self.record_event({ 'action': 'load_favorites', 'object_type': 'query', 'params': { 'q': search_term, 'tags': request.args.getlist('tags'), 'page': page } }) return response