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.