docs/main/GlobalResources.rst | 12 ++++++---- docs/main/Middleware.rst | 2 - moksha/__init__.py | 3 ++ moksha/api/widgets/placeholder.py | 1 moksha/controllers/apps.py | 3 +- moksha/controllers/root.py | 23 ++----------------- moksha/controllers/widgets.py | 44 ++++++++++++++++++++++++++++++++++++++ moksha/middleware/middleware.py | 27 +++++++++++++++++++++-- setup.py | 4 +++ 9 files changed, 91 insertions(+), 28 deletions(-)
New commits: commit e2ecd3148657e19d332c588468292bc3c8e077d7 Author: Luke Macken lmacken@redhat.com Date: Fri Feb 6 17:33:43 2009 -0500
Fix up some missing modules in our new widgets controller, and do some other minor tweaks
diff --git a/moksha/controllers/root.py b/moksha/controllers/root.py index d9ebd48..90dc1a9 100644 --- a/moksha/controllers/root.py +++ b/moksha/controllers/root.py @@ -34,9 +34,6 @@ from moksha.controllers.apps import AppController from moksha.controllers.widgets import WidgetController #from moksha.controllers.secc import AdminController
-from moksha.widgets.container import MokshaContainer -container = MokshaContainer('moksha_container') - # So we can mount the WidgetBrowser as /docs import os os.environ['TW_BROWSER_PREFIX'] = '/docs' @@ -60,7 +57,7 @@ class RootController(BaseController): def index(self): tmpl_context.menu_widget = moksha.menus['default_menu'] tmpl_context.contextual_menu_widget = moksha.menus['contextual_menu'] - return dict(title='Moksha') + return dict(title='[ Moksha ]')
@expose('moksha.templates.login') def login(self, **kw): diff --git a/moksha/controllers/widgets.py b/moksha/controllers/widgets.py index eecc95f..d6db65a 100644 --- a/moksha/controllers/widgets.py +++ b/moksha/controllers/widgets.py @@ -16,8 +16,14 @@ # Copyright 2008, Red Hat, Inc. # Authors: Luke Macken lmacken@redhat.com
-from tg import expose +import moksha + +from tg import expose, tmpl_context + from moksha.lib.base import Controller +from moksha.widgets.container import MokshaContainer + +container = MokshaContainer('moksha_container')
class WidgetController(Controller):
diff --git a/moksha/middleware/middleware.py b/moksha/middleware/middleware.py index 51b8406..d360762 100644 --- a/moksha/middleware/middleware.py +++ b/moksha/middleware/middleware.py @@ -74,7 +74,8 @@ class MokshaMiddleware(object): def __call__(self, environ, start_response): self.register_stomp(environ) request = Request(environ) - if request.path.startswith('/appz'): + if request.path.startswith('/appz/') or request.path.startswith('/widget') or \ + request.path.startswith('/docs/'): response = request.get_response(self.mokshaapp) else: response = request.get_response(self.application)
commit 4a6c7cc248ec29a11e46e48446176b7ab70da3a3 Author: Luke Macken lmacken@redhat.com Date: Fri Feb 6 17:30:19 2009 -0500
Hide the placeholder widget from our widgets menu
diff --git a/moksha/api/widgets/placeholder.py b/moksha/api/widgets/placeholder.py index 656580e..61b3dd8 100644 --- a/moksha/api/widgets/placeholder.py +++ b/moksha/api/widgets/placeholder.py @@ -2,6 +2,7 @@ from tw.api import Widget
class Placeholder(Widget): engine_name = 'mako' + hidden = True template = """ <div class='placeholder'> Moksha application <strong>${appname}</strong> is not registered yet. This is a placeholder
commit 174aa74031d58926e715c00ea9a37f6507fa4ab0 Author: Luke Macken lmacken@redhat.com Date: Fri Feb 6 17:22:42 2009 -0500
Add the ability to plugin and mount WSGI applications.
The MokshaMiddleware loads all WSGI Applications from the `moksha.wsgiapps` entry-point, wraps them in the tg.WSGIAppController, and stores them in the moksha.apps dictionary. This allows us to freely dispatch between TG apps and WSGI applications using the same lookup/dispatch controller.
diff --git a/docs/main/Middleware.rst b/docs/main/Middleware.rst index 5dc27d8..93f9258 100644 --- a/docs/main/Middleware.rst +++ b/docs/main/Middleware.rst @@ -9,7 +9,7 @@ application with a lot of additional functionality as well. This allows you to It currently provides the following functionality
* Sets up the feed storage and cache for widgets - * Handles dispatching moksha applications, which can be any WSGI app + * Handles dispatching moksha applications, which can be any WSGI app or Controller. * Handles dispatching to individual widgets, which are simply `ToscaWidgets http://toscawidgets.org`_ * Sets up `SQLAlchemy` database engines for each application * Initializes applications data models diff --git a/moksha/__init__.py b/moksha/__init__.py index e34a9dd..32da334 100644 --- a/moksha/__init__.py +++ b/moksha/__init__.py @@ -7,6 +7,9 @@ feed_cache = None # All loaded moksha applications apps = None
+# All WSGI applications +wsgiapps = None + # All loaded ToscaWidgets _widgets = None
diff --git a/moksha/controllers/apps.py b/moksha/controllers/apps.py index ee0e58e..cdbf029 100644 --- a/moksha/controllers/apps.py +++ b/moksha/controllers/apps.py @@ -20,11 +20,12 @@ import moksha
from tg import expose from moksha.lib.base import Controller +from moksha.exc import ApplicationNotFound
class AppController(Controller):
@expose() def lookup(self, app, *remainder): if app not in moksha.apps: - raise AppNotFoundException(app) + raise ApplicationNotFound(app) return moksha.apps[app]['controller'], remainder diff --git a/moksha/controllers/root.py b/moksha/controllers/root.py index b3edfbf..d9ebd48 100644 --- a/moksha/controllers/root.py +++ b/moksha/controllers/root.py @@ -41,7 +41,6 @@ container = MokshaContainer('moksha_container') import os os.environ['TW_BROWSER_PREFIX'] = '/docs'
- class RootController(BaseController):
appz = AppController() diff --git a/moksha/middleware/middleware.py b/moksha/middleware/middleware.py index 4d06161..51b8406 100644 --- a/moksha/middleware/middleware.py +++ b/moksha/middleware/middleware.py @@ -23,6 +23,7 @@ import pkg_resources import simplejson as json import urllib
+from tg.controllers import WSGIAppController from webob import Request, Response from shove import Shove from pylons import config @@ -53,7 +54,7 @@ class MokshaMiddleware(object): self.application = application self.mokshaapp = MokshaAppDispatcher()
- moksha.apps = {} # {'app name': tg.TGController} + moksha.apps = {} # {'app name': tg.TGController/tg.WSGIAppController} moksha._widgets = {} # {'widget name': tw.api.Widget} moksha.menus = {} # {'menu name': moksha.api.menus.MokshaMenu} self.engines = {} # {'app name': sqlalchemy.engine.base.Engine} @@ -63,6 +64,7 @@ class MokshaMiddleware(object): self.load_configs() self.load_widgets() self.load_applications() + self.load_wsgi_applications() self.load_models() self.load_menus()
@@ -134,6 +136,26 @@ class MokshaMiddleware(object): except ImportError: pass
+ def load_wsgi_applications(self): + log.info('Loading moksha WSGI applications') + for app_entry in pkg_resources.iter_entry_points('moksha.wsgiapp'): + log.info('Loading %s WSGI application' % app_entry.name) + app_class = app_entry.load() + app_path = app_entry.dist.location + moksha.apps[app_entry.name] = { + 'name': getattr(app_class, 'name', app_entry.name), + 'controller': WSGIAppController(app_class()), + 'path': app_path, + 'model': None, + } + try: + model = __import__('%s.model' % app_entry.name, + globals(), locals(), + [app_entry.name]) + moksha.apps[app_entry.name]['model'] = model + except ImportError: + pass + def load_widgets(self): log.info('Loading moksha widgets') for widget_entry in pkg_resources.iter_entry_points('moksha.widget'): diff --git a/setup.py b/setup.py index c1340c3..7aa603d 100644 --- a/setup.py +++ b/setup.py @@ -56,6 +56,10 @@ setup( #[moksha.consumer] #moksha = moksha.hub.hub:MokshaConsumer
+ #[moksha.wsgiapp] + # Use this entry point to mount WSGI applications, which can then be accessed + # the same as regular apps, through the `/appz/name` url. + [moksha.application] menu = moksha.api.menus.controllers:MokshaMenuController chat = moksha.api.widgets.chat.controllers:ChatController
commit 5c44e0ea4a2c27c94e6c0295f58fec7fcb192d89 Author: Luke Macken lmacken@redhat.com Date: Fri Feb 6 15:36:41 2009 -0500
Update some of the entrypoints in our GlobalResource docs
diff --git a/docs/main/GlobalResources.rst b/docs/main/GlobalResources.rst index d8b0096..8d0c49d 100644 --- a/docs/main/GlobalResources.rst +++ b/docs/main/GlobalResources.rst @@ -4,7 +4,7 @@ Global Resource Injection
Moksha has plugin suport for `Global Resources`, which are just JavaScript or CSS widgets that will get automatically injected in every page by the -:class:`GlobalResourceInjectionWidget` +:class:`GlobalResourceInjectionWidget`.
Moksha will load all `JSLink http://toscawidgets.org/documentation/ToscaWidgets/modules/api.html#jslink`_, @@ -24,10 +24,14 @@ Here is an example of what some global resources look like in Moksha's `setup.py [moksha.global]
jquery = tw.jquery:jquery_js - jquery_ui_core = moksha.widgets.container:ui_core_js - jquery_ui_draggable = moksha.widgets.container:ui_draggable_js - jquery_ui_resizable = moksha.widgets.container:ui_resizable_js + jquery_ui_core = tw.jquery.ui:ui_core_js + jquery_ui_draggable = tw.jquery.ui:ui_draggable_min_js + jquery_ui_resizable = tw.jquery.ui:ui_resizable_min_js + jquery_ui_dialog = tw.jquery.ui:ui_dialog_min_js + jquery_ui_tabs = tw.jquery.ui_tabs:jquery_ui_tabs_js
+ # Enable support for the Blueprint CSS framework & Plugins blueprint_ie_css = moksha.widgets.blueprint:blueprint_ie_css blueprint_screen_css = moksha.widgets.blueprint:blueprint_screen_css blueprint_print_css = moksha.widgets.blueprint:blueprint_print_css + blueprint_fancytype_css = moksha.widgets.blueprint:blueprint_plugin_fancytype_css
commit 39f9402282352643ce3a4995f82e11ee9998c364 Author: Luke Macken lmacken@redhat.com Date: Fri Feb 6 15:25:44 2009 -0500
Pull the widgets method out into it's own WidgetController
diff --git a/moksha/controllers/root.py b/moksha/controllers/root.py index 8d3bbb8..b3edfbf 100644 --- a/moksha/controllers/root.py +++ b/moksha/controllers/root.py @@ -31,6 +31,7 @@ from moksha.lib.base import BaseController from moksha.exc import ApplicationNotFound from moksha.controllers.error import ErrorController from moksha.controllers.apps import AppController +from moksha.controllers.widgets import WidgetController #from moksha.controllers.secc import AdminController
from moksha.widgets.container import MokshaContainer @@ -40,9 +41,11 @@ container = MokshaContainer('moksha_container') import os os.environ['TW_BROWSER_PREFIX'] = '/docs'
+ class RootController(BaseController):
appz = AppController() + widgets = WidgetController() error = ErrorController() #admin = AdminController()
@@ -60,22 +63,6 @@ class RootController(BaseController): tmpl_context.contextual_menu_widget = moksha.menus['contextual_menu'] return dict(title='Moksha')
- @expose('mako:moksha.templates.widget') - def widgets(self, widget, chrome=None, **kw): - options = {} - options.update(kw) - w = moksha._widgets.get(widget) - if not w: - raise WidgetNotFound(widget) - if chrome and getattr(w['widget'], 'visible', True): - tmpl_context.widget = container - options['content'] = w['widget'] - options['title'] = w['name'] - options['id'] = widget + '_container' - else: - tmpl_context.widget = w['widget'] - return dict(options=options) - @expose('moksha.templates.login') def login(self, **kw): came_from = kw.get('came_from', '/') diff --git a/moksha/controllers/widgets.py b/moksha/controllers/widgets.py new file mode 100644 index 0000000..eecc95f --- /dev/null +++ b/moksha/controllers/widgets.py @@ -0,0 +1,38 @@ +# This file is part of Moksha. +# +# Moksha is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Moksha is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Moksha. If not, see http://www.gnu.org/licenses/. +# +# Copyright 2008, Red Hat, Inc. +# Authors: Luke Macken lmacken@redhat.com + +from tg import expose +from moksha.lib.base import Controller + +class WidgetController(Controller): + + @expose('mako:moksha.templates.widget') + def default(self, widget, chrome=None, **kw): + options = {} + options.update(kw) + w = moksha._widgets.get(widget) + if not w: + raise WidgetNotFound(widget) + if chrome and getattr(w['widget'], 'visible', True): + tmpl_context.widget = container + options['content'] = w['widget'] + options['title'] = w['name'] + options['id'] = widget + '_container' + else: + tmpl_context.widget = w['widget'] + return dict(options=options)
moksha-commits@lists.fedorahosted.org