Bugfix blueprint naming

Following discussions for Flask we've decided to name blueprints based
on how they are registered. This allows for two different blueprints
to have the same self-name as long as they are registered in different
nested positions. This helps users choose better blueprint names.
This commit is contained in:
pgjones 2021-05-18 13:33:45 +01:00
parent 99afbb277d
commit 141fde1d8e
3 changed files with 50 additions and 33 deletions

View file

@ -1,6 +1,7 @@
import typing as t
from werkzeug.exceptions import BadRequest
from werkzeug.utils import cached_property
from werkzeug.wrappers import Request as RequestBase
from werkzeug.wrappers import Response as ResponseBase
@ -77,6 +78,21 @@ class Request(RequestBase):
else:
return None
@cached_property
def blueprints(self) -> t.List[str]:
"""The names of the current blueprint upwards through parent
blueprints.
"""
if self.blueprint is None:
return []
bps: t.List[str] = [self.blueprint]
while "." in bps[-1]:
bps.append(bps[-1].rpartition(".")[0])
return bps
def _load_form_data(self) -> None:
RequestBase._load_form_data(self)