Skip to content

Commit

Permalink
Added: ui context callable (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
signebedi committed Mar 28, 2024
1 parent 1584fb2 commit 6ae1f30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions libreforms_fastapi/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,17 @@ async def api_auth_login(form_data: Annotated[OAuth2PasswordRequestForm, Depends
### UI Routes - Auth
##########################

# This is a standard callable that will generate the context
# for the UI routes and Jinja templates.
def build_ui_context():

kwargs = {}

kwargs["config"] = config.model_dump()
kwargs["version"] = __version__

return kwargs

# Homepage
@app.get("/ui/home", response_class=HTMLResponse)
async def ui_homepage(request: Request):
Expand All @@ -1625,8 +1636,7 @@ async def ui_homepage(request: Request):
request=request,
name="about.html.jinja",
context={
"config": config.model_dump(),
"version": __version__,
**build_ui_context(),
}
)

Expand All @@ -1640,8 +1650,7 @@ async def ui_privacy(request: Request):
request=request,
name="privacy.html.jinja",
context={
"config": config.model_dump(),
"version": __version__,
**build_ui_context(),
}
)

Expand Down
4 changes: 2 additions & 2 deletions libreforms_fastapi/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Config(BaseSettings):
SITE_SOURCE_URL:str = os.getenv('SITE_SOURCE_URL', 'https://github.com/signebedi/libreforms-fastapi')


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>')
HOMEPAGE_CONTENT:str | Markup = 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')
Expand All @@ -81,7 +81,7 @@ def validate_homepage_content(cls, v):
raise ValueError(f'Issue converting to markup: {v}')
return m

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

@field_validator('PRIVACY_MESSAGE')
def validate_privacy_message(cls, v):
Expand Down

0 comments on commit 6ae1f30

Please sign in to comment.