Fix linking for localsite URLs and make the usage more seamless.

Review Request #2007 — Created Dec. 16, 2010 and submitted

Information

Review Board
master

Reviewers

Fix linking for localsite URLs and make the usage more seamless.

This implements some tricks to get seamless, easy linking of localsite URLs
when inside a localsite.

First, the URLs have been registered by creating a new urlpatterns entry
that we both add to the main URLs list and add with a s/(name)/ prefix (using
an include). Django, it turns out, allows multiple URLs with the same name,
and it will try each URL with the regular expression and parameters given.
Going this route, we don't trip up the URL parsers by encasing the "s/" in the
optional regex.

That's the first half of the equation. The second is URL resolving.

URL resolving for templates is now very easy and transparent to work with.
We replace/wrap Django's own {% url %} tag. We do this by adding the
localsite app's templatetags as a built-in set of tags, which will actually
override any of Django's own built-in tags.

The new tag wraps Django's tag and attempts to resolve two versions of the
URL: one with the local site name and one without. We get the local_site_name
from the context, which in most cases (when using RequestContext) is provided
by the new localsite context processor, which gets it from the new
LocalSiteMiddleware. LocalSiteMiddleware processes every view and stores
the local_site_name in the request for the context processor to access,
if it's provided in the URL.

This is still missing a couple components. First, reverse() still hasn't
been replaced. The plan there is to provide a new wrapper version that works
like the new {% url %} tag, and then use that everywhere else. Second,
the datagrid code doesn't provide context when linking to an object from a
cell, so that needs to be added to Djblets. These will be done in a
subsequent change.
Added new unit tests that check the new template tag.

Unit tests all pass.

Did some tests by hand. Things seem to work, except for when reverse() or datagrid object linking comes into play.
david
  1. 
      
  2. reviewboard/site/templatetags/localsite.py (Diff revision 1)
     
     
     
     
     
     
     
     
     
     
     
    Why are these commented out?
  3. shouldn't this be "load localsite" ?
  4. reviewboard/templates/base.html (Diff revision 1)
     
     
     
     
     
     
     
     
    Hmm. None of the accounts URLs have local-site rooting. Did you test these?
  5. 
      
chipx86
chipx86
Review request changed
david
  1. Very nice!
    
  2. reviewboard/site/templatetags/localsite.py (Diff revision 3)
     
     
     
    Extra lines?
  3.