summaryrefslogtreecommitdiffstats
path: root/ipa_webui
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-10-06 18:25:57 -0600
committerJason Gerard DeRose <jderose@redhat.com>2008-10-06 18:25:57 -0600
commit3082a5379ac5b5e949e79e4c473a013546ce7b6e (patch)
tree5f5528b0c18f014bae35d30193db883e950d17fd /ipa_webui
parentd38dcb6d39c87e2a35d94e86162a1d870fb1b2bc (diff)
downloadfreeipa-3082a5379ac5b5e949e79e4c473a013546ce7b6e.tar.gz
freeipa-3082a5379ac5b5e949e79e4c473a013546ce7b6e.tar.xz
freeipa-3082a5379ac5b5e949e79e4c473a013546ce7b6e.zip
More work on webui skeleton
Diffstat (limited to 'ipa_webui')
-rw-r--r--ipa_webui/controller.py46
-rw-r--r--ipa_webui/templates/form.kid16
-rw-r--r--ipa_webui/templates/main.kid6
-rw-r--r--ipa_webui/tests/test_controllers.py33
4 files changed, 74 insertions, 27 deletions
diff --git a/ipa_webui/controller.py b/ipa_webui/controller.py
index f0d627ece..a2a270cbd 100644
--- a/ipa_webui/controller.py
+++ b/ipa_webui/controller.py
@@ -20,22 +20,52 @@
Controller classes.
"""
-from ipalib.plugable import ReadOnly
+import simplejson
+from ipalib.plugable import ReadOnly, lock
class Controller(ReadOnly):
- def __init__(self, cmd, template):
- self.cmd = cmd
+ exposed = True
+
+ def __init__(self, template=None):
self.template = template
+ lock(self)
- def serialize(self, **kw):
+ def output_xhtml(self, **kw):
return self.template.serialize(
output='xhtml-strict',
- format='pretty+nice',
+ format='pretty',
**kw
)
+ def output_json(self, **kw):
+ return simplejson.dumps(kw, sort_keys=True, indent=4)
+
def __call__(self, **kw):
- return self.serialize(
- result=self.cmd(**kw),
- )
+ json = bool(kw.pop('_format', None) == 'json')
+ result = self.run(**kw)
+ assert type(result) is dict
+ if json or self.template is None:
+ return self.output_json(**result)
+ return self.output_xhtml(**result)
+
+ def run(self, **kw):
+ return {}
+
+
+class Command(Controller):
+ def __init__(self, command, template=None):
+ self.command = command
+ super(Command, self).__init__(template)
+
+ def run(self, **kw):
+ return dict(command=self.command)
+
+
+class Index(Controller):
+ def __init__(self, api, template=None):
+ self.api = api
+ super(Index, self).__init__(template)
+
+ def run(self):
+ return dict(api=self.api)
diff --git a/ipa_webui/templates/form.kid b/ipa_webui/templates/form.kid
new file mode 100644
index 000000000..640157005
--- /dev/null
+++ b/ipa_webui/templates/form.kid
@@ -0,0 +1,16 @@
+<?xml version='1.0' encoding='utf-8'?>
+<html xmlns:py="http://purl.org/kid/ns#">
+
+<head>
+ <title>Hello</title>
+</head>
+
+<body>
+ <table>
+ <tr py:for="param in command.params()">
+ <td py:content="param.name"/>
+ </tr>
+ </table>
+</body>
+
+</html>
diff --git a/ipa_webui/templates/main.kid b/ipa_webui/templates/main.kid
index 2eee036cf..692f2b575 100644
--- a/ipa_webui/templates/main.kid
+++ b/ipa_webui/templates/main.kid
@@ -2,11 +2,13 @@
<html xmlns:py="http://purl.org/kid/ns#">
<head>
- <title>Hello</title>
+ <title>FreeIPA</title>
</head>
<body>
- <div>Hello</div>
+ <p py:for="name in api.Command">
+ <a href="${name}" py:content="name"/>
+ </p>
</body>
</html>
diff --git a/ipa_webui/tests/test_controllers.py b/ipa_webui/tests/test_controllers.py
index 71e5c0e21..f5944dd9e 100644
--- a/ipa_webui/tests/test_controllers.py
+++ b/ipa_webui/tests/test_controllers.py
@@ -23,6 +23,7 @@ Test the `ipa_webui.controller` module.
from ipa_webui import controller
+
class test_Controller(object):
"""
Test the `controller.Controller` class.
@@ -32,15 +33,15 @@ class test_Controller(object):
"""
Test the `ipa_webui.controller.Controller.__init__()` method.
"""
- cmd = 'The command.'
+ o = controller.Controller()
+ assert o.template is None
template = 'The template.'
- o = controller.Controller(cmd, template)
- assert o.cmd is cmd
+ o = controller.Controller(template)
assert o.template is template
- def test_serialize(self):
+ def test_output_xhtml(self):
"""
- Test the `ipa_webui.controller.Controller.serialize` method.
+ Test the `ipa_webui.controller.Controller.output_xhtml` method.
"""
class Template(object):
def __init__(self):
@@ -52,20 +53,18 @@ class test_Controller(object):
self.kw = kw
return dict(kw)
- d = dict(output='xhtml-strict', format='pretty+nice')
+ d = dict(output='xhtml-strict', format='pretty')
t = Template()
- o = controller.Controller(None, t)
- assert o.serialize() == d
+ o = controller.Controller(t)
+ assert o.output_xhtml() == d
assert t.calls == 1
- def test_call(self):
+ def test_output_json(self):
"""
- Test the `ipa_webui.controller.Controller.__call__` method.
+ Test the `ipa_webui.controller.Controller.output_json` method.
"""
- class Template(object):
- def serialize(self, **kw):
- return 'Your login is %s.' % kw['result']
- def cmd(**kw):
- return kw['first'][0] + kw['last']
- o = controller.Controller(cmd, Template())
- assert o(first='John', last='Doe') == 'Your login is JDoe.'
+ o = controller.Controller()
+ assert o.output_json() == '{}'
+ e = '{\n "age": 27, \n "first": "John", \n "last": "Doe"\n}'
+ j = o.output_json(last='Doe', first='John', age=27)
+ assert j == e