mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
aurweb.templates: add make_variable_context
A new make_context wrapper which additionally includes either query parameters (get) or form data (post) in the context. Use this to simplify setting context variables for form data in particular. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
9052688ed2
commit
a5be6fc9be
2 changed files with 17 additions and 10 deletions
|
@ -41,6 +41,20 @@ def make_context(request: Request, title: str, next: str = None):
|
|||
}
|
||||
|
||||
|
||||
async def make_variable_context(request: Request, title: str, next: str = None):
|
||||
""" Make a context with variables provided by the user
|
||||
(query params via GET or form data via POST). """
|
||||
context = make_context(request, title, next)
|
||||
to_copy = dict(request.query_params) \
|
||||
if request.method.lower() == "get" \
|
||||
else dict(await request.form())
|
||||
|
||||
for k, v in to_copy.items():
|
||||
context[k] = v
|
||||
|
||||
return context
|
||||
|
||||
|
||||
def render_template(request: Request,
|
||||
path: str,
|
||||
context: dict,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue