예제 #1
0
def uploads(service_id):
    # No tests have been written, this has been quickly prepared for user research.
    # It's also very like that a new view will be created to show uploads.
    uploads = current_service.get_page_of_uploads(
        page=request.args.get('page'))

    prev_page = None
    if uploads.prev_page:
        prev_page = generate_previous_dict('main.uploads', service_id,
                                           uploads.current_page)
    next_page = None
    if uploads.next_page:
        next_page = generate_next_dict('main.uploads', service_id,
                                       uploads.current_page)

    if uploads.current_page == 1:
        listed_uploads = (current_service.contact_lists +
                          current_service.scheduled_jobs + uploads)
    else:
        listed_uploads = uploads

    return render_template(
        'views/jobs/jobs.html',
        jobs=listed_uploads,
        prev_page=prev_page,
        next_page=next_page,
        now=datetime.utcnow().isoformat(),
    )
예제 #2
0
def view_jobs(service_id):
    page = int(request.args.get('page', 1))
    jobs_response = job_api_client.get_page_of_jobs(service_id, 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)

    scheduled_jobs = ''
    if not current_user.has_permissions('view_activity') and page == 1:
        scheduled_jobs = render_template(
            'views/dashboard/_upcoming.html',
            scheduled_jobs=job_api_client.get_scheduled_jobs(service_id),
            hide_heading=True,
        )

    return render_template(
        'views/jobs/jobs.html',
        jobs=jobs,
        page=page,
        prev_page=prev_page,
        next_page=next_page,
        scheduled_jobs=scheduled_jobs,
    )
예제 #3
0
def platform_admin_list_complaints():
    page = get_page_from_request()
    if page is None:
        abort(404,
              "Invalid page argument ({}).".format(request.args.get('page')))

    response = complaint_api_client.get_all_complaints(page=page)

    prev_page = None
    if response['links'].get('prev'):
        prev_page = generate_previous_dict(
            'main.platform_admin_list_complaints', None, page)
    next_page = None
    if response['links'].get('next'):
        next_page = generate_next_dict('main.platform_admin_list_complaints',
                                       None, page)

    return render_template(
        'views/platform-admin/complaints.html',
        complaints=response['complaints'],
        page_title='All Complaints',
        page=page,
        prev_page=prev_page,
        next_page=next_page,
    )
예제 #4
0
파일: jobs.py 프로젝트: qld-gov-au/notify
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,
    )
예제 #5
0
def platform_admin_callback_failures():
    page = get_page_from_request()
    if page is None:
        abort(404,
              "Invalid page argument ({}).".format(request.args.get('page')))

    response = callback_failures_client.get_failing_callbacks(page=page)

    prev_page = None
    if response['links'].get('prev'):
        prev_page = generate_previous_dict(
            'main.platform_admin_callback_failures', None, page)
    next_page = None
    if response['links'].get('next'):
        next_page = generate_next_dict('main.platform_admin_callback_failures',
                                       None, page)

    return render_template(
        'views/platform-admin/callback_failures.html',
        callback_failures=response['callbacks'],
        page_title='Callback failures',
        page=page,
        prev_page=prev_page,
        next_page=next_page,
    )
예제 #6
0
def view_jobs(service_id):
    jobs = current_service.get_page_of_jobs(page=request.args.get('page'))

    prev_page = None
    if jobs.prev_page:
        prev_page = generate_previous_dict('main.view_jobs', service_id,
                                           jobs.current_page)
    next_page = None
    if jobs.next_page:
        next_page = generate_next_dict('main.view_jobs', service_id,
                                       jobs.current_page)

    scheduled_jobs = ''
    if not current_user.has_permissions(
            'view_activity') and jobs.current_page == 1:
        scheduled_jobs = render_template(
            'views/dashboard/_upcoming.html',
            hide_heading=True,
        )

    return render_template(
        'views/jobs/jobs.html',
        jobs=jobs,
        prev_page=prev_page,
        next_page=next_page,
        scheduled_jobs=scheduled_jobs,
    )
예제 #7
0
def view_jobs(service_id):
    page = int(request.args.get("page", 1))
    jobs_response = job_api_client.get_page_of_jobs(service_id, 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,
        scheduled_jobs=render_template(
            "views/dashboard/_upcoming.html",
            scheduled_jobs=job_api_client.get_scheduled_jobs(service_id),
            hide_show_more=True,
            title=_("Scheduled messages"),
        ) if page == 1 else None,
    )
예제 #8
0
def get_inbox_partials(service_id):
    page = int(request.args.get('page', 1))
    if 'inbound_sms' not in current_service['permissions']:
        abort(403)

    inbound_messages_data = service_api_client.get_most_recent_inbound_sms(service_id, page=page)
    inbound_messages = inbound_messages_data['data']

    if not inbound_messages:
        inbound_number = inbound_number_client.get_inbound_sms_number_for_service(service_id)['data']['number']
    else:
        inbound_number = None

    prev_page = None
    if page > 1:
        prev_page = generate_previous_dict('main.inbox', service_id, page)
    next_page = None
    if inbound_messages_data['has_next']:
        next_page = generate_next_dict('main.inbox', service_id, page)

    return {'messages': render_template(
        'views/dashboard/_inbox_messages.html',
        messages=inbound_messages,
        inbound_number=inbound_number,
        prev_page=prev_page,
        next_page=next_page

    )}
예제 #9
0
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)
예제 #10
0
def uploaded_letters(service_id, letter_print_day):
    page = get_page_from_request()
    if page is None:
        abort(404,
              "Invalid page argument ({}).".format(request.args.get('page')))
    uploaded_letters = upload_api_client.get_letters_by_service_and_print_day(
        current_service.id,
        letter_print_day=letter_print_day,
        page=page,
    )

    prev_page = None
    if uploaded_letters['links'].get('prev'):
        prev_page = generate_previous_dict(
            '.uploaded_letters',
            service_id,
            page,
            url_args={'letter_print_day': letter_print_day})
    next_page = None
    if uploaded_letters['links'].get('next'):
        next_page = generate_next_dict(
            '.uploaded_letters',
            service_id,
            page,
            url_args={'letter_print_day': letter_print_day})
    return render_template(
        'views/uploads/uploaded-letters.html',
        notifications=add_preview_of_content_uploaded_letters(
            uploaded_letters['notifications']),
        prev_page=prev_page,
        next_page=next_page,
        show_pagination=True,
        total=uploaded_letters['total'],
        letter_printing_statement=get_letter_printing_statement(
            'created',
            letter_print_day,
        ),
        letter_print_day=letter_print_day,
        single_notification_url=partial(
            url_for,
            '.view_notification',
            service_id=current_service.id,
            from_uploaded_letters=letter_print_day,
        ))
예제 #11
0
def uploads(service_id):
    # No tests have been written, this has been quickly prepared for user research.
    # It's also very like that a new view will be created to show uploads.
    uploads = current_service.get_page_of_uploads(
        page=request.args.get('page'))

    prev_page = None
    if uploads.next_page:
        prev_page = generate_previous_dict('main.uploads', service_id,
                                           uploads.current_page)
    next_page = None
    if uploads.prev_page:
        next_page = generate_next_dict('main.uploads', service_id,
                                       uploads.current_page)

    return render_template(
        'views/jobs/jobs.html',
        jobs=uploads,
        prev_page=prev_page,
        next_page=next_page,
        scheduled_jobs='',
    )
예제 #12
0
def platform_admin_list_complaints():
    page = get_page_from_request()
    if page is None:
        abort(404, "Invalid page argument ({}).".format(request.args.get("page")))

    response = complaint_api_client.get_all_complaints(page=page)

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

    return render_template(
        "views/platform-admin/complaints.html",
        complaints=response["complaints"],
        page_title="All Complaints",
        page=page,
        prev_page=prev_page,
        next_page=next_page,
    )
예제 #13
0
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 ({}).".format(request.args.get('page')))
    filter_args = parse_filter_args(request.args)
    filter_args['status'] = set_status_filters(filter_args)
    service_data_retention_days = None

    if message_type is not None:
        service_data_retention_days = current_service.get_days_of_retention(
            message_type)

    if request.path.endswith('csv') and current_user.has_permissions(
            'view_activity'):
        return Response(generate_notifications_csv(
            service_id=service_id,
            page=page,
            page_size=5000,
            template_type=[message_type],
            status=filter_args.get('status'),
            limit_days=service_data_retention_days),
                        mimetype='text/csv',
                        headers={
                            'Content-Disposition':
                            'inline; filename="notifications.csv"'
                        })
    notifications = notification_api_client.get_notifications_for_service(
        service_id=service_id,
        page=page,
        template_type=[message_type] if message_type else [],
        status=filter_args.get('status'),
        limit_days=service_data_retention_days,
        to=request.form.get('to', ''),
    )
    url_args = {
        'message_type': message_type,
        'status': request.args.get('status')
    }
    prev_page = None

    if 'links' in notifications and notifications['links'].get('prev', None):
        prev_page = generate_previous_dict('main.view_notifications',
                                           service_id,
                                           page,
                                           url_args=url_args)
    next_page = None

    if 'links' in notifications and notifications['links'].get('next', None):
        next_page = generate_next_dict('main.view_notifications', service_id,
                                       page, url_args)

    if message_type:
        download_link = url_for('.view_notifications_csv',
                                service_id=current_service.id,
                                message_type=message_type,
                                status=request.args.get('status'))
    else:
        download_link = None

    return {
        'service_data_retention_days':
        service_data_retention_days,
        '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_service_statistics(
                                service_id,
                                today_only=False,
                                limit_days=service_data_retention_days))),
        'notifications':
        render_template(
            'views/activity/notifications.html',
            notifications=list(
                add_preview_of_content_to_notifications(
                    notifications['notifications'])),
            page=page,
            limit_days=service_data_retention_days,
            prev_page=prev_page,
            next_page=next_page,
            status=request.args.get('status'),
            message_type=message_type,
            download_link=download_link,
        ),
    }
예제 #14
0
파일: jobs.py 프로젝트: qld-gov-au/notify
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', 'letter']:
        abort(404)
    filter_args = parse_filter_args(request.args)
    filter_args['status'] = set_status_filters(filter_args)
    if request.path.endswith('csv'):
        return Response(generate_notifications_csv(
            service_id=service_id,
            page=page,
            page_size=5000,
            template_type=[message_type],
            status=filter_args.get('status'),
            limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS']),
                        mimetype='text/csv',
                        headers={
                            'Content-Disposition':
                            'inline; filename="notifications.csv"'
                        })
    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'],
        to=request.form.get('to', ''),
    )
    url_args = {
        'message_type': message_type,
        'status': request.args.get('status')
    }
    prev_page = None

    if 'links' in notifications and notifications['links'].get('prev', None):
        prev_page = generate_previous_dict('main.view_notifications',
                                           service_id,
                                           page,
                                           url_args=url_args)
    next_page = None

    if 'links' in notifications and notifications['links'].get('next', None):
        next_page = generate_next_dict('main.view_notifications', service_id,
                                       page, url_args)

    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=list(
                            add_preview_of_content_to_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'))),
    }
예제 #15
0
def test_generate_previous_dict(client):
    ret = generate_previous_dict("main.view_jobs", "foo", 2, {})
    assert "page=1" in ret["url"]
    assert ret["title"] == "Previous page"
    assert ret["label"] == "page 1"
예제 #16
0
def test_generate_previous_dict(client):
    ret = generate_previous_dict('main.view_jobs', 'foo', 2, {})
    assert 'page=1' in ret['url']
    assert ret['title'] == 'Previous page'
    assert ret['label'] == 'page 1'
예제 #17
0
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"),
            ),
        ),
    }
예제 #18
0
def test_generate_previous_dict(client):
    ret = generate_previous_dict('main.view_jobs', 'foo', 2, {})
    assert 'page=1' in ret['url']
    assert ret['title'] == 'Previous page'
    assert ret['label'] == 'page 1'
예제 #19
0
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 ({}).".format(request.args.get("page")))
    if message_type not in ["email", "sms", "letter", None]:
        abort(404)
    filter_args = parse_filter_args(request.args)
    filter_args["status"] = set_status_filters(filter_args)
    service_data_retention_days = current_app.config.get(
        "ACTIVITY_STATS_LIMIT_DAYS", None)

    if message_type is not None:
        service_data_retention_days = current_service.get_days_of_retention(
            message_type)

    if request.path.endswith("csv") and current_user.has_permissions(
            "view_activity"):
        return Response(
            generate_notifications_csv(
                service_id=service_id,
                page=page,
                page_size=5000,
                template_type=[message_type],
                status=filter_args.get("status"),
                limit_days=service_data_retention_days,
            ),
            mimetype="text/csv",
            headers={
                "Content-Disposition": 'inline; filename="notifications.csv"'
            },
        )
    notifications = notification_api_client.get_notifications_for_service(
        service_id=service_id,
        page=page,
        template_type=[message_type] if message_type else [],
        status=filter_args.get("status"),
        limit_days=service_data_retention_days,
        to=request.form.get("to", ""),
    )
    url_args = {
        "message_type": message_type,
        "status": request.args.get("status")
    }
    prev_page = None

    if "links" in notifications and notifications["links"].get("prev", None):
        prev_page = generate_previous_dict("main.view_notifications",
                                           service_id,
                                           page,
                                           url_args=url_args)
    next_page = None

    if "links" in notifications and notifications["links"].get("next", None):
        next_page = generate_next_dict("main.view_notifications", service_id,
                                       page, url_args)

    if message_type:
        download_link = url_for(
            ".view_notifications_csv",
            service_id=current_service.id,
            message_type=message_type,
            status=request.args.get("status"),
        )
    else:
        download_link = None

    return {
        "service_data_retention_days":
        service_data_retention_days,
        "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_service_statistics(
                    service_id,
                    today_only=False,
                    limit_days=service_data_retention_days),
            ),
        ),
        "notifications":
        render_template(
            "views/activity/notifications.html",
            notifications=list(
                add_preview_of_content_to_notifications(
                    notifications["notifications"])),
            page=page,
            limit_days=service_data_retention_days,
            prev_page=prev_page,
            next_page=next_page,
            status=request.args.get("status"),
            message_type=message_type,
            download_link=download_link,
        ),
    }