Author: justi9
Date: 2009-11-09 15:52:45 -0500 (Mon, 09 Nov 2009)
New Revision: 3705
Modified:
mgmt/trunk/cumin/python/cumin/grid/limit.py
mgmt/trunk/cumin/python/cumin/widgets.strings
mgmt/trunk/wooly/python/wooly/profile.py
mgmt/trunk/wooly/python/wooly/server.py
Log:
* Improve the app error output
* Fix the presentation of CuminItemTable, and use it for LimitSet
Modified: mgmt/trunk/cumin/python/cumin/grid/limit.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/limit.py 2009-11-09 19:51:58 UTC (rev 3704)
+++ mgmt/trunk/cumin/python/cumin/grid/limit.py 2009-11-09 20:52:45 UTC (rev 3705)
@@ -16,14 +16,34 @@
strings = StringCatalog(__file__)
log = logging.getLogger("cumin.limit")
-class LimitSet(ItemTable):
+class LimitDataSet(object):
+ def __init__(self, app, negotiator):
+ self.app = app
+ self.negotiator = negotiator
+
+ def get_items(self, session):
+ negotiator = self.negotiator.get(session)
+
+ limits = self.app.model.get_negotiator_limits(negotiator)
+
+ if limits is None:
+ return ()
+
+ keys = limits.keys()
+ keys.sort()
+
+ return [{"name": x,
+ "curr": limits[x]["CURRENT"],
+ "max": limits[x]["MAX"]}
+ for x in keys]
+
+class LimitSet(CuminItemTable):
def __init__(self, app, name, negotiator):
super(LimitSet, self).__init__(app, name)
- self.negotiator = negotiator
+ self.data = LimitDataSet(app, negotiator)
self.defer_enabled = True
- self.update_enabled = True
col = self.NameColumn(app, "name")
self.add_column(col)
@@ -41,21 +61,8 @@
self.add_child(self.limit_count)
def do_get_items(self, session):
- negotiator = self.negotiator.get(session)
+ return self.data.get_items(session)
- limits = self.app.model.get_negotiator_limits(negotiator)
-
- if limits is None:
- return ()
-
- keys = limits.keys()
- keys.sort()
-
- return [{"name": x,
- "curr": limits[x]["CURRENT"],
- "max": limits[x]["MAX"]}
- for x in keys]
-
def render_title(self, session):
return self.limit_count.render(session)
@@ -74,9 +81,9 @@
return "Name"
def render_content(self, session, data):
- limit = Identifiable(data["name"])
+ limit = data["name"]
href = self.frame.limit.get_href(session, limit)
- return fmt_link(href, data["name"])
+ return fmt_link(href, limit)
class CurrentColumn(ItemTableColumn):
def render_title(self, session, data):
@@ -94,7 +101,7 @@
def __init__(self, app, name, negotiator):
super(LimitFrame, self).__init__(app, name)
- self.object = Parameter(app, "limit")
+ self.object = Parameter(app, "name")
self.add_parameter(self.object)
self.view = LimitView(app, "view", negotiator, self.object)
Modified: mgmt/trunk/cumin/python/cumin/widgets.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.strings 2009-11-09 19:51:58 UTC (rev 3704)
+++ mgmt/trunk/cumin/python/cumin/widgets.strings 2009-11-09 20:52:45 UTC (rev 3705)
@@ -637,6 +637,26 @@
</form>
</div>
+[CuminItemTable.html]
+<div id="{id}" class="CuminTable">
+ <table class="mobjects">
+ {columns}
+ <thead>
+ <tr>
+ <th class="setnav" colspan="{column_count}">
+ <div class="rfloat">{page}</div>
+
+ {count}
+ </th>
+ </tr>
+
+ <tr>{headers}</tr>
+ </thead>
+
+ <tbody>{items}</tbody>
+ </table>
+</div>
+
[TableHeader.css]
th.selected a {
color: black;
Modified: mgmt/trunk/wooly/python/wooly/profile.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/profile.py 2009-11-09 19:51:58 UTC (rev 3704)
+++ mgmt/trunk/wooly/python/wooly/profile.py 2009-11-09 20:52:45 UTC (rev 3705)
@@ -1,3 +1,5 @@
+import sys
+
from time import time
from collections import defaultdict
@@ -60,9 +62,9 @@
for widget in rendered.difference(processed):
print "Warning: %s was rendered but not processed" % widget
- def print_stack_trace(self):
+ def print_stack_trace(self, writer=sys.stdout):
for call in self.current_calls:
- print "in %s" % call
+ writer.write(" in %s\n" % call)
def print_process_calls(self):
if self.process_calls:
Modified: mgmt/trunk/wooly/python/wooly/server.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/server.py 2009-11-09 19:51:58 UTC (rev 3704)
+++ mgmt/trunk/wooly/python/wooly/server.py 2009-11-09 20:52:45 UTC (rev 3705)
@@ -108,8 +108,31 @@
content = page.render(session)
except:
- return self.send_error(response, headers)
+ headers.append(("Content-Type", "text/plain"))
+ response("500 Internal Error", headers)
+
+ writer = Writer()
+ writer.write("APPLICATION ERROR\n\n")
+
+ print_exc(None, writer)
+
+ writer.write("\n")
+
+ profile = page.profile.get(session)
+
+ if profile:
+ writer.write("Widget trace:\n\n")
+
+ profile.print_stack_trace(writer)
+ writer.write("\n")
+
+ self.print_url_vars(env["QUERY_STRING"], writer)
+ self.print_session(session, writer)
+ self.print_environment(env, writer)
+
+ return writer.to_string()
+
headers.append(("Content-Length", str(len(content))))
self.adapt_session_to_response(page, session, headers)
@@ -118,6 +141,37 @@
return (content,)
+ def print_url_vars(self, query, writer):
+ writer.write("URL variables:\n\n")
+
+ vars = query.split(";")
+
+ for var in sorted(vars):
+ key, value = var.split("=")
+ writer.write(" %-30s %s\n" % (key, value))
+
+ writer.write("\n")
+
+ def print_session(self, session, writer):
+ writer.write("Session:\n\n")
+
+ for path in sorted(session.values_by_path):
+ value = session.values_by_path[path]
+
+ writer.write(" %-30s %s\n" % (path, value))
+
+ writer.write("\n")
+
+ def print_environment(self, env, writer):
+ writer.write("Environment:\n\n")
+
+ for key in sorted(env):
+ value = env[key]
+
+ writer.write(" %-30s %s\n" % (key, value))
+
+ writer.write("\n")
+
def adapt_request_to_session(self, env, session):
session.unmarshal_url_vars(env["QUERY_STRING"])
@@ -196,18 +250,6 @@
return ()
- def send_error(self, response, headers):
- headers.append(("Content-Type", "text/plain"))
-
- response("500 Internal Error", headers)
-
- writer = Writer()
- writer.write("APPLICATION ERROR\n\n")
-
- print_exc(None, writer)
-
- return writer.to_string()
-
class ClientSessionExpireThread(Thread):
def __init__(self, server):
super(ClientSessionExpireThread, self).__init__()