Example #1
0
def get_all_notifications_for_service_job(service_id, job_id):
    data = notifications_filter_schema.load(request.args).data
    page = data['page'] if 'page' in data else 1
    page_size = data[
        'page_size'] if 'page_size' in data else current_app.config.get(
            'PAGE_SIZE')
    paginated_notifications = get_notifications_for_job(service_id,
                                                        job_id,
                                                        filter_dict=data,
                                                        page=page,
                                                        page_size=page_size)

    kwargs = request.args.to_dict()
    kwargs['service_id'] = service_id
    kwargs['job_id'] = job_id

    notifications = None
    if data.get('format_for_csv'):
        notifications = [
            notification.serialize_for_csv()
            for notification in paginated_notifications.items
        ]
    else:
        notifications = notification_with_template_schema.dump(
            paginated_notifications.items, many=True).data

    return jsonify(notifications=notifications,
                   page_size=page_size,
                   total=paginated_notifications.total,
                   links=pagination_links(
                       paginated_notifications,
                       '.get_all_notifications_for_service_job',
                       **kwargs)), 200
Example #2
0
def get_all_notifications():
    data = notifications_filter_schema.load(request.args).data
    include_jobs = data.get("include_jobs", False)
    page = data.get("page", 1)
    page_size = data.get("page_size", current_app.config.get("API_PAGE_SIZE"))
    limit_days = data.get("limit_days")

    pagination = notifications_dao.get_notifications_for_service(
        str(authenticated_service.id),
        personalisation=True,
        filter_dict=data,
        page=page,
        page_size=page_size,
        limit_days=limit_days,
        key_type=api_user.key_type,
        include_jobs=include_jobs,
    )
    return (
        jsonify(
            notifications=notification_with_personalisation_schema.dump(
                pagination.items, many=True).data,
            page_size=page_size,
            total=pagination.total,
            links=pagination_links(pagination, ".get_all_notifications",
                                   **request.args.to_dict()),
        ),
        200,
    )
Example #3
0
def get_all_notifications_for_service(service_id):
    data = notifications_filter_schema.load(request.args).data
    if data.get('to'):
        notification_type = data.get('template_type')[0] if data.get('template_type') else None
        return search_for_notification_by_to_field(service_id=service_id,
                                                   search_term=data['to'],
                                                   statuses=data.get('status'),
                                                   notification_type=notification_type)
    page = data['page'] if 'page' in data else 1
    page_size = data['page_size'] if 'page_size' in data else current_app.config.get('PAGE_SIZE')
    limit_days = data.get('limit_days')
    include_jobs = data.get('include_jobs', True)
    include_from_test_key = data.get('include_from_test_key', False)

    pagination = notifications_dao.get_notifications_for_service(
        service_id,
        filter_dict=data,
        page=page,
        page_size=page_size,
        limit_days=limit_days,
        include_jobs=include_jobs,
        include_from_test_key=include_from_test_key
    )
    kwargs = request.args.to_dict()
    kwargs['service_id'] = service_id
    return jsonify(
        notifications=notification_with_template_schema.dump(pagination.items, many=True).data,
        page_size=page_size,
        total=pagination.total,
        links=pagination_links(
            pagination,
            '.get_all_notifications_for_service',
            **kwargs
        )
    ), 200
Example #4
0
def get_all_notifications_for_service(service_id):
    data = notifications_filter_schema.load(request.args).data
    if data.get("to"):
        notification_type = data.get("template_type")[0] if data.get(
            "template_type") else None
        return search_for_notification_by_to_field(
            service_id=service_id,
            search_term=data["to"],
            statuses=data.get("status"),
            notification_type=notification_type,
        )
    page = data["page"] if "page" in data else 1
    page_size = data[
        "page_size"] if "page_size" in data else current_app.config.get(
            "PAGE_SIZE")
    limit_days = data.get("limit_days")
    include_jobs = data.get("include_jobs", True)
    include_from_test_key = data.get("include_from_test_key", False)
    include_one_off = data.get("include_one_off", True)

    count_pages = data.get("count_pages", True)

    pagination = notifications_dao.get_notifications_for_service(
        service_id,
        filter_dict=data,
        page=page,
        page_size=page_size,
        count_pages=count_pages,
        limit_days=limit_days,
        include_jobs=include_jobs,
        include_from_test_key=include_from_test_key,
        include_one_off=include_one_off,
    )

    kwargs = request.args.to_dict()
    kwargs["service_id"] = service_id

    if data.get("format_for_csv"):
        notifications = [
            notification.serialize_for_csv()
            for notification in pagination.items
        ]
    else:
        notifications = notification_with_template_schema.dump(
            pagination.items, many=True).data
    return (
        jsonify(
            notifications=notifications,
            page_size=page_size,
            total=pagination.total,
            links=pagination_links(pagination,
                                   ".get_all_notifications_for_service",
                                   **kwargs),
        ),
        200,
    )
Example #5
0
def get_all_notifications_for_service_job(service_id, job_id):
    data = notifications_filter_schema.load(request.args).data
    page = data["page"] if "page" in data else 1
    page_size = data[
        "page_size"] if "page_size" in data else current_app.config.get(
            "PAGE_SIZE")
    paginated_notifications = get_notifications_for_job(service_id,
                                                        job_id,
                                                        filter_dict=data,
                                                        page=page,
                                                        page_size=page_size)

    kwargs = request.args.to_dict()
    kwargs["service_id"] = service_id
    kwargs["job_id"] = job_id

    notifications = None
    if data.get("format_for_csv"):
        notifications = [
            notification.serialize_for_csv()
            for notification in paginated_notifications.items
        ]
    else:
        notifications = notification_with_template_schema.dump(
            paginated_notifications.items, many=True).data

    return (
        jsonify(
            notifications=notifications,
            page_size=page_size,
            total=paginated_notifications.total,
            links=pagination_links(paginated_notifications,
                                   ".get_all_notifications_for_service_job",
                                   **kwargs),
        ),
        200,
    )
Example #6
0
def get_all_notifications_for_service_job(service_id, job_id):
    data = notifications_filter_schema.load(request.args).data
    page = data['page'] if 'page' in data else 1
    page_size = data['page_size'] if 'page_size' in data else current_app.config.get('PAGE_SIZE')

    pagination = get_notifications_for_job(
        service_id,
        job_id,
        filter_dict=data,
        page=page,
        page_size=page_size)
    kwargs = request.args.to_dict()
    kwargs['service_id'] = service_id
    kwargs['job_id'] = job_id
    return jsonify(
        notifications=notification_with_template_schema.dump(pagination.items, many=True).data,
        page_size=page_size,
        total=pagination.total,
        links=pagination_links(
            pagination,
            '.get_all_notifications_for_service_job',
            **kwargs
        )
    ), 200