Author: justi9
Date: 2007-10-12 12:24:51 -0400 (Fri, 12 Oct 2007)
New Revision: 1024
Modified:
mgmt/cumin/python/cumin/page.py
mgmt/cumin/python/wooly/__init__.py
Log:
Moves frame handling to wooly.Page and off of cumin.CuminPage
Modified: mgmt/cumin/python/cumin/page.py
===================================================================
--- mgmt/cumin/python/cumin/page.py 2007-10-12 15:53:43 UTC (rev 1023)
+++ mgmt/cumin/python/cumin/page.py 2007-10-12 16:24:51 UTC (rev 1024)
@@ -33,21 +33,6 @@
def get_default(self, session):
return list()
- class FrameParameter(Parameter):
- def do_marshal(self, frame):
- return frame.path()
-
- def do_unmarshal(self, path):
- return self.app.get_widget(path)
-
- def set_frame(self, session, frame):
- self.frame.set(session, frame)
-
- return frame
-
- def get_frame(self, session):
- return self.frame.get(session)
-
def set_modal(self, session, modal):
self.modal.set(session, modal)
Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py 2007-10-12 15:53:43 UTC (rev 1023)
+++ mgmt/cumin/python/wooly/__init__.py 2007-10-12 16:24:51 UTC (rev 1024)
@@ -160,6 +160,84 @@
def __str__(self):
return "%s '%s'" % (self.__class__.__name__, self.path())
+class Attribute(object):
+ def __init__(self, app, name):
+ self.app = app
+ self.name = name
+ self.widget = None
+ self.default = None
+ self.is_required = True
+
+ def path(self):
+ if not self.widget:
+ raise Exception("Parameter has no widget")
+
+ if not self.widget.parent:
+ return self.name
+ else:
+ path = self.widget.path() + "." + self.name
+
+ return path
+
+ def set_required(self, is_required):
+ self.is_required = is_required
+
+ def validate(self, session):
+ value = self.get(session)
+
+ if value == None and self.is_required:
+ raise Exception("%s not set" % str(self))
+
+ def get(self, session):
+ value = session.get(self.path())
+
+ # Use strict test because empty collections are False
+ if value == None:
+ default = self.get_default(session)
+
+ if default != None:
+ value = self.set(session, default)
+
+ return value
+
+ def add(self, session, value):
+ self.set(session, value)
+
+ def set(self, session, value):
+ return session.set(self.path(), value)
+
+ def get_default(self, session):
+ return self.default
+
+ def set_default(self, default):
+ self.default = default
+
+ def __str__(self):
+ return "%s '%s'" % (self.__class__.__name__, self.path())
+
+class Parameter(Attribute):
+ def __init__(self, app, name):
+ super(Parameter, self).__init__(app, name)
+
+ app.add_parameter(self)
+
+ def marshal(self, object):
+ if object == None:
+ string = ""
+ else:
+ string = self.do_marshal(object)
+
+ return string
+
+ def do_marshal(self, object):
+ return str(object)
+
+ def unmarshal(self, string):
+ return self.do_unmarshal(string)
+
+ def do_unmarshal(self, string):
+ return string
+
class Page(Widget):
xml_content_type = "text/xml"
html_content_type = "text/html"
@@ -170,6 +248,9 @@
def __init__(self, app, name):
super(Page, self).__init__(app, name)
+ self.frame = self.FrameParameter(app, "frame")
+ self.add_parameter(self.frame)
+
def get_last_modified(self, session):
return datetime.utcnow()
@@ -179,6 +260,21 @@
def save_session(self, session):
pass
+ def set_frame(self, session, frame):
+ self.frame.set(session, frame)
+
+ return frame
+
+ def get_frame(self, session):
+ return self.frame.get(session)
+
+ class FrameParameter(Parameter):
+ def do_marshal(self, frame):
+ return frame.path()
+
+ 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)
@@ -269,84 +365,6 @@
def clear_caches(self):
self.cached_css = None
-class Attribute(object):
- def __init__(self, app, name):
- self.app = app
- self.name = name
- self.widget = None
- self.default = None
- self.is_required = True
-
- def path(self):
- if not self.widget:
- raise Exception("Parameter has no widget")
-
- if not self.widget.parent:
- return self.name
- else:
- path = self.widget.path() + "." + self.name
-
- return path
-
- def set_required(self, is_required):
- self.is_required = is_required
-
- def validate(self, session):
- value = self.get(session)
-
- if value == None and self.is_required:
- raise Exception("%s not set" % str(self))
-
- def get(self, session):
- value = session.get(self.path())
-
- # Use strict test because empty collections are False
- if value == None:
- default = self.get_default(session)
-
- if default != None:
- value = self.set(session, default)
-
- return value
-
- def add(self, session, value):
- self.set(session, value)
-
- def set(self, session, value):
- return session.set(self.path(), value)
-
- def get_default(self, session):
- return self.default
-
- def set_default(self, default):
- self.default = default
-
- def __str__(self):
- return "%s '%s'" % (self.__class__.__name__, self.path())
-
-class Parameter(Attribute):
- def __init__(self, app, name):
- super(Parameter, self).__init__(app, name)
-
- app.add_parameter(self)
-
- def marshal(self, object):
- if object == None:
- string = ""
- else:
- string = self.do_marshal(object)
-
- return string
-
- def do_marshal(self, object):
- return str(object)
-
- def unmarshal(self, string):
- return self.do_unmarshal(string)
-
- def do_unmarshal(self, string):
- return string
-
class Session(object):
def __init__(self, app, trunk=None):
self.app = app