diff --git a/vaccinate/api/export_mapbox.py b/vaccinate/api/export_mapbox.py index 930aa23..e370380 100644 --- a/vaccinate/api/export_mapbox.py +++ b/vaccinate/api/export_mapbox.py @@ -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] diff --git a/vaccinate/config/urls.py b/vaccinate/config/urls.py index df212a4..04a9db2 100644 --- a/vaccinate/config/urls.py +++ b/vaccinate/config/urls.py @@ -20,6 +20,8 @@ path("", core_views.index), path("healthcheck", core_views.healthcheck), path("logout", logout), + path("location", core_views.location_search), + path("location/", 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), diff --git a/vaccinate/core/views.py b/vaccinate/core/views.py index 42f4c4d..f89a4cb 100644 --- a/vaccinate/core/views.py +++ b/vaccinate/core/views.py @@ -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 @@ -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(), + }, + ) diff --git a/vaccinate/templates/location.html b/vaccinate/templates/location.html new file mode 100644 index 0000000..249daed --- /dev/null +++ b/vaccinate/templates/location.html @@ -0,0 +1,466 @@ +{% extends "api/base.html" %} + +{% block title %}{{ location }} - VIAL{% endblock %} + +{% block content %} +

{{ location }}

+

{{ location.public_id }} - {{ location.full_address }}

+

Find another location

+ +{% for title, content in api_previews %} +

{{ title }}

+
{{ content }}
+{% endfor %} + +

In our database

+
View model in our database + +

+ ID: + {{ location.public_id }} +

+

+ name: + {{ location.name }} +

+

+ phone_number: + {{ location.phone_number }} +

+

+ location_type: + {{ location.location_type }} +

+ + +

+ full_address: + {{ location.full_address }} +

+

+ street_address: + {{ location.street_address }} +

+

+ city: + {{ location.city }} +

+ +

+ state: + {{ location.state }} +

+

+ county: + {{ location.county }} +

+ +

+ zip_code: + {{ location.zip_code }} +

+ + +

+ hours: + {{ location.hours }} +

+ + + +

+ website: + {{ location.website }} +

+ + + +

+ vaccines_offered: + {{ location.vaccines_offered }} +

+ + +

+ accepts_appointments: + {{ location.accepts_appointments }} +

+ + +

+ accepts_walkins: + {{ location.accepts_walkins }} +

+ +

+ public_notes: + {{ location.public_notes }} +

+ + + +

+ google_places_id: + {{ location.google_places_id }} +

+ +

+ vaccinespotter_location_id: + {{ location.vaccinespotter_location_id }} +

+ +

+ vaccinefinder_location_id: + {{ location.vaccinefinder_location_id }} +

+ +

+ provider: + {{ location.provider }} +

+ + +

+ latitude: + {{ location.latitude }} +

+ + + +

+ longitude: + {{ location.longitude }} +

+ + + +

+ point: + {{ location.point }} +

+ +

+ soft_deleted: + {{ location.soft_deleted }} +

+ +

+ soft_deleted_because: + {{ location.soft_deleted_because }} +

+ +

+ duplicate_of: + {{ location.duplicate_of }} +

+ +

+ import_run: + {{ location.import_run }} +

+ + +

+ provenance: + {{ location.provenance }} +

+ + + +

+ internal_notes: + {{ location.internal_notes }} +

+ + + +

+ do_not_call: + {{ location.do_not_call }} +

+ + + +

+ do_not_call_reason: + {{ location.do_not_call_reason }} +

+ + + + +

+ created_at: + {{ location.created_at }} +

+ +

+ created_by: + {{ location.created_by }} +

+ + +

+ airtable_id: + {{ location.airtable_id }} +

+ + +

+ public_id: + {{ location.public_id }} +

+ +

+ import_json: + {{ location.import_json }} +

+ +

+ import_ref: + {{ location.import_ref }} +

+ + + +

+ preferred_contact_method: + {{ location.preferred_contact_method }} +

+ + +

+ is_pending_review: + {{ location.is_pending_review }} +

+
+ +

Denormalized values

+
View denormalized values +

+ dn_latest_report: + {{ location.dn_latest_report }} +

+ +

+ dn_latest_report_including_pending: + {{ location.dn_latest_report_including_pending }} +

+

+ dn_latest_yes_report: + {{ location.dn_latest_yes_report }} +

+

+ dn_latest_skip_report: + {{ location.dn_latest_skip_report }} +

+

+ dn_latest_non_skip_report: + {{ location.dn_latest_non_skip_report }} +

+

+ dn_skip_report_count: + {{ location.dn_skip_report_count }} +

+ +

+ dn_yes_report_count: + {{ location.dn_yes_report_count }} +

+
+ +{% if location.dn_latest_non_skip_report %} +

Latest non-skip report

+
View latest non-skip report +
+ {{ location.dn_latest_non_skip_report }} +

+ is_pending_review: + {{ location.is_pending_review }} +

+

+ originally_pending_review: + {{ location.originally_pending_review }} +

+

+ pending_review_because: + {{ location.pending_review_because }} +

+

+ claimed_by: + {{ location.claimed_by }} +

+

+ claimed_at: + {{ location.claimed_at }} +

+

+ soft_deleted: + {{ location.soft_deleted }} +

+

+ soft_deleted_because: + {{ location.soft_deleted_because }} +

+

+ report_source: + {{ location.report_source }} +

+

+ appointment_tag: + {{ location.appointment_tag }} +

+

+ appointment_details: + {{ location.appointment_details }} +

+

+ public_notes: + {{ location.public_notes }} +

+

+ internal_notes: + {{ location.internal_notes }} +

+

+ restriction_notes: + {{ location.restriction_notes }} +

+

+ vaccines_offered: + {{ location.vaccines_offered }} +

+

+ website: + {{ location.website }} +

+

+ full_address: + {{ location.full_address }} +

+

+ hours: + {{ location.hours }} +

+

+ planned_closure: + {{ location.planned_closure }} +

+

+ reported_by: + {{ location.reported_by }} +

+

+ created_at: + {{ location.created_at }} +

+

+ call_request: + {{ location.call_request }} +

+

+ availability_tags: + {{ location.availability_tags }} +

+

+ airtable_id: + {{ location.airtable_id }} +

+

+ airtable_json: + {{ location.airtable_json }} +

+

+ public_id: + {{ location.public_id }} +

+
+
+{% endif %} + +

Concordances

+ +{% for concordance in location.concordances.all %} + {{ concordance }} +{% empty %} + None +{% endfor %} + +

Matched source locations

+
View matched source locations +{% for source_location in source_locations %} +

{{ source_location }}

+

Created at {{ source_location.created_at }}, last imported at {{ source_location.last_imported_at }}

+ Availability:
{{ source_location.import_json.availability|pprint }}
+ Inventory:
{{ source_location.import_json.inventory|pprint }}
+
{{ source_location.import_json|pprint }}
+{% endfor %} +
+ + + +{% endblock %} diff --git a/vaccinate/templates/location_search.html b/vaccinate/templates/location_search.html new file mode 100644 index 0000000..608df31 --- /dev/null +++ b/vaccinate/templates/location_search.html @@ -0,0 +1,42 @@ +{% extends "api/base.html" %} + +{% block title %}Location debug search{% endblock %} + +{% block content %} +

Location debug search

+ +
+

+ + +

+
+
+ + + +{% endblock %}