From a65477fac45426b7c7b566ded6a808069296f09c Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Sat, 6 Apr 2024 08:16:27 -0500 Subject: [PATCH] 0.0.2 - fix httpx --- CHANGELOG.md | 9 +++++++++ Dockerfile | 22 ++++++++++++++++++++++ htmx_patterns/__about__.py | 2 +- htmx_patterns/config.py | 26 +++++++++++++------------- justfile | 9 +++++++++ 5 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 Dockerfile create mode 100644 justfile diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..807f372 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# HTMX-PATTERNS CHANGELOG + +## 0.0.2 + +* fix https + +## 0.0.1 + +* infinite scroll diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2585672 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.11 + +WORKDIR /app + +RUN pip install uv + +COPY pyproject.toml . +COPY htmx_patterns/__about__.py ./htmx_patterns/__about__.py +COPY htmx_patterns/__init__.py ./htmx_patterns/__init__.py +COPY README.md . + +RUN uv pip install --system . +COPY . . + +EXPOSE 5000 + +RUN uv pip install --system --no-deps . +ENV TZ=America/Chicago +ENV ENV=production +# CMD ['htmx-patterns', 'api', 'run'] +CMD htmx-patterns api run + diff --git a/htmx_patterns/__about__.py b/htmx_patterns/__about__.py index d9609e8..481166c 100644 --- a/htmx_patterns/__about__.py +++ b/htmx_patterns/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2024-present Waylon S. Walker # # SPDX-License-Identifier: MIT -__version__ = "0.0.1" +__version__ = "0.0.2" diff --git a/htmx_patterns/config.py b/htmx_patterns/config.py index 4df6aa8..aa2ffe7 100644 --- a/htmx_patterns/config.py +++ b/htmx_patterns/config.py @@ -32,19 +32,17 @@ class ApiServer(BaseModel): proxy_headers: bool = True -@pass_context -def https_url_for(context: dict, name: str, **path_params: Any) -> str: - request = context["request"] - http_url = request.url_for(name, **path_params) - return str(http_url).replace("http", "https", 1) +# @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: request = context["request"] url = str(request.url_for(name)) - if params == {}: - return url + from urllib.parse import parse_qs, urlencode, urlparse, urlunparse # Parse the URL @@ -71,6 +69,9 @@ 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 @@ -80,16 +81,15 @@ def get_templates(config: BaseSettings) -> Jinja2Templates: templates.env.filters["timestamp"] = lambda u: datetime.fromtimestamp( u, tz=timezone.utc ).strftime("%B %d, %Y") - templates.env.globals["https_url_for"] = https_url_for templates.env.globals["url_for"] = url_for_query templates.env.globals["config"] = config console.print(f'Using environment: {os.environ.get("ENV")}') - if os.environ.get("ENV") in ["dev", "qa", "prod"]: - templates.env.globals["url_for"] = https_url_for - console.print("Using HTTPS") - else: - console.print("Using HTTP") + # if os.environ.get("ENV") in ["dev", "qa", "prod"]: + # templates.env.globals["url_for"] = https_url_for + # console.print("Using HTTPS") + # else: + # console.print("Using HTTP") return templates diff --git a/justfile b/justfile new file mode 100644 index 0000000..7d5fce5 --- /dev/null +++ b/justfile @@ -0,0 +1,9 @@ +default: + @just --list + +build-image: + podman build -t docker.io/waylonwalker/htmx-patterns-waylonwalker-com:0.0.2 . + +push-image: + podman push docker.io/waylonwalker/htmx-patterns-waylonwalker-com:0.0.2 +