From a58160973788ef90d2fb5bd458f62396875cb048 Mon Sep 17 00:00:00 2001 From: Jay Miller Date: Thu, 1 Feb 2024 12:51:44 -0500 Subject: [PATCH] remove cruft.json --- .cruft.json | 2 +- src/Dockerfile | 2 -- src/fastapi_app/app.py | 12 ++++++++++-- src/pyproject.toml | 1 + src/templates/base.html | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.cruft.json b/.cruft.json index a350527..776148a 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/Azure-Samples/Azure-Python-Standardization-Template-Generator", - "commit": "621af12f962b64b1f3458b83fa1af0898d565d80", + "commit": "0178d866789d5eef0d9b6769673640cbada8b3b9", "checkout": null, "context": { "cookiecutter": { diff --git a/src/Dockerfile b/src/Dockerfile index 9a401aa..a342db5 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -5,8 +5,6 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && apt-get update && apt-get install -y xdg-utils \ && apt-get clean -y && rm -rf /var/lib/apt/lists/* -RUN python -m pip install --upgrade pip - WORKDIR /demo-code COPY requirements.txt . diff --git a/src/fastapi_app/app.py b/src/fastapi_app/app.py index a5ef613..159f1b7 100644 --- a/src/fastapi_app/app.py +++ b/src/fastapi_app/app.py @@ -1,6 +1,7 @@ import os import pathlib +from azure.monitor.opentelemetry import configure_azure_monitor from fastapi import FastAPI, Request from fastapi.responses import HTMLResponse from fastapi.staticfiles import StaticFiles @@ -9,6 +10,9 @@ from .models import Cruise, Destination, InfoRequest, engine +if os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING"): + configure_azure_monitor() + app = FastAPI() parent_path = pathlib.Path(__file__).parent.parent app.mount("/mount", StaticFiles(directory=parent_path / "static"), name="static") @@ -39,14 +43,18 @@ def destinations(request: Request): def destination_detail(request: Request, pk: int): with Session(engine) as session: destination = session.exec(select(Destination).where(Destination.id == pk)).first() - return templates.TemplateResponse("destination_detail.html", {"request": request, "destination": destination}) + return templates.TemplateResponse( + "destination_detail.html", {"request": request, "destination": destination, "cruises": destination.cruises} + ) @app.get("/cruise/{pk}") def cruise_detail(request: Request, pk: int): with Session(engine) as session: cruise = session.exec(select(Cruise).where(Cruise.id == pk)).first() - return templates.TemplateResponse("cruise_detail.html", {"request": request, "cruise": cruise}) + return templates.TemplateResponse( + "cruise_detail.html", {"request": request, "cruise": cruise, "destinations": cruise.destinations} + ) @app.get("/info_request/", response_class=HTMLResponse) diff --git a/src/pyproject.toml b/src/pyproject.toml index 658f84b..cc1c66f 100644 --- a/src/pyproject.toml +++ b/src/pyproject.toml @@ -3,6 +3,7 @@ name = "fastapi_app" version = "1.0.0" description = "Create a relecloud demo application with fastapi and cosmos-postgres" dependencies = [ + "azure-monitor-opentelemetry", "fastapi", "jinja2", "uvicorn[standard]", diff --git a/src/templates/base.html b/src/templates/base.html index cfe04a2..301d3e6 100644 --- a/src/templates/base.html +++ b/src/templates/base.html @@ -23,7 +23,7 @@ - +