moksha/api/widgets/global_resources/widget.py | 49 ++++++++++++++++-
moksha/api/widgets/grid.py | 10 ++-
moksha/api/widgets/moksha.py | 71 --------------------------
moksha/lib/helpers.py | 13 ++++
setup.py | 1
5 files changed, 65 insertions(+), 79 deletions(-)
New commits:
commit c13df0c81e64bb464a6bcd1dec424ff031cb9286
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sun May 24 22:12:20 2009 -0400
Use the new ``when_ready`` method to fix a race-condition in the Grid widget
diff --git a/moksha/api/widgets/grid.py b/moksha/api/widgets/grid.py
index 29f7c09..5b0b879 100644
--- a/moksha/api/widgets/grid.py
+++ b/moksha/api/widgets/grid.py
@@ -14,12 +14,13 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <
http://www.gnu.org/licenses/>.
-from tw.api import JSLink
+import uuid
+import simplejson as json
+
+from tw.api import JSLink, js_callback
from tw.forms import FormField
from tw.jquery.ui_core import jquery_ui_core_js
from tw.jquery import jQuery, jquery_js
-import simplejson as json
-import uuid
jquery_json_js = JSLink(filename='public/javascript/jquery.json.js',
@@ -79,4 +80,5 @@ class Grid(FormField):
d['id'] += "-uuid" + str(uuid.uuid4())
- self.add_call(jQuery("#%s" % d['id']).mokshagrid(grid_d))
+ from moksha.lib.helpers import when_ready
+ self.add_call(when_ready(jQuery("#%s" %
d['id']).mokshagrid(grid_d)))
commit cf5f0634e9e5962d6f43e85b96bfc99814c111f8
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sun May 24 22:11:19 2009 -0400
Add a moksha.lib.helpers.when_ready method.
This method takes a js_function and returns a js_callback that will run
when the document is ready. This is best used in conjunction with the
Widget.add_call method.
diff --git a/moksha/lib/helpers.py b/moksha/lib/helpers.py
index c531dd6..14b3bc4 100644
--- a/moksha/lib/helpers.py
+++ b/moksha/lib/helpers.py
@@ -25,6 +25,7 @@ import re
import os
import logging
+from tw.api import js_callback
from pytz import timezone, utc
from webob import Request
from decorator import decorator
@@ -994,3 +995,15 @@ class DateTimeDisplay(object):
def __str__(self):
return self.datetime.strftime('%Y-%m-%d %H:%M:%S %Z%z')
+
+
+def when_ready(func):
+ """
+ Takes a js_function and returns a js_callback that will run
+ when the document is ready.
+
+ >>> from tw.api import js_function
+ >>> print
when_ready(js_function('jQuery')('foo').bar({'biz':
'baz'}))
+ $(document).ready(function(){jQuery("foo").bar({"biz":
"baz"})});
+ """
+ return js_callback('$(document).ready(function(){' + str(func) +
'});')
commit 0211a0febe6164b646ac61e78c92840aec68a63a
Author: Luke Macken <lmacken(a)redhat.com>
Date: Sun May 24 22:09:12 2009 -0400
Merge the MokshaGlobals widget with the GlobalResourceInjectionWidget.
Having a module called `moksha` was starting to cause problems.
diff --git a/moksha/api/widgets/global_resources/widget.py
b/moksha/api/widgets/global_resources/widget.py
index 8cc518b..f9f1b46 100644
--- a/moksha/api/widgets/global_resources/widget.py
+++ b/moksha/api/widgets/global_resources/widget.py
@@ -17,11 +17,21 @@
import logging
import pkg_resources
-from inspect import isclass
+from tg import config, url
from tw.api import Widget, CSSLink, JSLink
+from tw.jquery import jquery_js
+from paste.deploy.converters import asbool
+from pylons import request
+from inspect import isclass
log = logging.getLogger(__name__)
+moksha_js = JSLink(modname="moksha",
filename='public/javascript/moksha.js',
+ javascript=[jquery_js])
+moksha_extension_points_js = JSLink(modname="moksha", javascript=[moksha_js],
+ filename='public/javascript/moksha.extensions.js')
+
+
class GlobalResourceInjectionWidget(Widget):
"""
This widget will pull in all JSLink, CSSLink, and Widget resources that
@@ -33,16 +43,30 @@ class GlobalResourceInjectionWidget(Widget):
handles this for us, otherwise you can import the `global_resources`
widget from this module and do it yourself.
"""
- javascript = []
+ javascript = [moksha_js]
children = []
css = []
template = """
% for child in c:
${child()}
% endfor
- """
+ <script type="text/javascript">
+ moksha_base_url = "${base_url}";
+ moksha_csrf_token = "${csrf_token}";
+ moksha_userid = "${user_id}";
+ moksha_debug = ${debug};
+ moksha_profile = ${profile};
+ </script>
+ """
engine_name = 'mako'
+ params = ['base_url', 'csrf_token', 'user_id',
'debug', 'profile']
+ base_url = '/'
+ csrf_token = ''
+ user_id = ''
+ debug = 'false'
+ profile = 'false'
+
def __init__(self):
super(GlobalResourceInjectionWidget, self).__init__()
for widget_entry in pkg_resources.iter_entry_points('moksha.global'):
@@ -61,4 +85,23 @@ class GlobalResourceInjectionWidget(Widget):
"either a JSLink or CSSLink." %
widget_entry.name)
+ self.csrf_token_id = config.get('moksha.csrf.token_id',
'_csrf_token')
+ if asbool(config.get('moksha.extensionpoints', False)):
+ self.javascript.append(moksha_extension_points_js)
+
+ def update_params(self, d):
+ super(GlobalResourceInjectionWidget, self).update_params(d)
+
+ d['base_url'] = url('/')
+
+ if asbool(config.get('debug')):
+ d['debug'] = 'true'
+ if asbool(config['global_conf'].get('profile')):
+ d['profile'] = 'true'
+
+ identity = request.environ.get('repoze.who.identity')
+ if identity:
+ d['csrf_token'] = identity.get(self.csrf_token_id, '')
+ d['user_id'] = identity.get('user_id', '')
+
global_resources = GlobalResourceInjectionWidget()
diff --git a/moksha/api/widgets/moksha.py b/moksha/api/widgets/moksha.py
deleted file mode 100644
index 97ece50..0000000
--- a/moksha/api/widgets/moksha.py
+++ /dev/null
@@ -1,71 +0,0 @@
-# This file is part of Moksha.
-# Copyright (C) 2008-2009 Red Hat, Inc.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program 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 Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <
http://www.gnu.org/licenses/>.
-#
-# Authors: John (J5) Palmieri <johnp(a)redhat.com>
-
-import tg
-import pylons
-
-from tw.api import JSLink
-from tw.api import Widget
-from tw.jquery import jquery_js
-from paste.deploy.converters import asbool
-
-moksha_js = JSLink(modname="moksha",
filename='public/javascript/moksha.js',
- javascript=[jquery_js])
-moksha_extension_points_js = JSLink(modname="moksha",
-
filename='public/javascript/moksha.extensions.js',
- javascript=[moksha_js])
-
-class MokshaGlobals(Widget):
- javascript = [moksha_js]
- template = """<script type="text/javascript">
-moksha_base_url = "${base_url}";
-moksha_csrf_token = "${csrf_token}";
-moksha_userid = "${user_id}";
-moksha_debug = ${debug};
-moksha_profile = ${profile};
-</script>
-"""
- params = ['base_url', 'csrf_token', 'user_id',
'debug', 'profile']
- engine_name = 'mako'
-
- base_url = '/'
- csrf_token = ''
- user_id = ''
- debug = 'false'
- profile = 'false'
-
- def __init__(self, *args, **kw):
- super(MokshaGlobals, self).__init__(*args, **kw)
- self.csrf_token_id = tg.config.get('moksha.csrf.token_id',
'_csrf_token')
- if asbool(tg.config.get('moksha.extensionpoints', False)):
- self.javascript.append(moksha_extension_points_js)
-
- def update_params(self, d):
- super(MokshaGlobals, self).update_params(d)
-
- d['base_url'] = tg.url('/')
-
- if asbool(pylons.config.get('debug')):
- d['debug'] = 'true'
- if asbool(pylons.config['global_conf'].get('profile')):
- d['profile'] = 'true'
-
- identity = pylons.request.environ.get('repoze.who.identity')
- if identity:
- d['csrf_token'] = identity.get(self.csrf_token_id, '')
- d['user_id'] = identity.get('user_id', '')
diff --git a/setup.py b/setup.py
index 212b782..6b27c0e 100644
--- a/setup.py
+++ b/setup.py
@@ -103,7 +103,6 @@ setup(
MokshaMessageMetricsWidget = moksha.widgets.metrics:MokshaMessageMetricsWidget
[moksha.global]
- moksha = moksha.api.widgets.moksha:MokshaGlobals
# The pipeline for our live widgets
stomp_js = moksha.api.widgets.stomp:stomp_js