diff mbox

[Branch,~linaro-validation/lava-server/trunk] Rev 211: Improve extension list to support named mapping lookup

Message ID 20110719214058.22172.15751.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

Zygmunt Krynicki July 19, 2011, 9:40 p.m. UTC
------------------------------------------------------------
revno: 211
committer: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
branch nick: trunk
timestamp: Tue 2011-07-19 23:36:43 +0200
message:
  Improve extension list to support named mapping lookup
modified:
  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/extension.py'
--- lava_server/extension.py	2011-07-13 10:59:13 +0000
+++ lava_server/extension.py	2011-07-19 21:36:43 +0000
@@ -172,8 +172,31 @@ 
         """
         List of extensions
         """
+
+        class ExtensionMapping(object):
+            """
+            Class that exposes extensions by application name
+            """
+
+            def __init__(self, extension_list):
+                self._extension_list = extension_list
+
+            def __getattr__(self, attr):
+                for extension in self._extension_list:
+                    if extension.app_name == attr:
+                        return extension
+
+        class ExtensionList(list):
+            """
+            List with an additional property, useful for Django views
+            """
+
+            @property
+            def as_mapping(self):
+                return ExtensionMapping(self)
+
         if self._extensions is None:
-            self._extensions = []
+            self._extensions = ExtensionList()
             for name in self._find_extensions():
                 try:
                     extension = self._load_extension(name)