Author: justi9
Date: 2007-10-13 11:48:25 -0400 (Sat, 13 Oct 2007)
New Revision: 1041
Modified:
mgmt/cumin/python/cumin/page.py
mgmt/cumin/python/cumin/widgets.py
mgmt/cumin/python/wooly/__init__.py
Log:
Makes Page into a Frame. Renames get/set_frame to
get/set_current_frame. Fixes a bug in widget.ancestors()
Modified: mgmt/cumin/python/cumin/page.py
===================================================================
--- mgmt/cumin/python/cumin/page.py 2007-10-13 14:53:01 UTC (rev 1040)
+++ mgmt/cumin/python/cumin/page.py 2007-10-13 15:48:25 UTC (rev 1041)
@@ -46,15 +46,15 @@
else:
frame = self.main.show_server(session, server)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def show_server_group(self, session, sgroup):
frame = self.main.show_server_group(session, sgroup)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def show_cluster(self, session, cluster):
frame = self.main.show_cluster(session, cluster)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def show_virtual_host(self, session, vhost):
server = vhost.get_server()
@@ -68,17 +68,17 @@
frame = self.main
frame = frame.show_virtual_host(session, vhost)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def show_queue(self, session, queue):
frame = self.show_virtual_host(session, queue.virtual_host)
frame = frame.show_queue(session, queue)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def show_exchange(self, session, exchange):
frame = self.show_virtual_host(session, exchange.virtual_host)
frame = frame.show_exchange(session, exchange)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def render_title(self, session, object):
return "Cumin"
Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py 2007-10-13 14:53:01 UTC (rev 1040)
+++ mgmt/cumin/python/cumin/widgets.py 2007-10-13 15:48:25 UTC (rev 1041)
@@ -25,7 +25,7 @@
def render_href(self, session, vhost):
branch = session.branch()
- self.page().set_frame(branch, self)
+ self.page().set_current_frame(branch, self)
self.show_view(branch)
return branch.marshal()
Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py 2007-10-13 14:53:01 UTC (rev 1040)
+++ mgmt/cumin/python/wooly/__init__.py 2007-10-13 15:48:25 UTC (rev 1041)
@@ -35,7 +35,8 @@
self.cached_ancestors = tuple()
else:
ancs = list(self.parent.ancestors())
- ancs.append(self)
+ ancs.append(self.parent)
+
self.cached_ancestors = tuple(ancs)
return self.cached_ancestors
@@ -161,7 +162,7 @@
writer = Writer()
for child in self.children:
- writer.write(child.render(session, object))
+ writer.write(child.render(session, object))
return writer.to_string()
@@ -246,7 +247,34 @@
def do_unmarshal(self, string):
return string
-class Page(Widget):
+class Frame(Widget):
+ def __init__(self, app, name):
+ super(Frame, self).__init__(app, name)
+
+ self.object = None
+
+ def set_object_attribute(self, attribute):
+ self.object = attribute
+
+ def get_object(self, session):
+ if self.object:
+ return self.object.get(session)
+
+ def get_saved_parameters(self, session):
+ frame = self.page().get_current_frame(session)
+
+ if self is frame or self in frame.ancestors():
+ return super(Frame, self).get_saved_parameters(session)
+
+ def do_process(self, session, object):
+ new_object = self.get_object(session)
+ super(Frame, self).do_process(session, new_object)
+
+ def do_render(self, session, object):
+ new_object = self.get_object(session)
+ return super(Frame, self).do_render(session, new_object)
+
+class Page(Frame):
xml_content_type = "text/xml"
html_content_type = "text/html"
xml_1_0_declaration = """<?xml
version="1.0"?>"""
@@ -257,6 +285,7 @@
super(Page, self).__init__(app, name)
self.frame = self.FrameParameter(app, "frame")
+ self.frame.set_default(self)
self.add_parameter(self.frame)
self.cached_parameters = dict()
@@ -270,26 +299,23 @@
def save_session(self, session):
pass
- def set_frame(self, session, frame):
+ def set_current_frame(self, session, frame):
self.frame.set(session, frame)
return frame
- def get_frame(self, session):
+ def get_current_frame(self, session):
return self.frame.get(session)
def get_saved_parameters(self, session):
- frame = self.get_frame(session)
+ frame = self.get_current_frame(session)
- if frame:
- if frame not in self.cached_parameters:
- params = super(Page, self).get_saved_parameters(session)
- self.cached_parameters[frame] = params
+ if frame not in self.cached_parameters:
+ params = super(Page, self).get_saved_parameters(session)
+ self.cached_parameters[frame] = params
+
+ return self.cached_parameters[frame]
- return self.cached_parameters[frame]
- else:
- return super(Page, self).get_saved_parameters(session)
-
class FrameParameter(Parameter):
def do_marshal(self, frame):
return frame.path()
@@ -297,33 +323,6 @@
def do_unmarshal(self, path):
return self.app.get_widget(path)
-class Frame(Widget):
- def __init__(self, app, name):
- super(Frame, self).__init__(app, name)
-
- self.object = None
-
- def set_object_attribute(self, attribute):
- self.object = attribute
-
- def get_object(self, session):
- if self.object:
- return self.object.get(session)
-
- def get_saved_parameters(self, session):
- frame = self.page().get_frame(session)
-
- if not frame or self is frame or self in frame.ancestors():
- return super(Frame, self).get_saved_parameters(session)
-
- def do_process(self, session, object):
- new_object = self.get_object(session)
- super(Frame, self).do_process(session, new_object)
-
- def do_render(self, session, object):
- new_object = self.get_object(session)
- return super(Frame, self).do_render(session, new_object)
-
class Application(object):
def __init__(self):
self.pages = dict()
@@ -488,8 +487,14 @@
self.saved_parameters.extend(params)
def marshal(self):
- url = self.marshal_page() + "?" + self.marshal_url_vars()
+ page = self.marshal_page()
+ vars = self.marshal_url_vars()
+ if vars:
+ url = page + "?" + vars
+ else:
+ url = page
+
if self.debug:
self.app.debug.urls.add(url)
@@ -500,21 +505,23 @@
def marshal_url_vars(self, separator=";"):
params = self.get_page().get_saved_parameters(self)
- vars = list()
- for param in params:
- key = param.path()
- value = self.get(key)
- default = param.get_default(self)
+ if params:
+ vars = list()
- if value not in (default, None):
- skey = quote_plus(key)
- svalue = quote_plus(param.marshal(value))
+ for param in params:
+ key = param.path()
+ value = self.get(key)
+ default = param.get_default(self)
- vars.append("%s=%s" % (skey, svalue))
+ if value not in (default, None):
+ skey = quote_plus(key)
+ svalue = quote_plus(param.marshal(value))
- return separator.join(vars)
+ vars.append("%s=%s" % (skey, svalue))
+ return separator.join(vars)
+
def unmarshal(self, string):
if string.startswith("/"):
raise Exception("Illegal session string '" + string +
"'")