Prepare all views for a new modular approach to JS loading
Patch by: Sverre Rabbelier
--- a/app/soc/views/helper/params.py Sun Feb 15 20:25:35 2009 +0000
+++ b/app/soc/views/helper/params.py Sun Feb 15 20:26:15 2009 +0000
@@ -47,6 +47,23 @@
DEF_SUBMIT_MSG_PROFILE_SAVED = 0
+# list with all js scripts used for documentary purposes
+DEF_JS_USES_LIST = [
+ 'jq',
+ 'jq_ajaqQueue',
+ 'jq_autocomplete',
+ 'jq_bgiframe',
+ 'jq_bt',
+ 'jq_datetimepicker',
+ 'jq_progressbar',
+ 'jq_thickbox',
+ 'jq_ui_core',
+ 'menu',
+ 'orgaccept',
+ 'tinymce',
+ ]
+
+
def constructParams(params):
"""Constructs a new params dictionary based on params.
@@ -187,6 +204,13 @@
new_params['export_content_type'] = None
+ # TODO: Use only the js modules needed instead of js_uses_all
+ new_params['js_uses_all'] = DEF_JS_USES_LIST
+ new_params['js_uses_list'] = ['jq', 'menu']
+ new_params['js_uses_show'] = ['jq', 'menu']
+ new_params['js_uses_edit'] = ['jq', 'menu', 'tinymce', 'jq_bt',
+ 'jq_autocomplete']
+
new_params['error_public'] = 'soc/%(module_name)s/error.html' % params
new_params['error_export'] = new_params['error_public']
new_params['error_edit'] = new_params['error_public']
--- a/app/soc/views/helper/responses.py Sun Feb 15 20:25:35 2009 +0000
+++ b/app/soc/views/helper/responses.py Sun Feb 15 20:26:15 2009 +0000
@@ -120,7 +120,7 @@
context['gae_version'] = system.getAppVersion()
settings = site.logic.getSingleton()
-
+
if settings:
context['ga_tracking_num'] = settings.ga_tracking_num
context['gmaps_api_key'] = settings.gmaps_api_key
@@ -128,6 +128,12 @@
return context
+def useJavaScript(context, uses):
+ """Updates the context for JavaScript usage.
+ """
+
+ for use in uses:
+ context['uses_%s' % use] = True
def redirectToChangedSuffix(
request, old_suffix, new_suffix=None, params=None):
--- a/app/soc/views/models/base.py Sun Feb 15 20:25:35 2009 +0000
+++ b/app/soc/views/models/base.py Sun Feb 15 20:26:15 2009 +0000
@@ -41,7 +41,6 @@
import soc.logic
import soc.logic.lists
import soc.views.helper.lists
-import soc.views.helper.responses
import soc.views.helper.params
@@ -103,6 +102,7 @@
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
+ helper.responses.useJavaScript(context, params['js_uses_all'])
context['page_name'] = page_name
entity = None
@@ -151,6 +151,7 @@
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
+ helper.responses.useJavaScript(context, params['js_uses_all'])
context['page_name'] = page_name
try:
@@ -200,6 +201,7 @@
# create default template context for use with any templates
context = helper.responses.getUniversalContext(request)
+ helper.responses.useJavaScript(context, params['js_uses_all'])
context['page_name'] = page_name
entity = None
@@ -294,6 +296,7 @@
"""
context = helper.responses.getUniversalContext(request)
+ helper.responses.useJavaScript(context, params['js_uses_all'])
context['page_name'] = page_name
entity = None
@@ -487,6 +490,7 @@
context = dicts.merge(context,
helper.responses.getUniversalContext(request))
+ helper.responses.useJavaScript(context, params['js_uses_all'])
context['page_name'] = page_name
context['list'] = soc.logic.lists.Lists(contents)
@@ -523,11 +527,6 @@
redirect to after having successfully deleted the entity.
"""
- # create default template context for use with any templates
- context = helper.responses.getUniversalContext(request)
- context['page_name'] = page_name
- entity = None
-
try:
entity = self._logic.getFromKeyFieldsOr404(kwargs)
except out_of_band.Error, error:
@@ -537,11 +536,7 @@
'entity_type' : params['name'],
'create' : params['missing_redirect']})
return helper.responses.errorResponse(
- error, request, template=params['error_edit'], context=context)
-
- if not entity:
- #TODO: Create a proper error page for this
- return http.HttpResponseRedirect('/')
+ error, request, template=params['error_edit'])
if not self._logic.isDeletable(entity):
# TODO: Update the notice area telling the user that they
--- a/app/soc/views/models/group.py Sun Feb 15 20:25:35 2009 +0000
+++ b/app/soc/views/models/group.py Sun Feb 15 20:26:15 2009 +0000
@@ -133,6 +133,7 @@
# get the context for this webpage
context = responses.getUniversalContext(request)
+ helper.responses.useJavaScript(context, params['js_uses_all'])
context['page_name'] = page_name
if request.method == 'POST':
--- a/app/soc/views/models/group_app.py Sun Feb 15 20:25:35 2009 +0000
+++ b/app/soc/views/models/group_app.py Sun Feb 15 20:26:15 2009 +0000
@@ -240,11 +240,6 @@
For params see base.View.public().
"""
- # create default template context for use with any templates
- context = responses.getUniversalContext(request)
- context['page_name'] = page_name
- entity = None
-
try:
entity = self._logic.getFromKeyFieldsOr404(kwargs)
except out_of_band.Error, error:
--- a/app/soc/views/models/request.py Sun Feb 15 20:25:35 2009 +0000
+++ b/app/soc/views/models/request.py Sun Feb 15 20:26:15 2009 +0000
@@ -144,7 +144,8 @@
# get the context for this webpage
context = responses.getUniversalContext(request)
-
+ helper.responses.useJavaScript(context, params['js_uses_all'])
+
request_logic = params['logic']
# get the request entity using the information from kwargs
--- a/app/soc/views/models/role.py Sun Feb 15 20:25:35 2009 +0000
+++ b/app/soc/views/models/role.py Sun Feb 15 20:26:15 2009 +0000
@@ -128,6 +128,7 @@
new_params['extra_django_patterns'] = patterns
new_params['scope_redirect'] = redirects.getInviteRedirect
+
new_params['create_template'] = 'soc/role/edit.html'
new_params['edit_template'] = 'soc/role/edit.html'
@@ -169,6 +170,7 @@
# get the context for this webpage
context = responses.getUniversalContext(request)
+ responses.useJavaScript(context, params['js_uses_all'])
context['page_name'] = page_name
context['instruction_message'] = (self.DEF_INVITE_INSTRUCTION_MSG_FMT %
params)
@@ -296,6 +298,7 @@
# get the context for this webpage
context = responses.getUniversalContext(request)
+ responses.useJavaScript(context, params['js_uses_all'])
context['page_name'] = page_name
if request.method == 'POST':
@@ -399,6 +402,7 @@
# get the context for this webpage
context = responses.getUniversalContext(request)
+ responses.useJavaScript(context, params['js_uses_all'])
context['page_name'] = page_name
logic = params['logic']
@@ -452,6 +456,7 @@
# get the context for this webpage
context = responses.getUniversalContext(request)
+ responses.useJavaScript(context, params['js_uses_all'])
context['page_name'] = page_name
context['instruction_message'] = (self.DEF_REQUEST_INSTRUCTION_MSG_FMT %
params)
@@ -557,6 +562,7 @@
# get the context for this webpage
context = responses.getUniversalContext(request)
+ responses.useJavaScript(context, params['js_uses_all'])
context['page_name'] = page_name
# get the request entity using the information from kwargs