Ajax Module¶
The documentation foradmin_kit.ajaxmodule. The module has only one classAjax. So we will go through its attributes , methods and their functionality.
Attributes¶
-
response_type¶ The response type of the ajax class. Its defaults to
json, where its jsonifies the output python object. It also acceptstextwhere it converts the output to a string and is sent as the response.
-
-
unique¶ It defaults to
False, if itsTruethen the key will be unique to a class. Hence different Ajax classes with the same key can be registered.
-
Methods¶
-
run(self, request)¶ The main method that will be executed for generating response for an Ajax request. This is method should be overided by the child class.
-
Note
The remainder methods are internal. So should be overrided only if necessary.
-
route(self, request)¶ This is the core function, that calls
runmethod and then passes the output toformat_responsemethod and returns it. This method is executed when theadmin_kit sitefigures out theajax_classbased on the request.
-
-
classmethod
generate_key(cls, key)¶ Generates the key based on the configuration of Ajax Class. If the
uniqueattribute is set , it prepends thekeywith the slug form of its class name.This method is called in the
registerfunction forkeyandajax_classmapping.Example
# ajax.py from admin_kit import ajax class TestAjax(ajax.Ajax): ... class UniqueTestAjax(ajax.Ajax): unique = True ... TestAjax.generate_key('key') # `key` UniqueTestAjax.generate_key('key') # `unique-test-ajax-key`
To access this Ajax class in
models, Its slugged key name has to be used. In the above Example to map toUniqueTestAjaxclass,unique-test-ajax-keykey should be used inmodelsfile.
-
classmethod