Example #1
0
def api_all_tasks():
    """ Tasks API: retrieve by filters, delete all tasks
    """
    # retrieve tasks (plus completions and predictions) with pagination & ordering
    if request.method == 'GET':
        # get filter parameters from request
        fields = request.values.get('fields', 'all').split(',')
        page, page_size = int(request.values.get('page', 1)), int(
            request.values.get('page_size', 10))
        order = request.values.get('order', 'id')
        if page < 1 or page_size < 1:
            return make_response(
                jsonify({'detail': 'Incorrect page or page_size'}), 422)

        params = SimpleNamespace(fields=fields,
                                 page=page,
                                 page_size=page_size,
                                 order=order)
        tasks = prepare_tasks(g.project, params)
        return make_response(jsonify(tasks), 200)

    # delete all tasks with completions
    if request.method == 'DELETE':
        g.project.delete_tasks()
        return make_response(jsonify({'detail': 'deleted'}), 204)
Example #2
0
def api_all_tasks():
    """Tasks API: retrieve by filters, delete all tasks"""
    # retrieve tasks (plus completions and predictions) with pagination & ordering
    if request.method == "GET":
        # get filter parameters from request
        fields = request.values.get("fields", "all").split(",")
        page, page_size = int(request.values.get("page", 1)), int(
            request.values.get("page_size", 10))
        order = request.values.get("order", "id")
        if page < 1 or page_size < 1:
            return make_response(
                jsonify({"detail": "Incorrect page or page_size"}), 422)

        params = SimpleNamespace(fields=fields,
                                 page=page,
                                 page_size=page_size,
                                 order=order)
        tasks = prepare_tasks(g.project, params)
        return make_response(jsonify(tasks), 200)

    # delete all tasks with completions
    if request.method == "DELETE":
        g.project.delete_tasks()
        return make_response(jsonify({"detail": "deleted"}), 204)