コード例 #1
0
def get_job_partials(job, template):
    filter_args = parse_filter_args(request.args)
    filter_args['status'] = set_status_filters(filter_args)
    notifications = notification_api_client.get_notifications_for_service(
        job['service'], job['id'], status=filter_args['status'])

    if template['template_type'] == 'letter':
        # there might be no notifications if the job has only just been created and the tasks haven't run yet
        if notifications['notifications']:
            postage = notifications['notifications'][0]['postage']
        else:
            postage = template['postage']

        counts = render_template(
            'partials/jobs/count-letters.html',
            total=job.get('notification_count', 0),
            delivery_estimate=get_letter_timings(
                job['created_at'], postage=postage).earliest_delivery,
        )
    else:
        counts = render_template('partials/count.html',
                                 counts=_get_job_counts(job),
                                 status=filter_args['status'])
    service_data_retention_days = current_service.get_days_of_retention(
        template['template_type'])

    return {
        'counts':
        counts,
        'notifications':
        render_template(
            'partials/jobs/notifications.html',
            notifications=list(
                add_preview_of_content_to_notifications(
                    notifications['notifications'])),
            more_than_one_page=bool(
                notifications.get('links', {}).get('next')),
            percentage_complete=(job['notifications_requested'] /
                                 job['notification_count'] * 100),
            download_link=url_for('.view_job_csv',
                                  service_id=current_service.id,
                                  job_id=job['id'],
                                  status=request.args.get('status')),
            time_left=get_time_left(
                job['created_at'],
                service_data_retention_days=service_data_retention_days),
            job=job,
            template=template,
            template_version=job['template_version'],
        ),
        'status':
        render_template('partials/jobs/status.html', job=job),
    }
コード例 #2
0
def get_single_notification_partials(notification):
    return {
        'notifications':
        render_template(
            'partials/notifications/notifications.html',
            notification=notification,
            more_than_one_page=False,
            percentage_complete=100,
            time_left=get_time_left(notification['created_at']),
        ),
        'status':
        render_template('partials/notifications/status.html',
                        notification=notification),
    }
コード例 #3
0
def get_job_partials(job):
    filter_args = parse_filter_args(request.args)
    filter_args['status'] = set_status_filters(filter_args)
    notifications = job.get_notifications(status=filter_args['status'])
    if job.template_type == 'letter':
        counts = render_template(
            'partials/jobs/count-letters.html',
            job=job,
        )
    else:
        counts = render_template(
            'partials/count.html',
            counts=_get_job_counts(job),
            status=filter_args['status'],
            notifications_deleted=(job.status == 'finished'
                                   and not notifications['notifications']),
        )
    service_data_retention_days = current_service.get_days_of_retention(
        job.template_type)

    return {
        'counts':
        counts,
        'notifications':
        render_template(
            'partials/jobs/notifications.html',
            notifications=list(
                add_preview_of_content_to_notifications(
                    notifications['notifications'])),
            more_than_one_page=bool(
                notifications.get('links', {}).get('next')),
            download_link=url_for('.view_job_csv',
                                  service_id=current_service.id,
                                  job_id=job.id,
                                  status=request.args.get('status')),
            time_left=get_time_left(
                job.created_at,
                service_data_retention_days=service_data_retention_days),
            job=job,
            service_data_retention_days=service_data_retention_days,
        ),
        'status':
        render_template('partials/jobs/status.html',
                        job=job,
                        letter_print_day=get_letter_printing_statement(
                            "created", job.created_at)),
    }
コード例 #4
0
def get_job_partials(job, template):
    filter_args = _parse_filter_args(request.args)
    filter_args['status'] = _set_status_filters(filter_args)
    notifications = notification_api_client.get_notifications_for_service(
        job['service'], job['id'], status=filter_args['status'])

    if template['template_type'] == 'letter':
        counts = render_template(
            'partials/jobs/count-letters.html',
            total=job.get('notification_count', 0),
            delivery_estimate=get_letter_timings(
                job['created_at']).earliest_delivery,
        )
    else:
        counts = render_template('partials/count.html',
                                 counts=_get_job_counts(job),
                                 status=filter_args['status'])

    return {
        'counts':
        counts,
        'notifications':
        render_template(
            'partials/jobs/notifications.html',
            notifications=list(
                add_preview_of_content_to_notifications(
                    notifications['notifications'])),
            more_than_one_page=bool(
                notifications.get('links', {}).get('next')),
            percentage_complete=(job['notifications_requested'] /
                                 job['notification_count'] * 100),
            download_link=url_for('.view_job_csv',
                                  service_id=current_service['id'],
                                  job_id=job['id'],
                                  status=request.args.get('status')),
            time_left=get_time_left(job['created_at']),
            job=job,
            template=template,
            template_version=job['template_version'],
        ),
        'status':
        render_template('partials/jobs/status.html', job=job),
    }
コード例 #5
0
def get_job_partials(job, template):
    filter_args = parse_filter_args(request.args)
    filter_args['status'] = set_status_filters(filter_args)
    notifications = notification_api_client.get_notifications_for_service(
        job['service'], job['id'], status=filter_args['status'])

    if template['template_type'] == 'letter':
        # there might be no notifications if the job has only just been created and the tasks haven't run yet
        if notifications['notifications']:
            postage = notifications['notifications'][0]['postage']
        else:
            postage = template['postage']

        counts = render_template(
            'partials/jobs/count-letters.html',
            total=job.get('notification_count', 0),
            delivery_estimate=get_letter_timings(
                job['created_at'], postage=postage).earliest_delivery,
        )
    else:
        counts = render_template('partials/count.html',
                                 counts=_get_job_counts(job),
                                 status=filter_args['status'])
    service_data_retention_days = current_service.get_days_of_retention(
        template['template_type'])
    can_letter_job_be_cancelled = False
    if template["template_type"] == "letter":
        not_cancellable = [
            n for n in notifications["notifications"]
            if n["status"] not in CANCELLABLE_JOB_LETTER_STATUSES
        ]
        job_created = job["created_at"][:-6]
        if not letter_can_be_cancelled(
                "created",
                datetime.strptime(
                    job_created,
                    '%Y-%m-%dT%H:%M:%S.%f')) or len(not_cancellable) != 0:
            can_letter_job_be_cancelled = False
        else:
            can_letter_job_be_cancelled = True
    return {
        'counts':
        counts,
        'notifications':
        render_template(
            'partials/jobs/notifications.html',
            notifications=list(
                add_preview_of_content_to_notifications(
                    notifications['notifications'])),
            more_than_one_page=bool(
                notifications.get('links', {}).get('next')),
            percentage_complete=(job['notifications_requested'] /
                                 job['notification_count'] * 100),
            download_link=url_for('.view_job_csv',
                                  service_id=current_service.id,
                                  job_id=job['id'],
                                  status=request.args.get('status')),
            time_left=get_time_left(
                job['created_at'],
                service_data_retention_days=service_data_retention_days),
            job=job,
            template=template,
            template_version=job['template_version'],
        ),
        'status':
        render_template('partials/jobs/status.html',
                        job=job,
                        template_type=template["template_type"],
                        letter_print_day=get_letter_printing_statement(
                            "created", job["created_at"])),
        'can_letter_job_be_cancelled':
        can_letter_job_be_cancelled,
    }