Beispiel #1
0
    def test_view_returns_response(self):
        json_view = json_api_call(redirect_view)
        resp = json_view(self.get_req)

        self.assertEqual(b"", resp.content)
        if django.VERSION[1] > 5:
            self.assertEqual("http://lmgtfy.com", resp.url)
Beispiel #2
0
    def test_simple_dict_to_json(self):
        json_view = json_api_call(dict_view)
        resp = json_view(self.get_req)

        self.assertEqual(b'{"Hello": "World"}', resp.content)
        self.assertEqual("application/json", resp['Content-Type'])
        self.assertEqual('18', resp['Content-Length'])
Beispiel #3
0
    def test_view_returns_response(self):
        json_view = json_api_call(redirect_view)
        resp = json_view(self.get_req)

        self.assertEqual(b"", resp.content)
        if django.VERSION[1] > 5:
            self.assertEqual("http://lmgtfy.com", resp.url)
Beispiel #4
0
    def test_simple_dict_to_json(self):
        json_view = json_api_call(dict_view)
        resp = json_view(self.get_req)

        self.assertEqual(b'{"Hello": "World"}', resp.content)
        self.assertEqual("application/json", resp['Content-Type'])
        self.assertEqual('18', resp['Content-Length'])
Beispiel #5
0
_itree_codes_by_region = None
_all_itree_codes = None


def all_itree_codes():
    _ensure_itree_codes_fetched()
    return _all_itree_codes


def has_itree_code(region_code, itree_code):
    _ensure_itree_codes_fetched()
    has = itree_code in _itree_codes_by_region.get(region_code, [])
    return has


def _ensure_itree_codes_fetched():
    global _itree_codes_by_region, _all_itree_codes
    if _itree_codes_by_region is None:
        result, err = ecobackend.json_benefits_call('itree_codes.json', {})
        if err:
            raise Exception('Failed to retrieve i-Tree codes from ecoservice')

        _itree_codes_by_region = result['Codes']

        _all_itree_codes = set(
            itertools.chain(*_itree_codes_by_region.values()))


within_itree_regions_view = json_api_call(within_itree_regions)
Beispiel #6
0
#####################################
# PROGRESS PAGE ROUTES
#####################################

progress_page = route(GET=do(render_template('survey/progress.html'),
                             v.progress_page))

progress_page_blockface_popup = route(
    GET=do(
        render_template('survey/partials/progress_page_blockface_popup.html'),
        v.progress_page_blockface_popup))

group_borders_geojson = do(
    last_modified(get_group_territory_modification_time),
    route(GET=json_api_call(v.group_borders_geojson)))

group_popup = route(GET=do(group_request,
                           render_template('survey/partials/group_popup.html'),
                           v.group_popup))

#####################################
# RESERVATION ROUTES
#####################################

printable_reservations_map = route(
    GET=do(
        login_required,
        render_template('survey/printable_reservations_map.html'),
        v.printable_reservations_page))
Beispiel #7
0
def _api_call(verb, view_fn):
    return do(admin_instance_request, require_http_method(verb), view_fn)


def _template_api_call(verb, template, view_fn):
    templated_view = render_template(template)(view_fn)
    return _api_call(verb, templated_view)


list_imports = _template_api_call("GET", "importer/partials/imports.html", views.list_imports)

get_import_table = _template_api_call("GET", "importer/partials/import_table.html", views.get_import_table)

start_import = _template_api_call("POST", "importer/partials/import_table.html", views.start_import)

cancel = _template_api_call("GET", "importer/partials/imports.html", views.cancel)

solve = _template_api_call("POST", "importer/partials/row_status.html", views.solve)

commit = _template_api_call("GET", "importer/partials/imports.html", views.commit)

show_import_status = _api_call("GET", views.show_import_status)

update_row = _template_api_call("POST", "importer/partials/row_status.html", views.update_row)

export_all_species = _api_call("GET", json_api_call(views.export_all_species))

export_single_import = _api_call("GET", json_api_call(views.export_single_import))

merge_species = _api_call("POST", views.merge_species)
Beispiel #8
0
list_imports = _template_api_call(
    'GET', 'importer/partials/imports.html', views.list_imports)

refresh_imports = _template_api_call(
    'GET', 'importer/partials/import_tables.html', views.list_imports)

start_import = _template_api_call(
    'POST', 'importer/partials/imports.html', views.start_import)

cancel = _template_api_call(
    'GET', 'importer/partials/imports.html', views.cancel)

solve = _template_api_call(
    'POST', 'importer/partials/row_status.html', views.solve)

commit = _template_api_call(
    'GET', 'importer/partials/imports.html', views.commit)

show_import_status = _api_call('GET', views.show_import_status)

update_row = _template_api_call(
    'POST', 'importer/partials/row_status.html', views.update_row)

export_all_species = _api_call('GET', json_api_call(views.export_all_species))

export_single_import = _api_call(
    'GET', json_api_call(views.export_single_import))

merge_species = _api_call('POST', views.merge_species)
Beispiel #9
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)
_itree_codes_by_region = None
_all_itree_codes = None


def all_itree_codes():
    _ensure_itree_codes_fetched()
    return _all_itree_codes


def has_itree_code(region_code, itree_code):
    _ensure_itree_codes_fetched()
    has = itree_code in _itree_codes_by_region.get(region_code, [])
    return has


def _ensure_itree_codes_fetched():
    global _itree_codes_by_region, _all_itree_codes
    if _itree_codes_by_region is None:
        result, err = ecobackend.json_benefits_call('itree_codes.json', {})
        if err:
            raise Exception('Failed to retrieve i-Tree codes from ecoservice')

        _itree_codes_by_region = result['Codes']

        _all_itree_codes = set(
            itertools.chain(*_itree_codes_by_region.values()))


within_itree_regions_view = json_api_call(within_itree_regions)
Beispiel #11
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)
Beispiel #12
0
#####################################
# PROGRESS PAGE ROUTES
#####################################

progress_page = route(GET=do(render_template('survey/progress.html'),
                             v.progress_page))

progress_page_blockface_popup = route(
    GET=do(
        render_template('survey/partials/progress_page_blockface_popup.html'),
        v.progress_page_blockface_popup))

group_borders_geojson = do(
    last_modified(get_group_territory_modification_time),
    route(GET=json_api_call(v.group_borders_geojson)))

group_popup = route(GET=do(group_request,
                           render_template('survey/partials/group_popup.html'),
                           v.group_popup))

#####################################
# RESERVATION ROUTES
#####################################

printable_reservations_map = route(
    GET=do(
        login_required,
        render_template('survey/printable_reservations_map.html'),
        v.printable_reservations_page))
Beispiel #13
0
    Search for specified address, returning candidates with lat/long
    """
    key = request.GET.get('key')
    address = request.GET.get('address').encode('utf-8')
    for_storage = 'forStorage' in request.GET

    if key:
        # See settings.OMGEO_SETTINGS for configuration
        pq = PlaceQuery(query=address, key=key, for_storage=for_storage)
        geocode_result = geocoder.geocode(pq)
        candidates = geocode_result.get('candidates', None)
        if candidates:
            # There should only be one candidate since the user already chose a
            # specific suggestion and the front end filters out suggestions
            # that might result in more than one candidate (like "Beaches").
            match = candidates[0]
            return {
                'lat': match.y,
                'lng': match.x
            }

    return _no_results_response(address)


def get_esri_token(request):
    return {'token': ESRI_WGS.get_token()}


geocode_view = json_api_call(geocode)
get_esri_token_view = json_api_call(get_esri_token)
Beispiel #14
0
def geocode(request):
    """
    Search for specified address, returning candidates with lat/long
    """
    key = request.GET.get('key')
    address = request.GET.get('address').encode('utf-8')
    for_storage = 'forStorage' in request.GET

    if key:
        # See settings.OMGEO_SETTINGS for configuration
        pq = PlaceQuery(query=address, key=key, for_storage=for_storage)
        geocode_result = geocoder.geocode(pq)
        candidates = geocode_result.get('candidates', None)
        if candidates:
            # There should only be one candidate since the user already chose a
            # specific suggestion and the front end filters out suggestions
            # that might result in more than one candidate (like "Beaches").
            match = candidates[0]
            return {'lat': match.y, 'lng': match.x}

    return _no_results_response(address)


def get_esri_token(request):
    return {'token': ESRI_WGS.get_token()}


geocode_view = json_api_call(geocode)
get_esri_token_view = json_api_call(get_esri_token)