Example #1
0
    return rslt


def within_itree_regions(request):
    x = request.GET.get('x', None)
    y = request.GET.get('y', None)
    return (bool(x) and bool(y) and
            ITreeRegion.objects
            .filter(geometry__contains=Point(float(x),
                                             float(y))).exists())

_benefit_labels = {
    # Translators: 'Energy' is the name of an eco benefit
    'energy':     trans('Energy'),
    # Translators: 'Stormwater' is the name of an eco benefit
    'stormwater': trans('Stormwater'),
    # Translators: 'Carbon Dioxide' is the name of an eco benefit
    'co2':        trans('Carbon Dioxide'),
    # Translators: 'Carbon Dioxide Stored' is the name of an eco benefit
    'co2storage': trans('Carbon Dioxide Stored'),
    # Translators: 'Air Quality' is the name of an eco benefit
    'airquality': trans('Air Quality')
}


def get_benefit_label(benefit_name):
    return _benefit_labels[benefit_name]


within_itree_regions_view = json_api_call(within_itree_regions)
Example #2
0
    """
    viewbox = _get_viewbox_from_request(request)

    address = request.REQUEST['address']

    pq = PlaceQuery(query=address, viewbox=viewbox)

    geocode_result = geocoder.geocode(pq)
    candidates = geocode_result.get('candidates', None)

    if not candidates or len(candidates) == 0:
        return _no_results_response(address)
    else:
        candidates = [_omgeo_candidate_to_dict(c) for c in candidates]

        if _contains_bbox(request):
            bbox = {'xmin': request.REQUEST['xmin'],
                    'ymin': request.REQUEST['ymin'],
                    'xmax': request.REQUEST['xmax'],
                    'ymax': request.REQUEST['ymax']}

            candidates = [c for c in candidates if _in_bbox(bbox, c)]

            if len(candidates) == 0:
                return _no_results_response(address, inregion=True)

        return {'candidates': candidates}


geocode_view = json_api_call(geocode)
Example #3
0
            "Plot %s does not have a current tree" % plot_id)


def add_photo(request, instance, plot_id):
    treephoto, _ = add_tree_photo(request, instance, plot_id)

    return treephoto


# Note that API requests going to private instances require
# authentication "login_optional" before they can access they
# instance data

plots_closest_to_point_endpoint = check_signature(
    instance_request(
        json_api_call(
            plots_closest_to_point)))

instances_closest_to_point_endpoint = check_signature(
    instance_request(
        json_api_call(
            instances_closest_to_point)))

instance_info_endpoint = check_signature(
    instance_request(
        json_api_call(
            instance_info)))

plots_endpoint = check_signature(
    instance_request(
        json_api_call(
            route(
Example #4
0
    return {'start_status': 'OK', 'job_id': job.pk}


def check_export(request, instance, job_id):

    job = get_object_or_404(ExportJob, pk=job_id)

    # if a job has a user, it means the user must
    # be authenticated so only the job user can
    # retrieve the export
    if job.user and job.user != request.user:
        return {'status': 'ERROR',
                'message': 'Job not initiated by user',
                'url': None}

    else:
        return {'status': ExportJob.STATUS_STRINGS[job.status],
                'message': ExportJob.STATUS_CHOICES[job.status],
                'url': job.get_url_if_ready()}


begin_export_endpoint = json_api_call(
    instance_request(
        requires_feature('exports')(
            begin_export)))
check_export_endpoint = json_api_call(
    instance_request(
        requires_feature('exports')(
            check_export)))
Example #5
0
File: views.py Project: heath/OTM2
map_view = instance_request(
    render_template('treemap/map.html', _get_map_view_context))

get_map_feature_detail_view = instance_request(render_map_feature_detail)

get_map_feature_add_view = instance_request(render_map_feature_add)

edit_plot_detail_view = login_required(
    instance_request(
        creates_instance_user(
            render_template('treemap/plot_detail.html', plot_detail))))

update_map_feature_detail_view = login_or_401(
    json_api_call(
        instance_request(
            creates_instance_user(update_map_feature_detail))))

delete_tree_view = login_or_401(
    json_api_call(
        instance_request(
            creates_instance_user(delete_tree))))

delete_map_feature_view = login_or_401(
    json_api_call(
        instance_request(
            creates_instance_user(delete_map_feature))))

get_plot_eco_view = instance_request(etag(_map_feature_hash)(
    render_template('treemap/partials/plot_eco.html', plot_detail)))
Example #6
0
                updated_plot,
                user=request.user,
                supports_eco=request.instance_supports_ecobenefits)
        except:
            raise PermissionDenied(
                '%s does not have permission to the '
                'current tree from plot %s' %
                (request.user.username, plot_id))
    else:
        raise HttpResponseBadRequest(
            "Plot %s does not have a current tree" % plot_id)


plots_closest_to_point_endpoint = login_optional(
    instance_request(
        csrf_exempt(json_api_call(
            plots_closest_to_point))))

instances_closest_to_point_endpoint = login_optional(
    instance_request(
        csrf_exempt(json_api_call(
            instances_closest_to_point))))

instance_info_endpoint = login_optional(
    instance_request(
        csrf_exempt(json_api_call(
            instance_info))))

login_endpoint = csrf_exempt(
    json_api_call(login_required(user_info)))

plots_endpoint = json_api_call(
Example #7
0
    address = request.REQUEST['address']

    pq = PlaceQuery(query=address, viewbox=viewbox)

    geocode_result = geocoder.geocode(pq)
    candidates = geocode_result.get('candidates', None)

    if not candidates or len(candidates) == 0:
        return _no_results_response(address)
    else:
        candidates = [_omgeo_candidate_to_dict(c) for c in candidates]

        if _contains_bbox(request):
            bbox = {
                'xmin': request.REQUEST['xmin'],
                'ymin': request.REQUEST['ymin'],
                'xmax': request.REQUEST['xmax'],
                'ymax': request.REQUEST['ymax']
            }

            candidates = [c for c in candidates if _in_bbox(bbox, c)]

            if len(candidates) == 0:
                return _no_results_response(address, inregion=True)

        return {'candidates': candidates}


geocode_view = json_api_call(geocode)
Example #8
0
        _combine_benefit_basis(basis, ft_basis)
        _combine_grouped_benefits(benefits, ft_benefit_groups)

    _annotate_basis_with_extra_stats(basis)

    return benefits, basis


def within_itree_regions(request):
    from treemap.models import ITreeRegion
    x = request.GET.get('x', None)
    y = request.GET.get('y', None)
    return (bool(x) and bool(y) and ITreeRegion.objects.filter(
        geometry__contains=Point(float(x), float(y))).exists())


benefit_labels = {
    # Translators: 'Energy conserved' is the name of an eco benefit
    'energy': trans('Energy conserved'),
    # Translators: 'Stormwater filtered' is the name of an eco benefit
    'stormwater': trans('Stormwater filtered'),
    # Translators: 'Carbon dioxide removed' is the name of an eco benefit
    'co2': trans('Carbon dioxide removed'),
    # Translators: 'Carbon dioxide stored' is the name of an eco benefit
    'co2storage': trans('Carbon dioxide stored to date'),
    # Translators: 'Air quality improved' is the name of an eco benefit
    'airquality': trans('Air quality improved')
}

within_itree_regions_view = json_api_call(within_itree_regions)