Skip to content

Commit

Permalink
change templates folder to be relative to current file
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcampbell committed Oct 16, 2023
1 parent d874ce0 commit b9a622e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
30 changes: 23 additions & 7 deletions nsls2api/views/diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from pathlib import Path

import fastapi
from fastapi import HTTPException
from fastapi import status
from starlette.requests import Request
from starlette.templating import Jinja2Templates

from nsls2api.viewmodels.diagnostics.proposal_viewmodel import ProposalDiagnosticsViewModel
from nsls2api.viewmodels.diagnostics.user_viewmodel import UserDiagnosticsViewModel
from nsls2api.viewmodels.diagnostics.proposal_viewmodel import (
ProposalDiagnosticsViewModel,
)
from nsls2api.viewmodels.diagnostics.user_viewmodel import (
UserDiagnosticsViewModel,
)

templates = Jinja2Templates("templates")
templates = Jinja2Templates(
directory=str(Path(__file__).parent.parent / "templates")
)
router = fastapi.APIRouter()


Expand All @@ -18,11 +26,15 @@ async def diag_username(username: str, request: Request):

# if there was a problem in getting the information for a user then the error will not be None.
if vm.error:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=vm.error)
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail=vm.error
)

print(vm.to_dict())

return templates.TemplateResponse("diagnostics/user_diagnostics.html", vm.to_dict())
return templates.TemplateResponse(
"diagnostics/user_diagnostics.html", vm.to_dict()
)


@router.get("/diagnostics/proposal/{proposal_id}", include_in_schema=False)
Expand All @@ -32,8 +44,12 @@ async def diag_proposal(proposal_id: int, request: Request):

# if there was a problem in getting the information for a user then the error will not be None.
if vm.error:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=vm.error)
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail=vm.error
)

print(vm.to_dict())

return templates.TemplateResponse("diagnostics/proposal_diagnostics.html", vm.to_dict())
return templates.TemplateResponse(
"diagnostics/proposal_diagnostics.html", vm.to_dict()
)
16 changes: 12 additions & 4 deletions nsls2api/views/home.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path

import fastapi
import jinja_partials
from starlette.requests import Request
Expand All @@ -6,7 +8,7 @@
from nsls2api.viewmodels.proposals.details_viewmodel import DetailsViewModel
from nsls2api.viewmodels.proposals.search_viewmodel import SearchViewModel

templates = Jinja2Templates("templates")
templates = Jinja2Templates(directory=str(Path(__file__).parent.parent / "templates"))
jinja_partials.register_starlette_extensions(templates)

router = fastapi.APIRouter()
Expand Down Expand Up @@ -35,7 +37,9 @@ async def search_proposals(request: Request):
"shared/partials/proposals_search_results.html", vm.to_dict()
)

return templates.TemplateResponse("home/proposals_search.html", vm.to_dict())
return templates.TemplateResponse(
"home/proposals_search.html", vm.to_dict()
)


@router.get("/proposals", include_in_schema=False)
Expand All @@ -55,12 +59,16 @@ def favicon():

@router.get("/favicon-16x16.png", include_in_schema=False)
def favicon16():
return fastapi.responses.RedirectResponse(url="/static/images/favicon-16x16.png")
return fastapi.responses.RedirectResponse(
url="/static/images/favicon-16x16.png"
)


@router.get("/favicon-32x32.png", include_in_schema=False)
def favicon32():
return fastapi.responses.RedirectResponse(url="/static/images/favicon-32x32.png")
return fastapi.responses.RedirectResponse(
url="/static/images/favicon-32x32.png"
)


@router.get("/site.webmanifest", include_in_schema=False)
Expand Down

0 comments on commit b9a622e

Please sign in to comment.