mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat(FastAPI): added /requests (get) route
Introduces `aurweb.defaults` and `aurweb.filters`. `aurweb.filters` is a location developers can put their additional Jinja2 filters and/or functions. We should slowly move all of our filters over here, where it makes sense. `aurweb.defaults` is a new module which hosts some default constants and utility functions, starting with offsets (O) and per page values (PP). As far as the new GET /requests is concerned, we match up here to PHP's implementation, with some minor improvements: Improvements: * PP on this page is now configurable: 50 (default), 100, or 250. * Example: `https://localhost:8444/requests?PP=250` Modifications: * The pagination is a bit different, but serves the exact same purpose. * "Last" no longer goes to an empty page. * Closes: https://gitlab.archlinux.org/archlinux/aurweb/-/issues/14 Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
c164abe256
commit
99482f9962
11 changed files with 341 additions and 17 deletions
|
@ -71,6 +71,20 @@ def register_filter(name: str) -> Callable:
|
|||
return decorator
|
||||
|
||||
|
||||
def register_function(name: str) -> Callable:
|
||||
""" A decorator that can be used to register a function.
|
||||
"""
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
return func(*args, **kwargs)
|
||||
if name in _env.globals:
|
||||
raise KeyError(f"Jinja already has a function named '{name}'")
|
||||
_env.globals[name] = wrapper
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
|
||||
def make_context(request: Request, title: str, next: str = None):
|
||||
""" Create a context for a jinja2 TemplateResponse. """
|
||||
|
||||
|
@ -83,6 +97,7 @@ def make_context(request: Request, title: str, next: str = None):
|
|||
"timezones": time.SUPPORTED_TIMEZONES,
|
||||
"title": title,
|
||||
"now": datetime.now(tz=zoneinfo.ZoneInfo(timezone)),
|
||||
"utcnow": int(datetime.utcnow().timestamp()),
|
||||
"config": aurweb.config,
|
||||
"next": next if next else request.url.path
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue