Commits

Matthew Schinckel committed 6a6da92

Updated to allow for absolute urls.

Comments (0)

Files changed (2)

 
     {% menu_item "/foo/" "Foo" %}
     {% menu_item "/bar/" "Bar" %}
+    {% menu_item "http://example.com" "Baz" %}
 
 If we were viewing ``/foo/``, this renders to:
 
 
     <a class="active" href="/foo/">Foo</a>
     <a href="/bar/">Bar</a>
+    <a href="http://example.com">Baz</a>
 
 Using the standard template. If you want, you can override the
 ``menus/item.html`` template to change the display format.
 Changes
 -------
 
+1.0.8 - Allow for absolute urls, ie, pointing to another server. We never
+try to validate these for permission to view, it is assumed the user can.
+
 1.0.7 - Change how version number is stored. Include a new li-item.html
 template, and refactor how the template is found. Check func\_code
 exists before accessing it. Refactor some of the handling of paths.

menus/templatetags/menu_item.py

             
         if url.startswith('url:'):
             url = reverse(url[4:])
+        elif url.startswith('http'):
+            pass
         else:
             url = resolve_path(url, context)
         
                 raise template.TemplateSyntaxError("menu_item tag requires 'request' in context")
             return ''
         
+        # If it is an absolute URL, we can shortcut.
+        if url.startswith('http'):
+            self._update_nodelist()
+            return self.nodelist.render(template.context.Context(local))
+        
         request = context['request']
         
         # To find our current url, look in order at these.
         if not can_view:
             return ''
         
+        # Special-case: when the menu-item's url is '/' or text is 'home', then we don't mark
+        # it as active unless it's a complete match.
+        if page_url.startswith(local['url']):
+            if (local['url'] != '/' and local['text'].lower() != 'home') or page_url == local['url']:
+                local['classes'] += " active"
+        
+        self._update_nodelist()
+        new_context = template.context.Context(local)
+        return self.nodelist.render(new_context)
+    
+    def _update_nodelist(self):
         # Now import and render the template.
         file_name = self.template_file
         
             else:
                 t = get_template(file_name)
             self.nodelist = t.nodelist
-        
-        # Special-case: when the menu-item's url is '/' or text is 'home', then we don't mark
-        # it as active unless it's a complete match.
-        if page_url.startswith(local['url']):
-            if (local['url'] != '/' and local['text'].lower() != 'home') or page_url == local['url']:
-                local['classes'] += " active"
-        
-        new_context = template.context.Context(local)
-        return self.nodelist.render(new_context)
-        
+    
     
 def base_menu_item(template="menu/item.html"):
     """