Ajax Module¶
The documentation foradmin_kit.ajax
module. 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 acceptstext
where it converts the output to a string and is sent as the response.
-
-
unique
¶ It defaults to
False
, if itsTrue
then 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
run
method and then passes the output toformat_response
method and returns it. This method is executed when theadmin_kit site
figures out theajax_class
based on the request.
-
-
classmethod
generate_key
(cls, key)¶ Generates the key based on the configuration of Ajax Class. If the
unique
attribute is set , it prepends thekey
with the slug form of its class name.This method is called in the
register
function forkey
andajax_class
mapping.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 toUniqueTestAjax
class,unique-test-ajax-key
key should be used inmodels
file.
-
classmethod