Allow TemplateHook to be selective based on URL name

Review Request #1629 — Created May 31, 2010 and submitted

Information

Djblets
extensions

Reviewers

TemplateHook currently allows extensions to insert templates into our Django app.  So, for example, we have a hook called "base-scripts-post" which inserts templates on the base template.

Now, while creating a TemplateHook, we can supply an optional apply_to list parameter which allows us to specify which view functions should really render the hook.  For example:

TemplateHook(self, "base-scripts-post", "rbstats/rbstats_dlgs.html", ["dashboard"])

Now rbstats_dlgs.html will only be rendered on the dashboard view function.

I'm not entirely sure if my way of finding "func_name" is the way to go.  Open to suggestions.
Manual.
mike_conley
chipx86
  1. 
      
  2. Hmm yeah, I'm not entirely sure what I think of using the function name. I'd key off the URL name actually (as defined in the urls.py files). It's possible for a single function to handle multiple URLs too (in the case of iPhone vs. main UI, for example), and we don't want to have collisions there.
  3. 
      
mike_conley
mike_conley
chipx86
  1. Awesome! Glad you found something that works here.
  2. djblets/extensions/hooks.py (Diff revision 2)
     
     
     
     
    Should be on the same indentation level as the starting """.
  3. djblets/extensions/hooks.py (Diff revision 2)
     
     
    Is there a reason we need to include this here and not at the top of the file?
    1. No - good point.  I'll move it up top.
  4. djblets/extensions/middleware.py (Diff revision 2)
     
     
     
     
    Indentation should match the starting """.
  5. djblets/extensions/middleware.py (Diff revision 2)
     
     
    I'm not sure if we should be stashing it here or elsewhere, but what we do elsewhere is just request._djblets_whatever = value. 
    1. Alright, switched to request._djblets_extensions_kwargs.
  6. 
      
mike_conley
mike_conley
chipx86
  1. Looks fine. I'll commit this when the parent changes go in.
  2. 
      
mike_conley
  1. Patch available here:  http://github.com/mikeconley/djblets/commits/rr1629_selective_template_hook
  2. 
      
mike_conley
Review request changed
chipx86
  1. Committed to extensions as 7e55fd5
  2. 
      
Loading...