Files
contact.allucanget.biz/server/settings.py
zwitschi 56840ac313
All checks were successful
CI / test (3.11) (push) Successful in 9m26s
CI / build-image (push) Successful in 49s
feat(newsletter): Add subscription confirmation email functionality
- Implemented `send_subscription_confirmation` function to send a confirmation email upon subscription.
- Added a default HTML template for the confirmation email in settings.
- Updated the newsletter management page to handle subscription and unsubscription actions.
- Created new templates for embedding contact and newsletter forms.
- Added styles for the new templates and unified CSS styles across the application.
- Updated tests to reflect changes in the newsletter management API endpoints.
2025-10-30 12:38:26 +01:00

77 lines
2.6 KiB
Python

"""Environment driven configuration values."""
from __future__ import annotations
import os
import re
from pathlib import Path
from dotenv import load_dotenv
from .utils import normalize_recipients
load_dotenv()
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = os.getenv("FLASK_SECRET_KEY", "dev")
SENTRY_DSN = os.getenv("SENTRY_DSN")
SENTRY_TRACES_SAMPLE_RATE = float(
os.getenv("SENTRY_TRACES_SAMPLE_RATE", "0.0"))
ENABLE_REQUEST_LOGS = os.getenv("ENABLE_REQUEST_LOGS", "true").lower() in {
"1", "true", "yes"}
ENABLE_JSON_LOGS = os.getenv("ENABLE_JSON_LOGS", "false").lower() in {
"1", "true", "yes"}
DATABASE_URL = os.getenv("DATABASE_URL")
POSTGRES_URL = os.getenv("POSTGRES_URL")
def resolve_sqlite_path() -> Path:
"""Resolve the configured SQLite path honoring DATABASE_URL."""
if DATABASE_URL:
if DATABASE_URL.startswith("sqlite:"):
match = re.match(r"sqlite:(?:////?|)(.+)", DATABASE_URL)
if match:
return Path(match.group(1))
return Path("data/forms.db")
return Path(DATABASE_URL)
return BASE_DIR / "data" / "forms.db"
SQLITE_DB_PATH = resolve_sqlite_path()
RATE_LIMIT_MAX = int(os.getenv("RATE_LIMIT_MAX", "10"))
RATE_LIMIT_WINDOW = int(os.getenv("RATE_LIMIT_WINDOW", "60"))
REDIS_URL = os.getenv("REDIS_URL")
STRICT_ORIGIN_CHECK = os.getenv("STRICT_ORIGIN_CHECK", "false").lower() in {
"1", "true", "yes"}
ALLOWED_ORIGIN = os.getenv("ALLOWED_ORIGIN")
SMTP_SETTINGS = {
"host": os.getenv("SMTP_HOST"),
"port": int(os.getenv("SMTP_PORT", "587")),
"username": os.getenv("SMTP_USERNAME"),
"password": os.getenv("SMTP_PASSWORD"),
"sender": os.getenv("SMTP_SENDER"),
"use_tls": os.getenv("SMTP_USE_TLS", "true").lower() in {"1", "true", "yes"},
"recipients": normalize_recipients(os.getenv("SMTP_RECIPIENTS")),
}
if not SMTP_SETTINGS["sender"] and SMTP_SETTINGS["username"]:
SMTP_SETTINGS["sender"] = SMTP_SETTINGS["username"]
ADMIN_USERNAME = os.getenv("ADMIN_USERNAME", "admin")
ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "admin")
NEWSLETTER_CONFIRMATION_TEMPLATE = os.getenv("NEWSLETTER_CONFIRMATION_TEMPLATE", """
<html>
<body>
<h2>Welcome to our Newsletter!</h2>
<p>Thank you for subscribing to our newsletter. You're now part of our community and will receive updates on our latest news and offers.</p>
<p>If you wish to unsubscribe at any time, you can do so by visiting our <a href="https://your-domain.com/newsletter/manage">subscription management page</a>.</p>
<p>Best regards,<br>The Team</p>
</body>
</html>
""").strip()