Skip to content

Commit

Permalink
Fixed: issue with Markup configs (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Mar 28, 2024
1 parent 228c51b commit 780e9c9
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions libreforms_fastapi/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,39 @@ class Config(BaseSettings):
CONFIG_FILE_PATH:str = env_file_path
SITE_NAME:str = os.getenv('SITE_NAME', 'libreforms_fastapi')
SITE_SOURCE_URL:str = os.getenv('SITE_SOURCE_URL', 'https://github.com/signebedi/libreforms-fastapi')
HOMEPAGE_CONTENT:str = Markup(os.getenv('HOMEPAGE_CONTENT', ''))
PRIVACY_MESSAGE:str = Markup(os.getenv('PRIVACY_MESSAGE', ''))


HOMEPAGE_CONTENT:str = os.getenv('HOMEPAGE_CONTENT', '<p>Welcome to <code>libreforms-fastapi</code>, an open-source form management application based on the <a href="https://github.com/libreForms/spec">libreForms API</a> and built using FastAPI.</p>')


@field_validator('HOMEPAGE_CONTENT')
def validate_homepage_content(cls, v):
try:
# Attempt to create a Markup object to validate the privacy message
m = Markup(v)
except:
# If there is an issue, raise a ValueError
raise ValueError(f'Issue converting to markup: {v}')
return m

PRIVACY_MESSAGE:str = os.getenv('PRIVACY_MESSAGE', '')

@field_validator('PRIVACY_MESSAGE')
def validate_privacy_message(cls, v):
try:
# Attempt to create a Markup object to validate the privacy message
m = Markup(v)
except:
# If there is an issue, raise a ValueError
raise ValueError(f'Issue converting to markup: {v}')
return m


DOMAIN:str = os.getenv('DOMAIN', 'http://127.0.0.1:5000')
DEBUG:bool = os.getenv('DEBUG', 'False') == 'True'
SECRET_KEY:str = os.getenv('SECRET_KEY', 'supersecret_dev_key')

TIMEZONE: constr(strip_whitespace=True) = os.getenv('TIMEZONE', 'America/New_York')
TIMEZONE: ZoneInfo | str = os.getenv('TIMEZONE', 'America/New_York')

@field_validator('TIMEZONE')
def validate_timezone(cls, v):
Expand Down

0 comments on commit 780e9c9

Please sign in to comment.