예제 #1
0
    def test_count_is_cached(self):
        count = get_cached_plot_count(self.filter)
        self.assertEqual(0, count)

        # We save with the old
        plot = Plot(geom=self.instance.center, instance=self.instance)
        plot.save_with_user(self.user)

        count = get_cached_plot_count(self.filter)
        self.assertEqual(0, count)
예제 #2
0
    def test_updating_geo_rev_busts_count_cache(self):
        count = get_cached_plot_count(self.filter)
        self.assertEqual(0, count)

        plot = Plot(geom=self.instance.center, instance=self.instance)
        plot.save_with_user(self.user)
        self.filter.instance.update_geo_rev()

        count = get_cached_plot_count(self.filter)
        self.assertEqual(1, count)
예제 #3
0
    def test_updating_geo_rev_busts_count_cache(self):
        count = get_cached_plot_count(self.filter)
        self.assertEqual(0, count)

        plot = Plot(geom=self.instance.center, instance=self.instance)
        plot.save_with_user(self.user)
        self.filter.instance.update_geo_rev()

        count = get_cached_plot_count(self.filter)
        self.assertEqual(1, count)
예제 #4
0
    def test_count_is_cached(self):
        count = get_cached_plot_count(self.filter)
        self.assertEqual(0, count)

        # We save with the old
        plot = Plot(geom=self.instance.center, instance=self.instance)
        plot.save_with_user(self.user)

        count = get_cached_plot_count(self.filter)
        self.assertEqual(0, count)
예제 #5
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
예제 #6
0
파일: tree.py 프로젝트: jjmata/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)

    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
예제 #7
0
def search_tree_benefits(request, instance):
    filter_str = request.GET.get('q', '')
    display_str = request.GET.get('show', '')

    hide_summary_text = request.GET.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)

    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, digits=0)

    n_trees = basis['plot']['n_total']
    n_plots = basis['plot']['n_plots']
    n_empty_plots = n_plots - n_trees
    n_resources = 0

    tree_count_label = ungettext('tree', 'trees', n_trees) + ','
    empty_plot_count_label = ungettext(
        'empty planting site', 'empty planting sites', n_empty_plots)
    has_resources = instance.has_resources and 'resource' in basis
    if has_resources:
        n_resources = basis['resource']['n_total']
        empty_plot_count_label += ','

    context = {
        'n_trees': n_trees,
        'n_empty_plots': n_empty_plots,
        'n_resources': n_resources,
        'tree_count_label': tree_count_label,
        'empty_plot_count_label': empty_plot_count_label,
        'has_resources': has_resources,
        'hide_summary': hide_summary,
        'single_result': _single_result_context(instance, n_plots, n_resources,
                                                filter)
    }
    context.update(formatted)
    return context
예제 #8
0
 def plot_count(self):
     from treemap.ecocache import get_cached_plot_count
     from treemap.search import Filter
     all_plots_filter = Filter('', '', self)
     return get_cached_plot_count(all_plots_filter)
예제 #9
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 = get_cached_plot_count(filter)

    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)

    n_trees = basis['plot']['n_total']
    n_plots = basis['plot']['n_plots']
    n_empty_plots = n_plots - n_trees
    n_resources = 0

    tree_count_label = ungettext('tree', 'trees', n_trees) + ','
    empty_plot_count_label = ungettext('empty planting site',
                                       'empty planting sites', n_empty_plots)
    has_resources = instance.has_resources and 'resource' in basis
    if has_resources:
        n_resources = basis['resource']['n_total']
        empty_plot_count_label += ','

    context = {
        'n_trees':
        n_trees,
        'n_empty_plots':
        n_empty_plots,
        'n_resources':
        n_resources,
        'tree_count_label':
        tree_count_label,
        'empty_plot_count_label':
        empty_plot_count_label,
        'has_resources':
        has_resources,
        'hide_summary':
        hide_summary,
        'single_result':
        _single_result_context(instance, n_plots, n_resources, filter)
    }
    context.update(formatted)
    return context
예제 #10
0
 def plot_count(self):
     from treemap.ecocache import get_cached_plot_count
     from treemap.search import Filter
     all_plots_filter = Filter('', '', self)
     return get_cached_plot_count(all_plots_filter)
예제 #11
0
 def test_updating_geo_rev_busts_count_cache(self):
     get_cached_plot_count(self.filter, lambda: self.count)
     self.filter.instance.update_geo_rev()
     count = get_cached_plot_count(self.filter, lambda: 17)
     self.assertEqual(count, 17)
예제 #12
0
 def test_count_is_cached(self):
     get_cached_plot_count(self.filter, lambda: self.count)
     count = get_cached_plot_count(self.filter, lambda: 17)
     self.assertEqual(count, self.count)
예제 #13
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 = get_cached_plot_count(filter)

    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)

    n_trees = basis['plot']['n_total']
    n_plots = basis['plot']['n_plots']
    n_empty_plots = n_plots - n_trees
    n_resources = 0

    tree_count_label = ungettext('tree', 'trees', n_trees) + ','
    empty_plot_count_label = ungettext(
        'empty planting site', 'empty planting sites', n_empty_plots)
    has_resources = instance.has_resources and 'resource' in basis
    if has_resources:
        n_resources = basis['resource']['n_total']
        empty_plot_count_label += ','

    context = {
        'n_trees': n_trees,
        'n_empty_plots': n_empty_plots,
        'n_resources': n_resources,
        'tree_count_label': tree_count_label,
        'empty_plot_count_label': empty_plot_count_label,
        'has_resources': has_resources,
        'hide_summary': hide_summary,
        'single_result': _single_result_context(instance, n_plots, n_resources,
                                                filter)
    }
    context.update(formatted)
    return context