Tool: PEP8 Style Checker Processed Files: reviewboard/site/decorators.py reviewboard/site/tests.py reviewboard/site/middleware.py Tool: Pyflakes Processed Files: reviewboard/site/decorators.py reviewboard/site/tests.py reviewboard/site/middleware.py
'get_object_or_404' imported but unused
'LocalSite' imported but unused
'templatetags' imported but unused
Add a lazy, cacheable request.local_site attribute.
Review Request #8166 — Created May 16, 2016 and submitted
The way our Local Site storage has worked in the past is that the URL patterns would capture the Local Site's name, and the decorators for views would turn that into a LocalSite object, passing it to the view. This worked pretty well, but if other code needed access to the LocalSite and only had the request, they'd have to refetch it based on a private attribute on the request. This change adds a public attribute on the request containing the LocalSite itself. This attribute is only loaded on demand, the first time it's accessed, and is None if not working with a LocalSite. The decorators and other code can access this without worrying about redundant fetches, and without accessing private attributes. There's minimal impact to the Local Site code here. It's really just a new convenience for code that needs a Local Site from a request (which will be used in the upcoming integrations changes).
Tested various pages with and without a Local Site.
Tested this new attribute through the decorator and also in some new code
that only has access to the request.
Unit tests pass.