diff mbox

[Branch,~linaro-validation/lava-server/trunk] Rev 277: Allow applications to export simple menu

Message ID 20111109192615.3833.53387.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Zygmunt Krynicki Nov. 9, 2011, 7:26 p.m. UTC
------------------------------------------------------------
revno: 277
committer: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
branch nick: lava-server
timestamp: Wed 2011-11-09 00:48:55 +0100
message:
  Allow applications to export simple menu
modified:
  lava_server/context_processors.py
  lava_server/extension.py


--
lp:lava-server
https://code.launchpad.net/~linaro-validation/lava-server/trunk

You are subscribed to branch lp:lava-server.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-server/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_server/context_processors.py'
--- lava_server/context_processors.py	2011-10-11 09:20:14 +0000
+++ lava_server/context_processors.py	2011-11-08 23:48:55 +0000
@@ -19,12 +19,28 @@ 
 import versiontools
 
 import lava_server
-from lava_server.extension import loader
+from lava_server.extension import Menu, loader
+from django.core.urlresolvers import reverse
 
 
 def lava(request):
+    menu_list = [
+        Menu("LAVA", reverse('lava.home')),
+    ]
+    for extension in loader.extensions:
+        menu = extension.get_menu()
+        if menu:
+            menu_list.append(menu)
+    menu_list.extend([
+        Menu("Documentation", "http://lava.rtfd.org/"),
+        Menu("API", reverse("lava.api_help"), [
+            Menu("Available Methods", reverse("lava.api_help")),
+            Menu("Authentication Tokens", reverse("linaro_django_xmlrpc.views.tokens")),
+        ])
+    ])
     return {
         'lava': {
+            'menu_list': menu_list, 
             'extension_list': loader.extensions,
             'version': versiontools.format_version(
                 lava_server.__version__, hint=lava_server)}}

=== modified file 'lava_server/extension.py'
--- lava_server/extension.py	2011-10-11 09:58:00 +0000
+++ lava_server/extension.py	2011-11-08 23:48:55 +0000
@@ -92,6 +92,23 @@ 
         Absolute URL of the main view
         """
 
+    @abstractmethod
+    def get_menu(self):
+        """
+        Return a Menu object
+        """
+
+
+class Menu(object):
+    """
+    Menu (for navigation)
+    """
+    
+    def __init__(self, label, url, sub_menu=None):
+        self.label = label
+        self.url = url
+        self.sub_menu = sub_menu or []
+
 
 class LavaServerExtension(ILavaServerExtension):
     """
@@ -115,6 +132,10 @@ 
         Name of the main view
         """
 
+    def get_menu(self):
+        from django.core.urlresolvers import reverse
+        return Menu(self.name, reverse(self.main_view_name))
+
     @property
     def front_page_template(self):
         return None