API

djangojs – Main package

Django.js provide better integration of javascript into Django.

djangojs.JQUERY_DEFAULT_VERSION = '2.0.2'

Packaged jQuery version

djangojs.views – Javascript views helpers

This module provide helper views for javascript.

class djangojs.views.JsInitView(**kwargs)[source]

Bases: django.views.generic.base.TemplateView

Render a javascript file containing the URLs mapping and the context as JSON.

class djangojs.views.JsonView(**kwargs)[source]

Bases: django.views.generic.base.View

A views that render JSON.

class djangojs.views.UrlsJsonView(**kwargs)[source]

Bases: djangojs.views.JsonView

Render the URLs as a JSON object.

class djangojs.views.ContextJsonView(**kwargs)[source]

Bases: djangojs.views.JsonView

Render the context as a JSON object.

class djangojs.views.JsTestView(**kwargs)[source]

Bases: django.views.generic.base.TemplateView

Base class for JS tests views

django_js = False

Includes or not Django.js in the test view

jquery = False

Includes or not jQuery in the test view.

js_files = None

A path or a list of path to javascript files to include into the view.

  • Supports glob patterns.
  • Order is kept for rendering.
class djangojs.views.JasmineView(**kwargs)[source]

Bases: djangojs.views.JsTestView

Render a Jasmine test runner.

class djangojs.views.QUnitView(**kwargs)[source]

Bases: djangojs.views.JsTestView

Render a QUnit test runner

theme = u'qunit'

QUnit runner theme.

Should be one of: qunit, gabe, ninja, nv

djangojs.runners – Javascript unittest runners

This module provide Javascript test runners for Django unittest.

class djangojs.runners.JsTestCase(methodName='runTest')[source]

Bases: djangojs.runners.PhantomJsRunner, django.test.testcases.LiveServerTestCase

A PhantomJS suite that run against the Django LiveServerTestCase

url_args = None

an optionnal arguments array to pass to the reverse() function

url_kwargs = None

an optionnal keyword arguments dictionnary to pass to the reverse() function

url_name = None

a mandatory named URL that point to the test runner page

class djangojs.runners.JsFileTestCase(methodName='runTest')[source]

Bases: djangojs.runners.PhantomJsRunner, unittest.case.TestCase

A PhantomJS suite that run against a local html file

filename = None

absolute path to the test runner page

class djangojs.runners.JsTemplateTestCase(methodName='runTest')[source]

Bases: djangojs.runners.JsFileTestCase

A PhantomJS suite that run against a rendered html file but without server.

Note

Template is rendered using a modified static storage that give file:// scheme URLs. To benefits from it, you have to use either the static template tag or one the djangojs template tags.

Warning

Template is not rendered within a request/response dialog. You can’t access the request object and everything that depends on the server.

jquery = False

Includes or not jQuery in the test view. Template has to handle the use_jquery property.

js_files = None

A path or a list of path to javascript files to include into the view.

  • Supports glob patterns.
  • Order is kept for rendering.
template_name = None

absolute path to the test runner page

exception djangojs.runners.JsTestException(message, failures=None)[source]

Bases: exceptions.Exception

An exception raised by Javascript tests.

It display javascript errors into the exception message.

class djangojs.runners.JasmineSuite[source]

Bases: object

A mixin that runs a jasmine test suite with PhantomJs.

class djangojs.runners.QUnitSuite[source]

Bases: object

A mixin that runs a QUnit test suite with PhantomJs.

class djangojs.runners.AbsoluteFileStorage(location=None, base_url=None)[source]

Bases: django.core.files.storage.FileSystemStorage

A storage that give the absolute file scheme URL as URL.

djangojs.utils – Miscellaneous helpers

This modules holds every helpers that does not fit in any standard django modules.

It might be splitted in futur releases.

djangojs.utils.urls_as_dict()[source]

Get the URLs mapping as a dictionnary

djangojs.utils.urls_as_json()[source]

Get the URLs mapping as JSON

class djangojs.utils.ContextSerializer[source]

Bases: object

Serialize the context from requests.

classmethod as_dict(request)[source]

Serialize the context as a dictionnary from a given request.

classmethod as_json(request)[source]

Serialize the context as JSON from a given request.

classmethod handle_user(data, request)[source]

Insert user informations in data

class djangojs.utils.StorageGlobber[source]

Bases: object

Retrieve file list from static file storages.

classmethod glob(files=None)[source]

Glob a pattern or a list of pattern static storage relative(s).

djangojs.tap – Tap format parser

This module provide test runners for JS in Django.

class djangojs.tap.TapParser(yield_class=<class 'djangojs.tap.TapTest'>, debug=False)[source]

Bases: object

A TAP parser class reading from iterable TAP lines.

djangojs.templatetags.js – Javascript template tags

Provide template tags to help with Javascript/Django integration.

class djangojs.templatetags.js.VerbatimNode(text_and_nodes)[source]

Bases: django.template.base.Node

Wrap {% verbatim %} and {% endverbatim %} around a block of javascript template and this will try its best to output the contents with no changes.

{% verbatim %}
    {% trans "Your name is" %} {{first}} {{last}}
{% endverbatim %}
djangojs.templatetags.js.coffee(filename)[source]

A simple shortcut to render a script tag to a static coffeescript file

djangojs.templatetags.js.coffeescript(filename)[source]

A simple shortcut to render a script tag to a static coffeescript file

djangojs.templatetags.js.css(filename)[source]

A simple shortcut to render a link tag to a static CSS file

djangojs.templatetags.js.django_js(context, jquery=True, i18n=True, csrf=True)[source]

Include Django.js javascript library in the page

djangojs.templatetags.js.django_js_init(context, jquery=False, i18n=True, csrf=True)[source]

Include Django.js javascript library initialization in the page

djangojs.templatetags.js.javascript(filename, type=u'text/javascript')[source]

A simple shortcut to render a script tag to a static javascript file

djangojs.templatetags.js.jquery_js(version=None, migrate=False)[source]

A shortcut to render a script tag for the packaged jQuery

djangojs.templatetags.js.js(filename, type=u'text/javascript')[source]

A simple shortcut to render a script tag to a static javascript file

djangojs.templatetags.js.verbatim(parser, token)[source]

Renders verbatim tags

djangojs.templatetags.js.verbatim_tags(parser, token, endtagname)[source]

Javascript templates (jquery, handlebars.js, mustache.js) use constructs like:

{{if condition}} print something{{/if}}

This, of course, completely screws up Django templates, because Django thinks {{ and }} means something.

The following code preserves {{ }} tokens.

This version of verbatim template tag allows you to use tags like url {% url name %}. {% trans “foo” %} or {% csrf_token %} within.

Inspired by:

djangojs.context_processors – Context processors

djangojs.context_processors.booleans(request)[source]

Allow to use booleans in templates.

See: http://stackoverflow.com/questions/4557114/django-custom-template-tag-which-accepts-a-boolean-parameter