Skip to content

Commit

Permalink
formatted and added response_classes (DHBW-FN-TIT20#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
Floskinner authored Feb 3, 2022
1 parent 610a15c commit 926049d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
20 changes: 16 additions & 4 deletions views/index.py
Original file line number Diff line number Diff line change
@@ -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})
28 changes: 21 additions & 7 deletions views/restaurant.py
Original file line number Diff line number Diff line change
@@ -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}
)
14 changes: 8 additions & 6 deletions views/signin.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,15 +18,15 @@ 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
Args:
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"

Expand All @@ -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})

return templates.TemplateResponse("signin/register.html", {"request": request, "legal": legal})

0 comments on commit 926049d

Please sign in to comment.