From 29058a2b266f4ed45e17ffc88b5853f8e390c1f2 Mon Sep 17 00:00:00 2001 From: surtur Date: Tue, 11 Aug 2020 15:12:22 +0200 Subject: [PATCH] chore: added basic teplating [wip] --- app/main.py | 16 +++++++- app/schemas.py | 24 +++++++++++ app/settings/globals.py | 5 +++ app/templates/dashboard.html.j2 | 70 +++++++++++++++++++++++++++++++++ app/templates/layout.html | 31 +++++++++++++++ 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 app/templates/dashboard.html.j2 create mode 100644 app/templates/layout.html diff --git a/app/main.py b/app/main.py index 57bf82b..bedab0a 100644 --- a/app/main.py +++ b/app/main.py @@ -4,8 +4,9 @@ import asyncio from typing import List, Optional -from fastapi import FastAPI, Depends, Security, HTTPException +from fastapi import FastAPI, Depends, Security, HTTPException, Request from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm +from fastapi.templating import Jinja2Templates from sqlalchemy.orm import Session from app import crud, models, schemas, auth @@ -15,6 +16,7 @@ from app.database import SessionLocal, engine models.Base.metadata.create_all(bind=engine) oauth2_scheme = OAuth2PasswordBearer(tokenUrl='/api/v1/auth/get_token') +templates=Jinja2Templates(directory="app/templates") app = FastAPI(title="Statuspage API",description="This documentation describes the Statuspage API.",version="0.0.1") @@ -155,3 +157,15 @@ async def get_metrics(skip: int = 0, limit: int = 90, db: Session = Depends(get_ async def get_urls(skip: int = 0, limit: int = 90, db: Session = Depends(get_db)): return crud.get_urls(db=db, skip=skip, limit=limit) + +""" +webpage routes +""" +@app.get("/") +def status_dashboard(request:Request): + """ + Serves the main page + """ + #return {"Dashboard": "Home page"} + return templates.TemplateResponse("dashboard.html.j2", {"request": request}) + diff --git a/app/schemas.py b/app/schemas.py index f20107b..8486b55 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -40,6 +40,7 @@ class UserBase(BaseModel): name: str full_name: Optional[str] = None is_active: bool = True + is_superuser: bool = False class User(BaseModel): created_unix: float @@ -54,6 +55,7 @@ class UserUpdate(UserBase): full_name: Optional[str] password: Optional[str] is_active: Optional[bool] + is_superuser: Optional[bool] class User(UserBase): pass @@ -63,6 +65,25 @@ class User(UserBase): +class MetricBase(BaseModel): + service_id: int + http_response_code: int + +class Metric(BaseModel): + request_unix: float + response_unix: float + +class MetricCreate(UserBase): + status: int + +class Metric(MetricBase): + pass + + class Config: + orm_mode = True + + + class APISimpleSuccessResponse(BaseModel): success: bool = True @@ -74,3 +95,6 @@ class Token(BaseModel): access_token: str token_type: str +class TokenPayload(BaseModel): + sub: str = None + diff --git a/app/settings/globals.py b/app/settings/globals.py index 5f96bbb..a3c2142 100644 --- a/app/settings/globals.py +++ b/app/settings/globals.py @@ -1,5 +1,6 @@ from pathlib import Path from typing import Optional +from pydantic import AnyHttpUrl from starlette.config import Config @@ -7,6 +8,10 @@ from starlette.config import Config p: Path = Path(__file__).parents[2] / "statuspagerc" config: Config = Config(p if p.exists() else None) +SERVER_NAME: Optional[str] +SERVER_HOST: Optional[AnyHttpUrl] + + DATABASE: str = config("DATABASE", cast=str) ALEMBIC_CONFIG: str = ( diff --git a/app/templates/dashboard.html.j2 b/app/templates/dashboard.html.j2 new file mode 100644 index 0000000..4be88c0 --- /dev/null +++ b/app/templates/dashboard.html.j2 @@ -0,0 +1,70 @@ +{% extends "layout.html" %} +{% block content %} +

Dashboard

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ownernamepinged timesMetrics
15min10min5min
Alphaservice 12 + +
Betaservice 152 + +
service 212 + +
service 321 + +
+ +{% endblock %} + diff --git a/app/templates/layout.html b/app/templates/layout.html new file mode 100644 index 0000000..c0522c2 --- /dev/null +++ b/app/templates/layout.html @@ -0,0 +1,31 @@ + + + + + + Statuspage + + + + + +
+ +

Status page

+ {% block content %} + {% endblock %} +
+ + +