Use global context for db_size and amount_of_feeds
This commit is contained in:
parent
06964a5761
commit
61b9db1333
3 changed files with 28 additions and 30 deletions
27
feeds/context_processors.py
Normal file
27
feeds/context_processors.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from django.http import HttpRequest
|
||||
|
||||
|
||||
def add_global_context(request: HttpRequest) -> dict[str, str | int]: # noqa: ARG001
|
||||
"""Add global context to all templates.
|
||||
|
||||
Args:
|
||||
request: The request object.
|
||||
|
||||
Returns:
|
||||
A dictionary with the global context.
|
||||
"""
|
||||
from feeds.stats import get_db_size # noqa: PLC0415
|
||||
|
||||
from .models import Feed # noqa: PLC0415
|
||||
|
||||
db_size: str = get_db_size()
|
||||
amount_of_feeds: int = Feed.objects.count()
|
||||
return {
|
||||
"db_size": db_size,
|
||||
"amount_of_feeds": amount_of_feeds,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue