devilry.apps.extjshelpers — ExtJS helpers

TODO: Tutorial and more docs.

Template filters

To use these filters, add the following to your Django template:

{% load extjs %}

Note that the examples below assume that devilry.examiner.restful.RestfulSimplifiedDelivery is available as a template variable as RestfulSimplifiedDelivery. You may use any RESTful class in place of RestfulSimplifiedDelivery.

extjs_model

Simple usage:

// Create a variable with the extjsmodel class definition
var deliverymodel = {{ RestfulSimplifiedDelivery|extjs_model }};

// Often you will rather define a model and use it later with the
// extjs_modelname filter (or a combination of both approaches)
{{ RestfulSimplifiedDelivery|extjs_model }};
var deliverymodelname = {{ RestfulSimplifiedDelivery|extjs_modelname }};
var model = Ext.ModelManager.getModel(deliverymodelname);

Specifying result_fieldgroups and model name suffix:

// Specify result_fieldgroups
{{ RestfulSimplifiedDelivery|extjs_model:"assignment_group,deadline" }};

// ... or specify a name suffix (to make the model name unique)
//     Notice the ;
{{ RestfulSimplifiedDelivery|extjs_model:";MyScope" }};

// ... or specify result_fieldgroups and suffix
{{ RestfulSimplifiedDelivery|extjs_model:"assignment_group,deadline;MyScope" }};

// Note that you can use extjs_modelname to get a suffixed name
{{ RestfulSimplifiedDelivery|extjs_modelname:"MyScope" }};
devilry.apps.extjshelpers.templatetags.extjs.extjs_model(restfulcls, args=None)[source]

Create an extjs model from the given restful class. Uses restfulcls_to_extjsmodel().

Parameters:
  • restfulcls – Forwarded directly to restfulcls_to_extjsmodel().
  • args – A string containing the arguments for restfulcls_to_extjsmodel(). args is split on ";". The first item in the resulting tuple is split on "," and forwarded as result_fieldgroups. If args is empty, result_fieldgroups will be an empty list. The second item in the resulting tuple is forwarded as modelnamesuffix. If args does not contain ";", this modelnamesuffix will be an empty string.

extjs_modelname

var modelname = {{ RestfulSimplifiedDelivery|extjs_modelname }};
devilry.apps.extjshelpers.templatetags.extjs.extjs_modelname(restfulcls, modelnamesuffix='')[source]

Get the name of the extjs model generated by extjs_model() using the same restfulcls.

Uses get_extjs_modelname().

extjs_combobox_model

var comboboxmodel = {{ RestfulSimplifiedDelivery|extjs_combobox_model }};
devilry.apps.extjshelpers.templatetags.extjs.extjs_combobox_model(restfulcls, modelnamesuffix='')[source]

Wrapper for restfulcls_to_extjscomboboxmodel().

extjs_store

var deliverystore = {{ RestfulSimplifiedDelivery|extjs_store }};
devilry.apps.extjshelpers.templatetags.extjs.extjs_store(restfulcls, storeidsuffix='')[source]

Create an extjs store from the given restful class. Uses restfulcls_to_extjsstore().

Parameters:storeidsuffix – Forwarded directly to restfulcls_to_extjsstore().

Low-level API for filters

devilry.apps.extjshelpers.modelintegration.get_extjs_modelname(restfulcls, modelnamesuffix='')[source]

Get the ExtJS model name for the given restful class. Generated from the module name and class name of restfulcls._meta.simplified

Parameters:modelnamesuffix – Suffixed to the generated model name.
devilry.apps.extjshelpers.modelintegration.restfulcls_to_extjsmodel(restfulcls, result_fieldgroups=[], modelnamesuffix='', pretty=False)[source]

Create an extjs model from the given restful class.

Parameters:
  • restfulcls – A class defined using the RESTful API.
  • result_fieldgroupsresult_fieldgroups is added as additional parameters to the proxy, which means that the parameter is forwarded to devilry.simplified.SimplifiedModelApi.search() on the server after passing through validations in the RESTful wrapper.
  • modelnamesuffix – See get_extjs_modelname().
  • pretty – Prettyformat output.
devilry.apps.extjshelpers.modelintegration.export_restfulcls_to_extjsmodel(restfulcls, result_fieldgroups=[], modelnamesuffix='')[source]

Create an extjs model from the given restful class.

Parameters:
devilry.apps.extjshelpers.modelintegration.restfulcls_to_extjscomboboxmodel(restfulcls, modelnamesuffix='')[source]

Shortcut for:

restfulcls_to_extjsmodel(restfulcls,
                         restfulcls._extjsmodelmeta.combobox_fieldgroups,
                         modelnamesuffix)
devilry.apps.extjshelpers.storeintegration.get_extjs_storeid(restfulcls, storeidsuffix='')[source]

Get the ExtJS store id for the given restful class. Generated from the store id and class name of restfulcls._meta.simplified

Parameters:storeidsuffix – This string added to the end of the id.
devilry.apps.extjshelpers.storeintegration.restfulcls_to_extjsstore(restfulcls, integrateModel=False, modelkwargs={}, storeidsuffix='')[source]

Create an extjs store from the given restful class.

Parameters:
  • restfulcls – A class defined using the RESTful API.
  • integrateModel – Make the model a part of the store. Uses Uses restfulcls_to_extjsmodel() with modelkwargs as arguments.
  • modelkwargs – See integrateModel.
  • storeidsuffix – Forwarded to func:get_extjs_storeid to generate the id of the store and to func:devilry.extjshelpers.modelintegration.get_extjs_modelname (as modelnamesuffix) to generate the model name.

Extensions to the RESTful API

See Low level RESTful web service API.

devilry.apps.extjshelpers.extjs_restful_modelapi(cls)

Decorator for RESTful classes.

Checks for, and adds defaults for the extjs specific inner meta class, ExtjsModelMeta.

ExtjsModelMeta can have the following attributes:

combobox_displayfield
When this object is used in a combobox (search, foreign-key, ...), the combobox need a field, displayField, to show after the an item has been selected (when not showing a dropdown). This attribute species a field name in the resultdata from devilry.simplified.SimplifiedModelApi.search() to use as displayField for comboboxes. Defaults to 'id'.
combobox_fieldgroups
Species the result_fieldgroups to send to devilry.simplified.SimplifiedModelApi.search() when querying for data in a combobox (see combobox_displayfield for more details on comboboxes). Defaults to an empty list.
combobox_tpl
Species the Ext.XTemplate (an extjs class) template to use for each item in the combobox dropdown (see combobox_displayfield parameter for more details on comboboxes). Defaults to '{combobox_displayfield}'.