|
| 1 | +from django.shortcuts import render |
| 2 | +from indicators.models import Indicator |
| 3 | +from base.models import Pathogen |
| 4 | + |
| 5 | + |
| 6 | +HEADER_DESCRIPTION = "Discover, display and download real-time infectious disease indicators (time series) that track a variety of pathogens, diseases and syndromes in a variety of locations (primarily within the USA). Browse the list, or filter it first by locations and pathogens of interest, by surveillance categories, and more. Expand any row to expose and select from a set of related indicators, then hit 'Show Selected Indicators' at bottom to plot or export your selected indicators, or to generate code snippets to retrieve them from the Delphi Epidata API. Most indicators are served from the Delphi Epidata real-time repository, but some may be available only from third parties or may require prior approval." |
| 7 | + |
| 8 | + |
| 9 | +def alternative_interface_view(request): |
| 10 | + try: |
| 11 | + ctx = {} |
| 12 | + ctx["header_description"] = HEADER_DESCRIPTION |
| 13 | + |
| 14 | + # Fetch pathogens for dropdown |
| 15 | + ctx["pathogens"] = list( |
| 16 | + Pathogen.objects.filter(used_in="indicators").order_by( |
| 17 | + "display_order_number" |
| 18 | + ) |
| 19 | + ) |
| 20 | + |
| 21 | + # Get pathogen filter from URL parameters |
| 22 | + pathogen_filter = request.GET.get("pathogen", "") |
| 23 | + ctx["selected_pathogen"] = pathogen_filter |
| 24 | + |
| 25 | + # Build queryset with optional pathogen filtering |
| 26 | + indicators_qs = Indicator.objects.prefetch_related("pathogens").all() |
| 27 | + |
| 28 | + if pathogen_filter: |
| 29 | + indicators_qs = indicators_qs.filter(pathogens__id=pathogen_filter) |
| 30 | + |
| 31 | + # Convert to list of dictionaries |
| 32 | + ctx["indicators"] = [ |
| 33 | + { |
| 34 | + "id": indicator.id, |
| 35 | + "name": indicator.name, |
| 36 | + "source": indicator.source.name if indicator.source else "Unknown", |
| 37 | + "geographic_scope": indicator.geographic_scope.name if indicator.geographic_scope else "Unknown", |
| 38 | + "temporal_scope_end": indicator.temporal_scope_end, |
| 39 | + "description": indicator.description, |
| 40 | + "pathogens": [pathogen.name for pathogen in indicator.pathogens.all()], |
| 41 | + } |
| 42 | + for indicator in indicators_qs |
| 43 | + ] |
| 44 | + |
| 45 | + return render( |
| 46 | + request, "alternative_interface/alter_dashboard.html", context=ctx |
| 47 | + ) |
| 48 | + except Exception as e: |
| 49 | + from django.http import HttpResponse |
| 50 | + |
| 51 | + return HttpResponse(f"Error loading page: {str(e)}") |
0 commit comments