(self)
return jsonify({'objects': return_sketches, 'meta': meta})
Handles GET request to the resource.

        Returns:
            List of sketches (instance of flask.wrappers.Response)
Handles GET request to the resource.
Handles GET request to the resource .
def get(self):
        """Handles GET request to the resource.

        Returns:
            List of sketches (instance of flask.wrappers.Response)
        """
        args = self.parser.parse_args()
        scope = args.get('scope')
        page = args.get('page')
        per_page = args.get('per_page')
        search_query = args.get('search_query')
        include_archived = args.get('include_archived')

        if current_user.admin and scope == 'admin':
            sketch_query = Sketch.query
        else:
            sketch_query = Sketch.all_with_acl()

        base_filter = sketch_query.filter(
            not_(Sketch.Status.status == 'deleted'),
            not_(Sketch.Status.status == 'archived'),
            Sketch.Status.parent).order_by(Sketch.updated_at.desc())

        base_filter_with_archived = sketch_query.filter(
            not_(Sketch.Status.status == 'deleted'),
            Sketch.Status.parent).order_by(Sketch.updated_at.desc())

        filtered_sketches = base_filter_with_archived
        sketches = []
        return_sketches = []

        has_next = False
        has_prev = False
        next_page = None
        prev_page = None
        current_page = 1
        total_pages = 0
        total_items = 0

        if scope == 'recent':
            # Get list of sketches that the user has actively searched in.
            # TODO: Make this cover more actions such as story updates etc.
            # TODO: Right now we only return the top 3, make this configurable.
            views = View.query.filter_by(
                user=current_user, name='').order_by(
                View.updated_at.desc()).limit(3)
            sketches = [view.sketch for view in views]
            total_items = len(sketches)
        elif scope == 'admin':
            if not current_user.admin:
                abort(HTTP_STATUS_CODE_FORBIDDEN, 'User is not an admin.')
            if include_archived:
                filtered_sketches = base_filter_with_archived
            else:
                filtered_sketches = base_filter
        elif scope == 'user':
            filtered_sketches = base_filter.filter_by(user=current_user)
        elif scope == 'archived':
            filtered_sketches = sketch_query.filter(
                Sketch.status.any(status='archived'))
        elif scope == 'shared':
            filtered_sketches = base_filter.filter(Sketch.user != current_user)
        elif scope == 'search':
            filtered_sketches = base_filter_with_archived.filter(
                or_(
                    Sketch.name.ilike(f'%{search_query}%'),
                    Sketch.description.ilike(f'%{search_query}%')
                )
            )

        if not sketches:
            pagination = filtered_sketches.paginate(
                page=page, per_page=per_page)
            sketches = pagination.items
            has_next = pagination.has_next
            has_prev = pagination.has_prev
            next_page = pagination.next_num
            prev_page = pagination.prev_num
            current_page = pagination.page
            total_pages = pagination.pages
            total_items = pagination.total

        for sketch in sketches:
            # Return a subset of the sketch objects to reduce the amount of
            # data sent to the client.
            return_sketches.append({
                'id': sketch.id,
                'name': sketch.name,
                'description': sketch.description,
                'created_at': str(sketch.created_at),
                'last_activity': utils.get_sketch_last_activity(sketch),
                'user': sketch.user.username,
                'status': sketch.get_status.status
            })

        meta = {
            'current_user': current_user.username,
            'has_next': has_next,
            'has_prev': has_prev,
            'next_page': next_page,
            'prev_page': prev_page,
            'current_page': current_page,
            'total_pages': total_pages,
            'total_items': total_items
        }
        return jsonify({'objects': return_sketches, 'meta': meta})
def get ( self ) : args = self . parser . parse_args ( ) scope = args . get ( 'scope' ) page = args . get ( 'page' ) per_page = args . get ( 'per_page' ) search_query = args . get ( 'search_query' ) include_archived = args . get ( 'include_archived' ) if current_user . admin and scope == 'admin' : sketch_query = Sketch . query else : sketch_query = Sketch . all_with_acl ( ) base_filter = sketch_query . filter ( not_ ( Sketch . Status . status == 'deleted' ) , not_ ( Sketch . Status . status == 'archived' ) , Sketch . Status . parent ) . order_by ( Sketch . updated_at . desc ( ) ) base_filter_with_archived = sketch_query . filter ( not_ ( Sketch . Status . status == 'deleted' ) , Sketch . Status . parent ) . order_by ( Sketch . updated_at . desc ( ) ) filtered_sketches = base_filter_with_archived sketches = [ ] return_sketches = [ ] has_next = False has_prev = False next_page = None prev_page = None current_page = 1 total_pages = 0 total_items = 0 if scope == 'recent' : # Get list of sketches that the user has actively searched in. # TODO: Make this cover more actions such as story updates etc. # TODO: Right now we only return the top 3, make this configurable. views = View . query . filter_by ( user = current_user , name = '' ) . order_by ( View . updated_at . desc ( ) ) . limit ( 3 ) sketches = [ view . sketch for view in views ] total_items = len ( sketches ) elif scope == 'admin' : if not current_user . admin : abort ( HTTP_STATUS_CODE_FORBIDDEN , 'User is not an admin.' ) if include_archived : filtered_sketches = base_filter_with_archived else : filtered_sketches = base_filter elif scope == 'user' : filtered_sketches = base_filter . filter_by ( user = current_user ) elif scope == 'archived' : filtered_sketches = sketch_query . filter ( Sketch . status . any ( status = 'archived' ) ) elif scope == 'shared' : filtered_sketches = base_filter . filter ( Sketch . user != current_user ) elif scope == 'search' : filtered_sketches = base_filter_with_archived . filter ( or_ ( Sketch . name . ilike ( f'%{search_query}%' ) , Sketch . description . ilike ( f'%{search_query}%' ) ) ) if not sketches : pagination = filtered_sketches . paginate ( page = page , per_page = per_page ) sketches = pagination . items has_next = pagination . has_next has_prev = pagination . has_prev next_page = pagination . next_num prev_page = pagination . prev_num current_page = pagination . page total_pages = pagination . pages total_items = pagination . total for sketch in sketches : # Return a subset of the sketch objects to reduce the amount of # data sent to the client. return_sketches . append ( { 'id' : sketch . id , 'name' : sketch . name , 'description' : sketch . description , 'created_at' : str ( sketch . created_at ) , 'last_activity' : utils . get_sketch_last_activity ( sketch ) , 'user' : sketch . user . username , 'status' : sketch . get_status . status } ) meta = { 'current_user' : current_user . username , 'has_next' : has_next , 'has_prev' : has_prev , 'next_page' : next_page , 'prev_page' : prev_page , 'current_page' : current_page , 'total_pages' : total_pages , 'total_items' : total_items } return jsonify ( { 'objects' : return_sketches , 'meta' : meta } )