38 lines
962 B
Python
38 lines
962 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 = {
|
|
"accent": random.choice(COLORS),
|
|
"config": config,
|
|
"login_token": f"/auth/?sessionid={request.COOKIES.get('session_id')}"
|
|
}
|
|
|
|
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
|