Commit 32abdbaf authored by Leonidas Spyropoulos's avatar Leonidas Spyropoulos Committed by Kevin Morris
Browse files

fastapi: Jinja contextfilter renamed to pass_context

Closes: #23

Signed-off-by: Leonidas Spyropoulos's avatarLeonidas Spyropoulos <>
parent 4f928b45
""" This module consists of aurweb's CAPTCHA utility functions and filters. """
import hashlib
import jinja2
from jinja2 import pass_context
from aurweb.db import query
from aurweb.models.user import User
......@@ -41,14 +41,14 @@ def get_captcha_answer(token):
return hashlib.md5((text + "\n").encode()).hexdigest()[:6]
def captcha_salt_filter(context):
""" Returns the most recent CAPTCHA salt in the list of salts. """
salts = get_captcha_salts()
return salts[0]
def captcha_cmdline_filter(context, salt):
""" Returns a CAPTCHA challenge for a given salt. """
return get_captcha_challenge(salt)
......@@ -4,7 +4,7 @@ import typing
from collections import OrderedDict
from fastapi import Request
from jinja2 import contextfilter
from jinja2 import pass_context
import aurweb.config
......@@ -88,7 +88,7 @@ def get_translator_for_request(request: Request):
return translate
def tr(context: typing.Any, value: str):
""" A translation filter; example: {{ "Hello" | tr("de") }}. """
_ = get_translator_for_request(context.get("request"))
......@@ -5,9 +5,8 @@ import string
from urllib.parse import urlparse
import jinja2
from email_validator import EmailNotValidError, EmailUndeliverableError, validate_email
from jinja2 import pass_context
import aurweb.config
......@@ -88,7 +87,7 @@ def migrate_cookies(request, response):
return response
def account_url(context, user):
request = context.get("request")
base = f"{request.url.scheme}://{request.url.hostname}"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment