0.1.0 boosted
This commit is contained in:
parent
126e90084e
commit
f29c40d25e
11 changed files with 181 additions and 22 deletions
|
|
@ -1,4 +1,4 @@
|
|||
# SPDX-FileCopyrightText: 2024-present Waylon S. Walker <waylon@waylonwalker.com>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
__version__ = "0.0.4"
|
||||
__version__ = "0.1.0"
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from fastapi import Depends, FastAPI, Request
|
|||
from fastapi.responses import FileResponse
|
||||
|
||||
from htmx_patterns.__about__ import __version__
|
||||
from htmx_patterns.boosted.router import boosted_router
|
||||
from htmx_patterns.config import get_config
|
||||
from htmx_patterns.infinite.router import infinite_router
|
||||
|
||||
|
|
@ -36,10 +37,11 @@ app = FastAPI(
|
|||
config = get_config()
|
||||
|
||||
app.include_router(infinite_router)
|
||||
app.include_router(boosted_router)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def read_main(request: Request):
|
||||
async def index(request: Request):
|
||||
return config.templates.TemplateResponse("index.html", {"request": request})
|
||||
|
||||
|
||||
|
|
|
|||
24
htmx_patterns/boosted/models.py
Normal file
24
htmx_patterns/boosted/models.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from datetime import date, datetime
|
||||
from typing import List, Union
|
||||
|
||||
from faker import Faker
|
||||
from polyfactory.factories.pydantic_factory import ModelFactory
|
||||
from pydantic import UUID4, BaseModel
|
||||
|
||||
faker = Faker()
|
||||
|
||||
|
||||
class Person(BaseModel):
|
||||
id: UUID4
|
||||
name: str
|
||||
birthday: Union[datetime, date]
|
||||
phone_number: str
|
||||
|
||||
|
||||
class PersonFactory(ModelFactory):
|
||||
name = faker.name
|
||||
phone_number = faker.phone_number
|
||||
__model__ = Person
|
||||
|
||||
|
||||
# result = PersonFactory.build()
|
||||
37
htmx_patterns/boosted/router.py
Normal file
37
htmx_patterns/boosted/router.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import asyncio
|
||||
import time
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi.requests import Request
|
||||
|
||||
boosted_router = APIRouter(prefix="/boosted", tags=["Shots Methods"])
|
||||
|
||||
from htmx_patterns.boosted.models import PersonFactory
|
||||
from htmx_patterns.config import get_config
|
||||
|
||||
config = get_config()
|
||||
|
||||
|
||||
@boosted_router.get("/")
|
||||
@boosted_router.get("")
|
||||
async def boosted(request: Request, id: int = 0):
|
||||
# simulate getting a person by id
|
||||
person = PersonFactory.build()
|
||||
|
||||
if id > 0:
|
||||
prev_id = id - 1
|
||||
next_id = id + 1
|
||||
else:
|
||||
prev_id = None
|
||||
next_id = id + 1
|
||||
|
||||
return config.templates.TemplateResponse(
|
||||
"boosted/person.html",
|
||||
{
|
||||
"request": request,
|
||||
"person": person,
|
||||
"person_id": id,
|
||||
"prev_id": prev_id,
|
||||
"next_id": next_id,
|
||||
},
|
||||
)
|
||||
|
|
@ -32,11 +32,6 @@ class ApiServer(BaseModel):
|
|||
proxy_headers: bool = True
|
||||
|
||||
|
||||
# @pass_context
|
||||
# def https_url_for(context: dict, name: str, **params: Any) -> str:
|
||||
# http_url = url_for_query(context, name, **params)
|
||||
# return str(http_url).replace("http", "https", 1)
|
||||
|
||||
|
||||
@pass_context
|
||||
def url_for_query(context: dict, name: str, **params: dict) -> str:
|
||||
|
|
@ -71,7 +66,6 @@ def url_for_query(context: dict, name: str, **params: dict) -> str:
|
|||
|
||||
if os.environ.get("ENV") in ["dev", "qa", "prod"]:
|
||||
updated_url = updated_url.replace("http", "https", 1)
|
||||
|
||||
return updated_url
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ async def infinite(request: Request, page: int = 1, n: int = 10):
|
|||
persons = [PersonFactory.build() for _ in range(n)]
|
||||
|
||||
if request.state.prefers_partial:
|
||||
await asyncio.sleep(0.5)
|
||||
await asyncio.sleep(1)
|
||||
return config.templates.TemplateResponse(
|
||||
"infinite/persons_partial.html",
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue