Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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', '')

        results = self.get_queries(search_term)

        # 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))

        if request.args.has_key('all'):
            response = [
                serialize_query(result,
                                with_stats=True,
                                with_last_modified_by=False,
                                with_visualizations=True)
                for result in ordered_results
            ]
        else:
            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,
                                with_visualizations=True)

        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):
        """
        Retrieve a list of visualizations.

        :qparam number page_size: Number of visualizations 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:`visualization <visualization-response-label>` objects.
        """
        search_term = request.args.get('q', '')

        results = self.get_visualizations(search_term)

        # 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))

        if request.args.has_key('all'):
            response = [
                serialize_visualization(result) for result in ordered_results
            ]
        else:
            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_visualization)

        if search_term:
            self.record_event({
                'action': 'search',
                'object_type': 'visualization',
                'term': search_term,
            })
        else:
            self.record_event({
                'action': 'list',
                'object_type': 'visualization',
            })

        return response
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    def get(self):
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        groups = {
            group.id: group
            for group in models.Group.all(self.current_org)
        }

        def serialize_user(user):
            d = user.to_dict()
            user_groups = []
            for group_id in set(d['groups']):
                group = groups.get(group_id)

                if group:
                    user_groups.append({'id': group.id, 'name': group.name})

            d['groups'] = user_groups

            return d

        search_term = request.args.get('q', '')

        disabled = request.args.get('disabled',
                                    'false')  # get enabled users by default
        disabled = parse_boolean(disabled)

        pending = request.args.get(
            'pending', None)  # get both active and pending by default
        if pending is not None:
            pending = parse_boolean(pending)

        users = self.get_users(disabled, pending, search_term)

        return paginate(users, page, page_size, serialize_user)
Ejemplo n.º 6
0
    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,
        )
Ejemplo n.º 7
0
    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')
        viz_id = request.args.get('vis')

        if has_permission('admin'):
            if search_term:
                results = models.Dashboard.search(self.current_org,
                                                  self.current_user.group_ids,
                                                  self.current_user.id,
                                                  search_term, viz_id)
            else:
                results = models.Dashboard.all(self.current_org,
                                               self.current_user.group_ids,
                                               self.current_user.id, viz_id)
        else:
            results = models.Dashboard.get_by_dashboard_group(
                self.current_org, self.current_user.group_ids,
                self.current_user.id, viz_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))

        if request.args.has_key('all'):
            response = [
                serialize_dashboard(result) for result in ordered_results
            ]
        elif request.args.has_key('overview'):
            response = [
                serialize_dashboard_overview(result, user=self.current_user)
                for result in ordered_results
            ]
        else:
            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
Ejemplo n.º 8
0
 def get(self):
     page = request.args.get('page', 1, type=int)
     page_size = request.args.get('page_size', 25, type=int)
     return paginate(self.current_org.events, page, page_size, serialize_event)