Commit 3cbb7ca0 by Thimo Kraemer

Updated kss.py

parent cb9ff3fa
......@@ -25,32 +25,36 @@
"""
Usage:
// Create a response instance
# Create a response instance
kss = KSSResponse();
// Add a command
# Add a command
kss.add_command('setNodeAttr', '#my-selector',
name='foo',
value='bar',
)
// Or via dynamic method
# Or via dynamic method
kss.setNodeAttr('#my-selector',
name='foo',
value='bar',
)
// Commands that do not require a selector
# Commands that do not require a selector
kss.add_command('alert', message='Hello!')
// Or via dynamic method
# Or via dynamic method
kss.alert(message='Hello!')
// Return the KSS response as JSON
# Return the KSS response as JSON
return str(kss)
// Or return it within an RPC service
# Or return it within an RPC service
return kss.response
# Or from a Django view
return JsonResponse(kss.response, charset='utf-8')
"""
import json
......@@ -60,8 +64,7 @@ __all__ = ['KSSResponse']
class KSSResponse(object):
def __init__(self, encoding='utf-8'):
self.encoding = encoding
def __init__(self):
self.response = {'commands': []}
def add_command(self, _action, _selector=None, **_params):
......@@ -77,4 +80,4 @@ class KSSResponse(object):
return partial(self.add_command, name)
def __str__(self):
return json.dumps(self.response, encoding=self.encoding)
return json.dumps(self.response)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment