コード例 #1
0
ファイル: jobs.py プロジェクト: alphagov/notifications-admin
def view_jobs(service_id):
    page = int(request.args.get("page", 1))
    # all but scheduled and cancelled
    statuses_to_display = job_api_client.JOB_STATUSES - {"scheduled", "cancelled"}
    jobs_response = job_api_client.get_jobs(service_id, statuses=statuses_to_display, page=page)
    jobs = [add_rate_to_job(job) for job in jobs_response["data"]]

    prev_page = None
    if jobs_response["links"].get("prev", None):
        prev_page = generate_previous_dict("main.view_jobs", service_id, page)
    next_page = None
    if jobs_response["links"].get("next", None):
        next_page = generate_next_dict("main.view_jobs", service_id, page)

    return render_template("views/jobs/jobs.html", jobs=jobs, page=page, prev_page=prev_page, next_page=next_page)
コード例 #2
0
def test_generate_previous_next_dict_adds_other_url_args(client):
    ret = generate_next_dict('main.view_notifications', 'foo', 2, {'message_type': 'blah'})
    assert 'notifications/blah' in ret['url']
コード例 #3
0
def test_generate_next_dict(client):
    ret = generate_next_dict('main.view_jobs', 'foo', 2, {})
    assert 'page=3' in ret['url']
    assert ret['title'] == 'Next page'
    assert ret['label'] == 'page 3'
コード例 #4
0
ファイル: jobs.py プロジェクト: alphagov/notifications-admin
def get_notifications(service_id, message_type, status_override=None):
    # TODO get the api to return count of pages as well.
    page = get_page_from_request()
    if page is None:
        abort(404, "Invalid page argument ({}) reverting to page 1.".format(request.args["page"], None))
    if message_type not in ["email", "sms"]:
        abort(404)

    filter_args = _parse_filter_args(request.args)
    filter_args["status"] = _set_status_filters(filter_args)

    notifications = notification_api_client.get_notifications_for_service(
        service_id=service_id,
        page=page,
        template_type=[message_type],
        status=filter_args.get("status"),
        limit_days=current_app.config["ACTIVITY_STATS_LIMIT_DAYS"],
    )

    url_args = {"message_type": message_type, "status": request.args.get("status")}
    prev_page = None
    if notifications["links"].get("prev", None):
        prev_page = generate_previous_dict("main.view_notifications", service_id, page, url_args=url_args)
    next_page = None
    if notifications["links"].get("next", None):
        next_page = generate_next_dict("main.view_notifications", service_id, page, url_args)

    if request.path.endswith("csv"):
        csv_content = generate_notifications_csv(
            notification_api_client.get_notifications_for_service(
                service_id=service_id,
                page=page,
                page_size=notifications["total"],
                template_type=[message_type],
                status=filter_args.get("status"),
                limit_days=current_app.config["ACTIVITY_STATS_LIMIT_DAYS"],
            )["notifications"]
        )
        return (
            csv_content,
            200,
            {"Content-Type": "text/csv; charset=utf-8", "Content-Disposition": 'inline; filename="notifications.csv"'},
        )
    return {
        "counts": render_template(
            "views/activity/counts.html",
            status=request.args.get("status"),
            status_filters=get_status_filters(
                current_service, message_type, service_api_client.get_detailed_service(service_id)["data"]["statistics"]
            ),
        ),
        "notifications": render_template(
            "views/activity/notifications.html",
            notifications=notifications["notifications"],
            page=page,
            prev_page=prev_page,
            next_page=next_page,
            status=request.args.get("status"),
            message_type=message_type,
            download_link=url_for(
                ".view_notifications_csv",
                service_id=current_service["id"],
                message_type=message_type,
                status=request.args.get("status"),
            ),
        ),
    }