render_template: convert HTTPStatus objects

This will automate a lot of conversion that happens
around the codebase in terms of status_code.

As of this commit, we should improve usage and remove
int(status_code) casts wherever we can.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-06-19 05:06:24 -07:00
parent 7ae95ac908
commit b7d67bf5fc

View file

@ -65,7 +65,7 @@ async def make_variable_context(request: Request, title: str, next: str = None):
def render_template(request: Request, def render_template(request: Request,
path: str, path: str,
context: dict, context: dict,
status_code=int(HTTPStatus.OK)): status_code: HTTPStatus = HTTPStatus.OK):
""" Render a Jinja2 multi-lingual template with some context. """ """ Render a Jinja2 multi-lingual template with some context. """
# Create a deep copy of our jinja2 environment. The environment in # Create a deep copy of our jinja2 environment. The environment in
@ -81,7 +81,7 @@ def render_template(request: Request,
template = templates.get_template(path) template = templates.get_template(path)
rendered = template.render(context) rendered = template.render(context)
response = HTMLResponse(rendered, status_code=status_code) response = HTMLResponse(rendered, status_code=int(status_code))
response.set_cookie("AURLANG", context.get("language")) response.set_cookie("AURLANG", context.get("language"))
response.set_cookie("AURTZ", context.get("timezone")) response.set_cookie("AURTZ", context.get("timezone"))
return response return response