diff options
author | Stas Medvedev <medvedevsa97@gmail.com> | 2024-06-12 16:05:12 +0300 |
---|---|---|
committer | Stas Medvedev <medvedevsa97@gmail.com> | 2024-06-12 16:05:12 +0300 |
commit | ed49bb17b9e93a1406ab51f7dca5906661863627 (patch) | |
tree | fd5dfa78e46c9b29dcd1fdaf3897fbd117cf7c2b | |
parent | 3805407b0868aeccf7462a68c1d86540764bc02f (diff) |
refactore utils
refactore html about, client_geo
-rw-r--r-- | .vscode/launch.json | 20 | ||||
-rw-r--r-- | app/main.py | 18 | ||||
-rw-r--r-- | static/style.css | 23 | ||||
-rw-r--r-- | templates/partials/about.html | 37 | ||||
-rw-r--r-- | templates/partials/avatars.html | 2 | ||||
-rw-r--r-- | templates/partials/client_geo.html | 18 | ||||
-rw-r--r-- | utils/__init__.py (renamed from app/utils.py) | 0 |
7 files changed, 77 insertions, 41 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json index a24f6a9..4e95206 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,12 +5,28 @@ "version": "0.2.0", "configurations": [ { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": false + }, + { "name": "uvicorn", "type": "debugpy", "request": "launch", "module": "uvicorn", - "args": ["app.main:app", "--host", "0.0.0.0", "--log-config", "./log_config.json"], + "args": [ + "app.main:app", + "--host", + "0.0.0.0", + "--log-config", + "./log_config.json", + "--workers", + "1" + ], "console": "integratedTerminal" } ] -}
\ No newline at end of file +} diff --git a/app/main.py b/app/main.py index 7cf756c..59e7a8b 100644 --- a/app/main.py +++ b/app/main.py @@ -5,8 +5,7 @@ from fastapi.responses import HTMLResponse from fastapi.staticfiles import StaticFiles from starlette.templating import Jinja2Templates -from app.utils import get_avatar_urls, get_client_geo -from app.logging import logger +from utils import get_avatar_urls, get_client_geo templates = Jinja2Templates(directory="templates") @@ -17,13 +16,20 @@ app.mount("/static", StaticFiles(directory="static"), name="static") @app.get("/", response_class=HTMLResponse) async def index( request: Request, - client_geo: Annotated[dict, Depends(get_client_geo)], avatar_urls: Annotated[list[str], Depends(get_avatar_urls)], ): + return templates.TemplateResponse( + "index.html", + {"request": request, "avatar_urls": avatar_urls}, + ) - logger.info(str(dict(request.headers))) +@app.get("/client_geo", response_class=HTMLResponse) +async def client_addr( + request: Request, + client_geo: Annotated[dict, Depends(get_client_geo)], +): return templates.TemplateResponse( - "index.html", - {"request": request, "client_geo": client_geo, "avatar_urls": avatar_urls}, + "partials/client_geo.html", + {"request": request, "client_geo": client_geo}, ) diff --git a/static/style.css b/static/style.css index 70482a5..500a6e4 100644 --- a/static/style.css +++ b/static/style.css @@ -673,11 +673,6 @@ div { margin-bottom: 2.5rem; } -.my-2 { - margin-top: 0.5rem; - margin-bottom: 0.5rem; -} - .ml-6 { margin-left: 1.5rem; } @@ -702,6 +697,14 @@ div { height: 100%; } +.min-h-20 { + min-height: 5rem; +} + +.min-h-16 { + min-height: 4rem; +} + .w-full { width: 100%; } @@ -714,6 +717,12 @@ div { flex-grow: 1; } +.select-none { + -webkit-user-select: none; + -moz-user-select: none; + user-select: none; +} + .list-outside { list-style-position: outside; } @@ -722,10 +731,6 @@ div { list-style-type: disc; } -.flex-row { - flex-direction: row; -} - .flex-col { flex-direction: column; } diff --git a/templates/partials/about.html b/templates/partials/about.html index b9dc26d..238d895 100644 --- a/templates/partials/about.html +++ b/templates/partials/about.html @@ -1,10 +1,15 @@ -<div class="about relative text-center"> +<div class="about relative text-center"> <p>Привет, меня зовут Стас</p> <p> Я - <a class="text-interactive group" href="https://habr.com/ru/companies/ruvds/articles/488340/"> + <a + class="text-interactive group" + href="https://habr.com/ru/companies/ruvds/articles/488340/" + > backend - <span class="hidden z-10 group-hover:inline-block absolute text-black bg-neutral-100 border-2 border-neutral-500 inset-x-0 my-10 p-2"> + <span + class="hidden z-10 group-hover:inline-block absolute text-black bg-neutral-100 border-2 border-neutral-500 inset-x-0 my-10 p-2" + > Если говорить академично, то бэкенд-разработчик — это программист, который отвечает за внутреннюю и вычислительную логику веб-сайта или веб-приложения, а также иного программного обеспечения и информационных @@ -22,24 +27,10 @@ В основном пишу на <a href="https://python.org" class="text-interactive">python</a> </p> - <div class="gap-2 flex flex-wrap text-2xl my-2"> - <p class="w-full "> - Уже вычислил тебя по ip: - </p> - <div class="w-full flex flex-wrap justify-around"> - <span>😎</span> - <a class="block text-center underline decoration-primary-300" href="https://ip-api.com"> - {{client_geo['query']}} - </a> - <span>😎</span> - </div> - {% if 'city' in client_geo %} - <div class="flex w-full"> - <p>{{client_geo['country']}}</p> - <p>{{client_geo['city']}}</p> - </div> - {% endif %} - - </div> - + <div + hx-get="/client_geo" + hx-trigger="load" + hx-swap="outerHTML" + class="w-full min-h-16" + ></div> </div> diff --git a/templates/partials/avatars.html b/templates/partials/avatars.html index a6f84ff..4a5c05f 100644 --- a/templates/partials/avatars.html +++ b/templates/partials/avatars.html @@ -1,5 +1,5 @@ <div class="swiper h-full"> - <div class="swiper-wrapper"> + <div class="swiper-wrapper select-none"> {% for url in avatar_urls %} <img src="{{url}}" alt="" class="swiper-slide"/> {% endfor %} diff --git a/templates/partials/client_geo.html b/templates/partials/client_geo.html new file mode 100644 index 0000000..fac4371 --- /dev/null +++ b/templates/partials/client_geo.html @@ -0,0 +1,18 @@ +<div class="w-full flex flex-col text-2xl"> + <p>Уже вычислил тебя по ip:</p> + <div class="flex w-full justify-around"> + <span>😎</span> + <a + class="block text-center underline decoration-primary-300" + href="https://ip-api.com" + > + {{client_geo['query']}} + </a> + <span>😎</span> + </div> + + {% if 'city' in client_geo %} + <p>{{client_geo['country']}}</p> + <p>{{client_geo['city']}}</p> + {% endif %} +</div> diff --git a/app/utils.py b/utils/__init__.py index 22d7058..22d7058 100644 --- a/app/utils.py +++ b/utils/__init__.py |