Пример #1
0
def usage(service_id):
    year, current_financial_year = requested_and_current_financial_year(
        request)

    free_sms_allowance = billing_api_client.get_free_sms_fragment_limit_for_year(
        service_id, year)
    units = billing_api_client.get_billable_units(service_id, year)
    yearly_usage = billing_api_client.get_service_usage(service_id, year)

    usage_template = 'views/usage.html'
    if 'letter' in current_service['permissions']:
        usage_template = 'views/usage-with-letters.html'
    return render_template(usage_template,
                           months=list(
                               get_free_paid_breakdown_for_billable_units(
                                   year, free_sms_allowance, units)),
                           selected_year=year,
                           years=get_tuples_of_financial_years(
                               partial(url_for,
                                       '.usage',
                                       service_id=service_id),
                               start=current_financial_year - 1,
                               end=current_financial_year + 1,
                           ),
                           **calculate_usage(yearly_usage, free_sms_allowance))
Пример #2
0
def get_dashboard_partials(service_id):
    all_statistics = template_statistics_client.get_template_statistics_for_service(
        service_id, limit_days=7)
    template_statistics = aggregate_template_usage(all_statistics)
    stats = aggregate_notifications_stats(all_statistics)
    column_width, max_notifiction_count = get_column_properties(3)

    dashboard_totals = get_dashboard_totals(stats),
    highest_notification_count = max(
        sum(value[key] for key in {'requested', 'failed', 'delivered'})
        for key, value in dashboard_totals[0].items())
    free_sms_allowance = billing_api_client.get_free_sms_fragment_limit_for_year(
        current_service.id,
        get_current_financial_year(),
    )
    yearly_usage = billing_api_client.get_service_usage(
        service_id,
        get_current_financial_year(),
    )
    return {
        'upcoming':
        render_template('views/dashboard/_upcoming.html', ),
        'inbox':
        render_template(
            'views/dashboard/_inbox.html',
            inbound_sms_summary=(
                service_api_client.get_inbound_sms_summary(service_id)
                if current_service.has_permission('inbound_sms') else None),
        ),
        'totals':
        render_template(
            'views/dashboard/_totals.html',
            service_id=service_id,
            statistics=dashboard_totals[0],
            column_width=column_width,
            smaller_font_size=(highest_notification_count >
                               max_notifiction_count),
        ),
        'template-statistics':
        render_template(
            'views/dashboard/template-statistics.html',
            template_statistics=template_statistics,
            most_used_template_count=max(
                [row['count'] for row in template_statistics] or [0]),
        ),
        'jobs':
        render_template(
            'views/dashboard/_jobs.html',
            jobs=current_service.immediate_jobs,
        ),
        'usage':
        render_template(
            'views/dashboard/_usage.html',
            column_width=column_width,
            **calculate_usage(yearly_usage, free_sms_allowance),
        ),
    }
Пример #3
0
def get_dashboard_partials(service_id):
    all_statistics = template_statistics_client.get_template_statistics_for_service(
        service_id, limit_days=7)
    template_statistics = aggregate_template_usage(all_statistics)
    stats = aggregate_notifications_stats(all_statistics)

    dashboard_totals = get_dashboard_totals(stats),
    free_sms_allowance = billing_api_client.get_free_sms_fragment_limit_for_year(
        current_service.id,
        get_current_financial_year(),
    )
    yearly_usage = billing_api_client.get_service_usage(
        service_id,
        get_current_financial_year(),
    )
    return {
        'upcoming':
        render_template('views/dashboard/_upcoming.html', ),
        'inbox':
        render_template('views/dashboard/_inbox.html', ),
        'totals':
        render_template(
            'views/dashboard/_totals.html',
            service_id=service_id,
            statistics=dashboard_totals[0],
        ),
        'template-statistics':
        render_template(
            'views/dashboard/template-statistics.html',
            template_statistics=template_statistics,
            most_used_template_count=max(
                [row['count'] for row in template_statistics] or [0]),
        ),
        'usage':
        render_template(
            'views/dashboard/_usage.html',
            **calculate_usage(yearly_usage, free_sms_allowance),
        ),
    }