Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Thimo Kraemer
KSS
Commits
3cbb7ca0
Commit
3cbb7ca0
authored
Oct 06, 2018
by
Thimo Kraemer
Browse files
Updated kss.py
parent
cb9ff3fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
kss.py
kss.py
+13
-10
No files found.
kss.py
View file @
3cbb7ca0
...
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment