From 926049d699fabbeed9b43f8038dedf9914571741 Mon Sep 17 00:00:00 2001 From: Florian Glaser <58706771+Floskinner@users.noreply.github.com> Date: Thu, 3 Feb 2022 20:10:28 +0100 Subject: [PATCH] formatted and added response_classes (#31) --- views/index.py | 20 ++++++++++++++++---- views/restaurant.py | 28 +++++++++++++++++++++------- views/signin.py | 14 ++++++++------ 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/views/index.py b/views/index.py index bf57613..c2e69f7 100644 --- a/views/index.py +++ b/views/index.py @@ -1,22 +1,34 @@ """Router for the Home of the Website""" from datetime import datetime -from schemes import scheme_filter, Cuisine, Allergies, scheme_rest import fastapi +from fastapi.responses import HTMLResponse from starlette.requests import Request from starlette.templating import Jinja2Templates +from schemes import Allergies +from schemes import Cuisine +from schemes import scheme_filter +from schemes import scheme_rest + templates = Jinja2Templates("templates") router = fastapi.APIRouter() -@router.get("/") +@router.get("/", response_class=HTMLResponse) def index(request: Request): """Return the renderd template for the /index.html Args: request (Request): Requerd for Template """ - #request filter of user - rest_filter = scheme_filter.FilterRest(cuisine=Cuisine.ASIAN, allergies=Allergies.LACTOSE, rating=4, costs=2, radius=15000, location=scheme_rest.LocationBase(lat="47.7007", lng="9.562")) + # request filter of user + rest_filter = scheme_filter.FilterRest( + cuisine=Cuisine.ASIAN, + allergies=Allergies.LACTOSE, + rating=4, + costs=2, + radius=15000, + location=scheme_rest.LocationBase(lat="47.7007", lng="9.562"), + ) return templates.TemplateResponse("index.html", {"request": request, "rest_filter": rest_filter}) diff --git a/views/restaurant.py b/views/restaurant.py index e219759..cdf6767 100644 --- a/views/restaurant.py +++ b/views/restaurant.py @@ -1,16 +1,30 @@ """Router for the Home of the Website""" import enum -from schemes import scheme_rest + import fastapi +from fastapi.responses import HTMLResponse from starlette.requests import Request from starlette.templating import Jinja2Templates +from schemes import scheme_rest + templates = Jinja2Templates("templates") router = fastapi.APIRouter() -@router.get("/findrestaurant") -async def findrestaurant(request: Request, rest_name: str, costs : float, cuisine : str): - #api.Search_restaurant(...) - restaurant = scheme_rest.Restaurant(place_id="PlaceID", name=rest_name, geometry=scheme_rest.Geometry(location=scheme_rest.LocationRest(lat="47.7007", lng="9.562", adr=cuisine)), - maps_url="https://maps.google.com/?cid=10544281732087259755", rating=4.0, own_rating=costs, phone_number="07541", homepage="http://www.alpha-fn.de/") - return templates.TemplateResponse("restaurant/restaurant_result.html", {"request": request, "restaurant": restaurant}) + +@router.get("/findrestaurant", response_class=HTMLResponse) +async def findrestaurant(request: Request, rest_name: str, costs: float, cuisine: str): + # api.Search_restaurant(...) + restaurant = scheme_rest.Restaurant( + place_id="PlaceID", + name=rest_name, + geometry=scheme_rest.Geometry(location=scheme_rest.LocationRest(lat="47.7007", lng="9.562", adr=cuisine)), + maps_url="https://maps.google.com/?cid=10544281732087259755", + rating=4.0, + own_rating=costs, + phone_number="07541", + homepage="http://www.alpha-fn.de/", + ) + return templates.TemplateResponse( + "restaurant/restaurant_result.html", {"request": request, "restaurant": restaurant} + ) diff --git a/views/signin.py b/views/signin.py index fa559a9..3132230 100644 --- a/views/signin.py +++ b/views/signin.py @@ -1,12 +1,14 @@ """ Logic for Login and Registration Pages """ import fastapi +from fastapi.responses import HTMLResponse from starlette.requests import Request from starlette.templating import Jinja2Templates templates = Jinja2Templates("templates") router = fastapi.APIRouter() -@router.get("/signin/") + +@router.get("/signin/", response_class=HTMLResponse) def signin(request: Request): """Return the rendered template for the login page @@ -16,7 +18,7 @@ def signin(request: Request): return templates.TemplateResponse("signin/signin.html", {"request": request}) -@router.get("/register/") +@router.get("/register/", response_class=HTMLResponse) def register(request: Request): """Return the rendered template for the login page @@ -24,7 +26,7 @@ def register(request: Request): request (Request): Requerd for Template """ - #read terms of service and privacy policy from text files + # read terms of service and privacy policy from text files tosstring = "Terms of Service is Missing" privstring = "Privacy Policy is Missing" @@ -37,7 +39,7 @@ def register(request: Request): print(tosstring) except Exception as e: print(e) - + legal = {"tos": tosstring, "privacy": privstring} - - return templates.TemplateResponse("signin/register.html",{"request": request, "legal": legal}) \ No newline at end of file + + return templates.TemplateResponse("signin/register.html", {"request": request, "legal": legal})