push changes
This commit is contained in:
28
config.py
28
config.py
@@ -1,21 +1,17 @@
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from urllib.parse import quote_plus
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).resolve().parent
|
BASE_DIR = Path(__file__).resolve().parent
|
||||||
load_dotenv(BASE_DIR / '.env')
|
load_dotenv(BASE_DIR / '.env')
|
||||||
|
|
||||||
|
|
||||||
def _normalize_sqlalchemy_db_url(raw: str | None) -> str:
|
def _q(value: str) -> str:
|
||||||
if raw:
|
return quote_plus(value or '')
|
||||||
raw = raw.strip()
|
|
||||||
if raw.startswith('postgres://'):
|
|
||||||
return raw.replace('postgres://', 'postgresql+psycopg://', 1)
|
|
||||||
if raw.startswith('sqlite:///') and not raw.startswith('sqlite:////'):
|
|
||||||
rel = raw.replace('sqlite:///', '', 1)
|
|
||||||
return f"sqlite:///{(BASE_DIR / rel).resolve()}"
|
|
||||||
return raw
|
|
||||||
|
|
||||||
|
|
||||||
|
def _build_db_url() -> str:
|
||||||
db_engine = os.getenv('DB_ENGINE', 'sqlite').strip().lower()
|
db_engine = os.getenv('DB_ENGINE', 'sqlite').strip().lower()
|
||||||
db_host = os.getenv('DB_HOST', 'localhost').strip()
|
db_host = os.getenv('DB_HOST', 'localhost').strip()
|
||||||
db_port = os.getenv('DB_PORT', '').strip()
|
db_port = os.getenv('DB_PORT', '').strip()
|
||||||
@@ -28,11 +24,17 @@ def _normalize_sqlalchemy_db_url(raw: str | None) -> str:
|
|||||||
|
|
||||||
if db_engine in ('pgsql', 'postgres', 'postgresql'):
|
if db_engine in ('pgsql', 'postgres', 'postgresql'):
|
||||||
port = db_port or '5432'
|
port = db_port or '5432'
|
||||||
return f"postgresql+psycopg://{db_user}:{db_password}@{db_host}:{port}/{db_name}"
|
return (
|
||||||
|
f"postgresql+psycopg://{_q(db_user)}:{_q(db_password)}"
|
||||||
|
f"@{db_host}:{port}/{_q(db_name)}"
|
||||||
|
)
|
||||||
|
|
||||||
if db_engine == 'mysql':
|
if db_engine == 'mysql':
|
||||||
port = db_port or '3306'
|
port = db_port or '3306'
|
||||||
return f"mysql+pymysql://{db_user}:{db_password}@{db_host}:{port}/{db_name}"
|
return (
|
||||||
|
f"mysql+pymysql://{_q(db_user)}:{_q(db_password)}"
|
||||||
|
f"@{db_host}:{port}/{_q(db_name)}"
|
||||||
|
)
|
||||||
|
|
||||||
raise ValueError(f"Nieobsługiwany DB_ENGINE: {db_engine}")
|
raise ValueError(f"Nieobsługiwany DB_ENGINE: {db_engine}")
|
||||||
|
|
||||||
@@ -57,7 +59,7 @@ def _normalize_redis_url(raw: str | None) -> str:
|
|||||||
class Config:
|
class Config:
|
||||||
SECRET_KEY = os.getenv('SECRET_KEY', 'change-me-please')
|
SECRET_KEY = os.getenv('SECRET_KEY', 'change-me-please')
|
||||||
APP_MASTER_KEY = os.getenv('APP_MASTER_KEY', SECRET_KEY)
|
APP_MASTER_KEY = os.getenv('APP_MASTER_KEY', SECRET_KEY)
|
||||||
SQLALCHEMY_DATABASE_URI = _normalize_sqlalchemy_db_url(os.getenv('DATABASE_URL'))
|
SQLALCHEMY_DATABASE_URI = _build_db_url()
|
||||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
ARCHIVE_PATH = _path_from_env('ARCHIVE_PATH', BASE_DIR / 'storage' / 'archive')
|
ARCHIVE_PATH = _path_from_env('ARCHIVE_PATH', BASE_DIR / 'storage' / 'archive')
|
||||||
PDF_PATH = _path_from_env('PDF_PATH', BASE_DIR / 'storage' / 'pdf')
|
PDF_PATH = _path_from_env('PDF_PATH', BASE_DIR / 'storage' / 'pdf')
|
||||||
@@ -77,8 +79,6 @@ class Config:
|
|||||||
SESSION_COOKIE_HTTPONLY = True
|
SESSION_COOKIE_HTTPONLY = True
|
||||||
REMEMBER_COOKIE_HTTPONLY = True
|
REMEMBER_COOKIE_HTTPONLY = True
|
||||||
SESSION_COOKIE_SAMESITE = 'Lax'
|
SESSION_COOKIE_SAMESITE = 'Lax'
|
||||||
#CEIDG_API_URL = os.getenv('CEIDG_API_URL', 'https://dane.biznes.gov.pl/api/ceidg/v2/firmy')
|
|
||||||
#CEIDG_TEST_API_URL = os.getenv('CEIDG_TEST_API_URL', 'https://test-dane.biznes.gov.pl/api/ceidg/v2/firmy')
|
|
||||||
APP_FOOTER_TEXT = 'KSeF Manager · linuxiarz.pl · Mateusz Gruszczyński'
|
APP_FOOTER_TEXT = 'KSeF Manager · linuxiarz.pl · Mateusz Gruszczyński'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user