Add a lazy, cacheable request.local_site attribute.

Review Request #8166 — Created May 16, 2016 and submitted

Information

Review Board
release-3.0.x

Reviewers

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.

Description From Last Updated

'get_object_or_404' imported but unused

reviewbotreviewbot

'LocalSite' imported but unused

reviewbotreviewbot

undefined name 'Http404'

reviewbotreviewbot

undefined name 'Http404'

reviewbotreviewbot

'templatetags' imported but unused

reviewbotreviewbot

'templatetags' imported but unused

reviewbotreviewbot
reviewbot
  1. 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
    
    
  2. reviewboard/site/decorators.py (Diff revision 1)
     
     
    Show all issues
     'get_object_or_404' imported but unused
    
  3. reviewboard/site/decorators.py (Diff revision 1)
     
     
    Show all issues
     'LocalSite' imported but unused
    
  4. reviewboard/site/decorators.py (Diff revision 1)
     
     
    Show all issues
     undefined name 'Http404'
    
  5. reviewboard/site/decorators.py (Diff revision 1)
     
     
    Show all issues
     undefined name 'Http404'
    
  6. reviewboard/site/tests.py (Diff revision 1)
     
     
    Show all issues
     'templatetags' imported but unused
    
  7. 
      
chipx86
reviewbot
  1. 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
    
    
  2. reviewboard/site/tests.py (Diff revision 2)
     
     
    Show all issues
     'templatetags' imported but unused
    
  3. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-3.0.x (15668a3)
Loading...