def handle(self, *app_labels, **options): compile_output = options.get('compile', 'yes') data = {'dajaxice_js_functions': DajaxiceRequest.get_js_functions(), 'DAJAXICE_URL_PREFIX': DajaxiceRequest.get_media_prefix(), 'DAJAXICE_XMLHTTPREQUEST_JS_IMPORT': DajaxiceRequest.get_xmlhttprequest_js_import(), 'DAJAXICE_JSON2_JS_IMPORT': DajaxiceRequest.get_json2_js_import(), 'DAJAXICE_EXCEPTION': DajaxiceRequest.get_exception_message()} js = render_to_string('dajaxice/dajaxice.core.js', data) if compile_output.lower() == "closure": print self.complie_js_with_closure(js) else: print js
def dajaxice_js_import(context, core_url=None): # We must force this request to add the csrftoken cookie. request = context.get('request', None) if request: get_token(request) else: log.warning("The 'request' object must be accesible within the context. \ You must add 'django.contrib.messages.context_processors.request' \ to your TEMPLATE_CONTEXT_PROCESSORS and render your views\ using a RequestContext.") if not core_url or DajaxiceRequest.get_debug(): core_url = '/%s/dajaxice.core.js' % DajaxiceRequest.get_media_prefix() else: core_url = '%s%s' % (settings.STATIC_URL or '', core_url,) return {'core_url': core_url}
def js_core(request): """ Return the dajax JS code according settings.DAJAXICE_FUNCTIONS registered functions. """ data = { "dajaxice_js_functions": DajaxiceRequest.get_js_functions(), "DAJAXICE_URL_PREFIX": DajaxiceRequest.get_media_prefix(), "DAJAXICE_XMLHTTPREQUEST_JS_IMPORT": DajaxiceRequest.get_xmlhttprequest_js_import(), "DAJAXICE_JSON2_JS_IMPORT": DajaxiceRequest.get_json2_js_import(), "DAJAXICE_EXCEPTION": DajaxiceRequest.get_exception_message(), "DAJAXICE_JS_DOCSTRINGS": DajaxiceRequest.get_js_docstrings(), } return render_to_response("dajaxice/dajaxice.core.js", data, mimetype="text/javascript")
from django.shortcuts import render_to_response from django.views.decorators.cache import cache_control from puzzlaef.dajaxice.core import DajaxiceRequest def dajaxice_request(request, call): """ dajaxice_request Uses DajaxRequest to handle dajax request. Return the apropiate json according app_name and method. """ return DajaxiceRequest(request, call).process() @cache_control(max_age=DajaxiceRequest.get_cache_control()) def js_core(request): """ Return the dajax JS code according settings.DAJAXICE_FUNCTIONS registered functions. """ data = { "dajaxice_js_functions": DajaxiceRequest.get_js_functions(), "DAJAXICE_URL_PREFIX": DajaxiceRequest.get_media_prefix(), "DAJAXICE_XMLHTTPREQUEST_JS_IMPORT": DajaxiceRequest.get_xmlhttprequest_js_import(), "DAJAXICE_JSON2_JS_IMPORT": DajaxiceRequest.get_json2_js_import(), "DAJAXICE_EXCEPTION": DajaxiceRequest.get_exception_message(), "DAJAXICE_JS_DOCSTRINGS": DajaxiceRequest.get_js_docstrings(), } return render_to_response("dajaxice/dajaxice.core.js", data, mimetype="text/javascript")