示例#1
0
文件: views.py 项目: heath/OTM2
def search_tree_benefits(request, instance):
    filter_str = request.REQUEST.get('q', '')

    hide_summary_text = request.REQUEST.get('hide_summary', 'false')
    hide_summary = hide_summary_text.lower() == 'true'

    filter = Filter(filter_str, instance)
    total_plots = filter.get_object_count(Plot)

    benefits, basis = get_benefits_for_filter(filter)
    # Inject the plot count as a basis for tree benefit calcs
    basis.get('plot', {})['n_plots'] = total_plots

    formatted = _format_benefits(instance, benefits, basis)
    formatted['hide_summary'] = hide_summary

    return formatted
示例#2
0
文件: tree.py 项目: nvh3010/otm-core
def search_tree_benefits(request, instance):
    filter_str = request.REQUEST.get('q', '')
    display_str = request.REQUEST.get('show', '')

    hide_summary_text = request.REQUEST.get('hide_summary', 'false')
    hide_summary = hide_summary_text.lower() == 'true'

    filter = Filter(filter_str, display_str, instance)
    total_plots = get_cached_plot_count(
        filter, lambda: filter.get_object_count(Plot))

    benefits, basis = get_benefits_for_filter(filter)

    # Inject the plot count as a basis for tree benefit calcs
    basis.get('plot', {})['n_plots'] = total_plots

    # We also want to inject the total currency amount saved
    # for plot-based items except CO2 stored
    total_currency_saved = 0

    for benefit_name, benefit in benefits.get('plot', {}).iteritems():
        if benefit_name != BenefitCategory.CO2STORAGE:
            currency = benefit.get('currency', 0.0)
            if currency:
                total_currency_saved += currency

    # save it as if it were a normal benefit so we get formatting
    # and currency conversion
    benefits.get('plot', {})['totals'] = {
        'value': None,
        'currency': total_currency_saved,
        'label': _('Total annual benefits')
    }

    formatted = format_benefits(instance, benefits, basis, digits=0)
    formatted['hide_summary'] = hide_summary

    formatted['tree_count_label'] = (
        'tree,' if basis['plot']['n_total'] == 1 else 'trees,')
    formatted['plot_count_label'] = (
        'planting site' if basis['plot']['n_plots'] == 1 else 'planting sites')
    if instance.has_resources and 'resource' in basis:
        formatted['plot_count_label'] += ','

    return formatted
示例#3
0
文件: tree.py 项目: lorenanicole/OTM2
def search_tree_benefits(request, instance):
    filter_str = request.REQUEST.get('q', '')
    display_str = request.REQUEST.get('show', '')

    hide_summary_text = request.REQUEST.get('hide_summary', 'false')
    hide_summary = hide_summary_text.lower() == 'true'

    filter = Filter(filter_str, display_str, instance)
    total_plots = filter.get_object_count(Plot)

    benefits, basis = get_benefits_for_filter(filter)

    # Inject the plot count as a basis for tree benefit calcs
    basis.get('plot', {})['n_plots'] = total_plots

    # We also want to inject the total currency amount saved
    # for plot-based items except CO2 stored
    total_currency_saved = 0

    for benefit_name, benefit in benefits.get('plot', {}).iteritems():
        if benefit_name != BenefitCategory.CO2STORAGE:
            currency = benefit.get('currency', 0.0)
            if currency:
                total_currency_saved += currency

    # save it as if it were a normal benefit so we get formatting
    # and currency conversion
    benefits.get('plot', {})['totals'] = {
        'value': None,
        'currency': total_currency_saved,
        'label': trans('Total annual benefits')
    }

    formatted = format_benefits(instance, benefits, basis)
    formatted['hide_summary'] = hide_summary

    formatted['tree_count_label'] = (
        'tree,' if basis['plot']['n_total'] == 1 else 'trees,')
    formatted['plot_count_label'] = (
        'planting site' if basis['plot']['n_plots'] == 1 else 'planting sites')
    if instance.supports_resources and 'resource' in benefits:
        formatted['plot_count_label'] += ','

    return formatted
示例#4
0
def search_tree_benefits(request, instance):
    filter_str = request.REQUEST.get("q", "")
    display_str = request.REQUEST.get("show", "")

    hide_summary_text = request.REQUEST.get("hide_summary", "false")
    hide_summary = hide_summary_text.lower() == "true"

    filter = Filter(filter_str, display_str, instance)
    total_plots = filter.get_object_count(Plot)

    benefits, basis = get_benefits_for_filter(filter)

    # Inject the plot count as a basis for tree benefit calcs
    basis.get("plot", {})["n_plots"] = total_plots

    # We also want to inject the total currency amount saved
    # for plot-based items except CO2 stored
    total_currency_saved = 0

    for benefit_name, benefit in benefits.get("plot", {}).iteritems():
        if benefit_name != "co2storage":
            currency = benefit.get("currency", 0.0)
            if currency:
                total_currency_saved += currency

    # save it as if it were a normal benefit so we get formatting
    # and currency conversion
    benefits.get("plot", {})["totals"] = {
        "value": None,
        "currency": total_currency_saved,
        "label": trans("Total annual benefits"),
    }

    formatted = format_benefits(instance, benefits, basis)
    formatted["hide_summary"] = hide_summary

    formatted["tree_count_label"] = "tree," if basis["plot"]["n_total"] == 1 else "trees,"
    formatted["plot_count_label"] = "planting site" if basis["plot"]["n_plots"] == 1 else "planting sites"
    if instance.supports_resources and "resource" in benefits:
        formatted["plot_count_label"] += ","

    return formatted