Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
/location and /location/public_id debug tools
Browse files Browse the repository at this point in the history
Show the output of our various APIs all in one place.

Essential for figuring out if our various denormalizations
and expansions are working correctly.
  • Loading branch information
simonw committed Jun 9, 2021
1 parent 89cf550 commit 14c9098
Show file tree
Hide file tree
Showing 5 changed files with 575 additions and 2 deletions.
2 changes: 1 addition & 1 deletion vaccinate/api/export_mapbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def export_mapbox_preview(request):
# Maximum of 20 for the debugging preview
locations = locations.order_by("-id")[:20]

expansion = VaccineFinderInventoryExpansion(load_all=True)
expansion = VaccineFinderInventoryExpansion(load_all=not ids)

preview = {
"geojson": [_mapbox_geojson(location, expansion) for location in locations]
Expand Down
2 changes: 2 additions & 0 deletions vaccinate/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
path("", core_views.index),
path("healthcheck", core_views.healthcheck),
path("logout", logout),
path("location", core_views.location_search),
path("location/<public_id>", core_views.location),
path("dashboard/", include(django_sql_dashboard.urls)),
path("api/docs", api_views.api_docs),
path("api/submitReport", caller_api_views.submit_report),
Expand Down
65 changes: 64 additions & 1 deletion vaccinate/core/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import json
import os
import sys

import pkg_resources
from api import search as search_views
from api.export_mapbox import export_mapbox_preview
from django.contrib.auth.decorators import login_required, user_passes_test
from django.db import connection
from django.http.response import JsonResponse
from django.shortcuts import redirect, render
from django.shortcuts import get_object_or_404, redirect, render
from django.test.client import RequestFactory
from reversion import get_registered_models

from .models import Location


def index(request):
user = request.user
Expand All @@ -33,3 +40,59 @@ def healthcheck(request):
"reversion_models": [m._meta.label for m in get_registered_models()],
}
)


@login_required
@user_passes_test(lambda user: user.is_staff)
def location_search(request):
return render(request, "location_search.html")


@login_required
@user_passes_test(lambda user: user.is_staff)
def location(request, public_id):
location = get_object_or_404(Location, public_id=public_id)
api_previews = {}
rf = RequestFactory()
for title, view_fn, url, transform in (
(
"Mapbox GeoJSON representation (for vaccinatethestates.com)",
export_mapbox_preview,
"/?raw=1&id=" + location.public_id,
lambda d: d["geojson"][0],
),
(
"APIv0 (for api.vaccinatethestates.com)",
search_views.search_locations,
"/?format=v0preview&id=" + location.public_id,
lambda d: d["content"][0],
),
(
"APIv0 GeoJSON (for api.vaccinatethestates.com)",
search_views.search_locations,
"/?format=v0preview-geojson&id=" + location.public_id,
lambda d: d["features"][0],
),
):
req = rf.get(url)
req.skip_api_logging = True
req.skip_jwt_auth = True
res = view_fn(req)
if hasattr(res, "streaming_content"):
content = b"".join(res.streaming_content)
else:
content = res.content
data = transform(json.loads(content))
api_previews[title] = json.dumps(data, indent=4)

return render(
request,
"location.html",
{
"location": location,
"source_locations": location.matched_source_locations.order_by(
"-created_at"
).prefetch_related("concordances"),
"api_previews": api_previews.items(),
},
)
Loading

1 comment on commit 14c9098

@simonw
Copy link
Collaborator Author

@simonw simonw commented on 14c9098 Jun 10, 2021

Choose a reason for hiding this comment

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

Refs #653

Please sign in to comment.