Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions OpenOversight/app/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)


Expand All @@ -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",
)


Expand Down
31 changes: 1 addition & 30 deletions OpenOversight/app/templates/browse.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,7 @@ <h1 class="hero">Browse Officers by Department</h1>
<div class="text-center">
<div class="col-lg-6 text-start mx-auto py-5">
<p class="mb-5 vertical-padding">Use the map or list below to browse officers by department.</p>
<svg xmlns="http://www.w3.org/2000/svg"
version="1.1"
viewBox="0 0 1000 618">
<defs>
<style>
.cls-1 {
fill: #0099c9;
}

.cls-1,
.cls-2 {
stroke: #fff;
stroke-width: .8px;
}

.cls-2 {
fill: #d3d3d3;
}
</style>
</defs>
{% for state, path in map_paths.items() %}
{% if state in departments_by_state.keys() %}
<a href="#state-{{ state }}">
<path class="cls-1" d="{{ path }}" />
</a>
{% else %}
<path class="cls-2" d="{{ path }}" />
{% endif %}
{% endfor %}
</svg>
<object type="image/svg+xml" data="{{ url_for('main.render_map') }}"></object>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using <object> here to embed the SVG interactively on the browse page

{% for state, departments in departments_by_state.items() %}
<div id="state-{{ state }}" class="state-row mt-5">
<h3>{{ state | get_state_full_name }}</h3>
Expand Down
30 changes: 2 additions & 28 deletions OpenOversight/app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,8 @@ <h1>OpenOversight</h1>
</div>
<div class="row display-flex horizontal-padding text-start">
<div class="col-lg-6">
<svg xmlns="http://www.w3.org/2000/svg"
version="1.1"
viewBox="0 0 1000 618">
<defs>
<style>
.cls-1 {
fill: #0099c9;
}

.cls-1,
.cls-2 {
stroke: #fff;
stroke-width: .8px;
}

.cls-2 {
fill: #d3d3d3;
}
</style>
</defs>
{% for state, path in map_paths.items() %}
{% if state in departments_by_state.keys() %}
<path class="cls-1" d="{{ path }}" />
{% else %}
<path class="cls-2" d="{{ path }}" />
{% endif %}
{% endfor %}
</svg>
<img alt="Map of states with departments in OpenOversight"
src="{{ url_for('main.render_map') }}" />
Comment on lines +26 to +27
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using <img> here which renders it non-interactively on the front page

</div>
<div class="col-lg-6">
<a href="{{ url_for('main.get_officer') }}"
Expand Down
28 changes: 28 additions & 0 deletions OpenOversight/app/templates/map.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions OpenOversight/tests/routes/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Loading