auth/tauth/views/helper.py
2024-12-20 23:44:31 -05:00

38 lines
907 B
Python

import random
from django.core.handlers.wsgi import WSGIRequest
from django.http import HttpResponse
from django.template import loader
from tauth.settings import config
COLORS = ["rosewater", "flamingo", "pink", "mauve", "red", "maroon", "peach", "yellow", "green", "teal", "sky", "sapphire", "blue", "lavender"]
def render_template(
request: WSGIRequest,
template: str,
/, *,
status: int=200,
headers: dict[str, str]={},
content_type: str="text/html",
**context
) -> HttpResponse:
c = {
"theme": "auto",
"accent": random.choice(COLORS),
"config": config
}
for key, val in context.items():
c[key] = val
resp = HttpResponse(
loader.get_template(template).render(c, request),
status=status,
content_type=content_type
)
for key, val in headers.items():
resp[key] = val
return resp