diff --git a/OpenOversight/app/main/views.py b/OpenOversight/app/main/views.py index e79200847..71a0fbe76 100644 --- a/OpenOversight/app/main/views.py +++ b/OpenOversight/app/main/views.py @@ -160,7 +160,6 @@ def index(): state_count=state_count, department_count=department_count, departments_by_state=departments_by_state, - map_paths=current_app.config["MAP_DATA"], ) @@ -179,10 +178,19 @@ def set_session_timezone(): @main.route("/browse", methods=[HTTPMethod.GET]) def browse(): departments_by_state = Department.by_state() - return render_template( - "browse.html", - departments_by_state=departments_by_state, - map_paths=current_app.config["MAP_DATA"], + return render_template("browse.html", departments_by_state=departments_by_state) + + +@main.route("/map.svg", methods=[HTTPMethod.GET]) +def render_map(): + departments_by_state = Department.by_state() + return Response( + render_template( + "map.svg", + departments_by_state=departments_by_state, + map_paths=current_app.config["MAP_DATA"], + ), + mimetype="image/svg+xml", ) diff --git a/OpenOversight/app/templates/browse.html b/OpenOversight/app/templates/browse.html index 5266e545f..c6bb64b03 100644 --- a/OpenOversight/app/templates/browse.html +++ b/OpenOversight/app/templates/browse.html @@ -13,36 +13,7 @@

Browse Officers by Department

Use the map or list below to browse officers by department.

- - - - - {% for state, path in map_paths.items() %} - {% if state in departments_by_state.keys() %} - - - - {% else %} - - {% endif %} - {% endfor %} - + {% for state, departments in departments_by_state.items() %}

{{ state | get_state_full_name }}

diff --git a/OpenOversight/app/templates/index.html b/OpenOversight/app/templates/index.html index c3a17d218..e1899dd16 100644 --- a/OpenOversight/app/templates/index.html +++ b/OpenOversight/app/templates/index.html @@ -23,34 +23,8 @@

OpenOversight

- - - - - {% for state, path in map_paths.items() %} - {% if state in departments_by_state.keys() %} - - {% else %} - - {% endif %} - {% endfor %} - + Map of states with departments in OpenOversight
+ + + + {% for state, path in map_paths.items() %} + {% if state in departments_by_state.keys() %} + + + + {% else %} + + {% endif %} + {% endfor %} + diff --git a/OpenOversight/tests/routes/test_other.py b/OpenOversight/tests/routes/test_other.py index 9e19ead5c..ab6026790 100644 --- a/OpenOversight/tests/routes/test_other.py +++ b/OpenOversight/tests/routes/test_other.py @@ -4,6 +4,7 @@ import pytest from flask import current_app, url_for +from OpenOversight.app.models.database import Department from OpenOversight.app.utils.constants import ENCODING_UTF_8, KEY_TIMEZONE from OpenOversight.tests.constants import GENERAL_USER_USERNAME from OpenOversight.tests.routes.route_helpers import login_user @@ -83,3 +84,14 @@ def test_timezone_setting_empty_string(client): assert rv.status_code == HTTPStatus.OK with client.session_transaction() as session: assert session[KEY_TIMEZONE] == current_app.config.get(KEY_TIMEZONE) + + +def test_map_rendering(client, mockdata): + with current_app.test_request_context(): + departments_by_state = Department.by_state() + rv = client.get(url_for("main.render_map")) + assert rv.status_code == HTTPStatus.OK + assert rv.mimetype == "image/svg+xml" + + for state in departments_by_state.keys(): + assert f"#state-{state}" in rv.data.decode(ENCODING_UTF_8)