[rhmessaging-commits] rhmessaging commits: r1411 - in mgmt/cumin/python: wooly and 1 other directory.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Mon Dec 3 10:57:30 EST 2007
Author: justi9
Date: 2007-12-03 10:57:29 -0500 (Mon, 03 Dec 2007)
New Revision: 1411
Modified:
mgmt/cumin/python/cumin/broker.py
mgmt/cumin/python/cumin/brokercluster.py
mgmt/cumin/python/cumin/brokergroup.py
mgmt/cumin/python/cumin/brokerprofile.py
mgmt/cumin/python/cumin/client.py
mgmt/cumin/python/cumin/configproperty.py
mgmt/cumin/python/cumin/exchange.py
mgmt/cumin/python/cumin/measurement.py
mgmt/cumin/python/cumin/queue.py
mgmt/cumin/python/cumin/realm.py
mgmt/cumin/python/cumin/virtualhost.py
mgmt/cumin/python/cumin/widgets.py
mgmt/cumin/python/wooly/widgets.py
Log:
Because sqlobject is a pita, adds a get_item_count hook to ItemSet and
introduces a SQLObjectItemSet that uses it to avoid calling len() on
sqlobject queries.
Modified: mgmt/cumin/python/cumin/broker.py
===================================================================
--- mgmt/cumin/python/cumin/broker.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/broker.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -15,7 +15,7 @@
strings = StringCatalog(__file__)
-class BrokerSetForm(ItemSet, Form):
+class BrokerSetForm(SQLObjectItemSet, Form):
def __init__(self, app, name):
super(BrokerSetForm, self).__init__(app, name)
@@ -36,9 +36,9 @@
def get_title(self, session, model):
return "Brokers %s" % fmt_count(len(model.get_brokers()))
- def get_items(self, session, model):
+ def do_get_items(self, session, model):
start, end = self.paginator.get_bounds(session)
- return list(BrokerRegistration.select()[start:end])
+ return BrokerRegistration.select()[start:end]
def do_process(self, session, model):
if self.submit.get(session):
@@ -322,7 +322,7 @@
if broker:
return "Functional Hosts %s" % fmt_count(len(broker.vhosts))
- def get_items(self, session, broker):
+ def do_get_items(self, session, broker):
broker = broker.broker # Navigate from registration to real broker
if broker:
return sorted_by(broker.vhosts)
@@ -331,7 +331,7 @@
def get_title(self, session, broker):
return "Configuration"
- def get_items(self, session, broker):
+ def do_get_items(self, session, broker):
return broker.properties
def maybe_highlight(self, value, comparedto):
@@ -383,10 +383,10 @@
self.add_child(self.brokers)
def get_title(self, session, model):
- return "Brokers %s" % fmt_count(Broker.select().count())
+ return "Brokers %s" % fmt_count(BrokerRegistration.select().count())
class BrowserBrokers(BrokerSetForm):
- def get_items(self, session, model):
+ def do_get_items(self, session, model):
group = self.parent().group.get(session)
profile = self.parent().profile.get(session)
cluster = self.parent().cluster.get(session)
@@ -394,8 +394,6 @@
brokers = BrokerRegistration.selectBy \
(profile = profile, cluster = cluster)
- brokers = list(brokers)
-
# XXX add group filtering
return brokers
Modified: mgmt/cumin/python/cumin/brokercluster.py
===================================================================
--- mgmt/cumin/python/cumin/brokercluster.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/brokercluster.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -21,7 +21,7 @@
def get_title(self, session, model):
return "Broker Clusters %s" % fmt_count(BrokerCluster.select().count())
- def get_items(self, session, model):
+ def do_get_items(self, session, model):
return list(BrokerCluster.select())
def render_item_link(self, session, cluster):
@@ -97,7 +97,7 @@
def get_title(self, session, cluster):
return "Brokers %s" % fmt_count(len(cluster.brokers))
- def get_items(self, session, cluster):
+ def do_get_items(self, session, cluster):
return cluster.brokers
class ClusterStatsTab(Widget):
Modified: mgmt/cumin/python/cumin/brokergroup.py
===================================================================
--- mgmt/cumin/python/cumin/brokergroup.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/brokergroup.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -19,7 +19,7 @@
self.page().show_broker_group_add(branch)
return branch.marshal()
- def get_items(self, session, model):
+ def do_get_items(self, session, model):
return list(BrokerGroup.select())
def render_item_link(self, session, group):
@@ -90,7 +90,7 @@
def get_title(self, session, group):
return "Brokers %s" % fmt_count(len(group.brokers))
- def get_items(self, session, group):
+ def do_get_items(self, session, group):
return group.brokers
class BrokerGroupForm(CuminForm):
@@ -136,7 +136,7 @@
self.group_name.set(session, group.name)
class BrokerGroupInput(OptionInputSet):
- def get_items(self, session, model):
+ def do_get_items(self, session, model):
return model.get_broker_groups()
def render_item_value(self, session, group):
Modified: mgmt/cumin/python/cumin/brokerprofile.py
===================================================================
--- mgmt/cumin/python/cumin/brokerprofile.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/brokerprofile.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -20,7 +20,7 @@
def get_title(self, session, model):
return "Broker Profiles %s" % fmt_count(BrokerProfile.select().count())
- def get_items(self, session, model):
+ def do_get_items(self, session, model):
return list(BrokerProfile.select())
def render_item_link(self, session, profile):
@@ -68,7 +68,7 @@
return profile.name
class ProfileConfigTab(ConfigPropertySet):
- def get_items(self, session, profile):
+ def do_get_items(self, session, profile):
return sorted_by(profile.properties)
def get_title(self, session, profile):
@@ -81,7 +81,7 @@
def get_title(self, session, profile):
return "Brokers %s" % fmt_count(len(profile.brokers))
- def get_items(self, session, profile):
+ def do_get_items(self, session, profile):
return profile.brokers
def render_item_config_href(self, session, broker):
Modified: mgmt/cumin/python/cumin/client.py
===================================================================
--- mgmt/cumin/python/cumin/client.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/client.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -22,7 +22,7 @@
def render_unit_plural(self, session, vhost):
return self.unit.get(session) == "b" and "Bytes" or "Msgs."
- def get_items(self, session, vhost):
+ def do_get_items(self, session, vhost):
if vhost:
return sorted_by(vhost.clients, "ipAddr")
@@ -155,7 +155,7 @@
def get_title(self, session, client):
return "Sessions %s" % fmt_count(len(client.session_items()))
- def get_items(self, session, client):
+ def do_get_items(self, session, client):
return sorted_by(client.session_items())
def render_item_name(self, session, session_):
Modified: mgmt/cumin/python/cumin/configproperty.py
===================================================================
--- mgmt/cumin/python/cumin/configproperty.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/configproperty.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -6,7 +6,7 @@
from util import *
class ConfigPropertySet(ItemSet):
- def get_items(self, session, model):
+ def do_get_items(self, session, model):
return sorted_by(model.get_config_properties())
def render_item_name(self, session, prop):
Modified: mgmt/cumin/python/cumin/exchange.py
===================================================================
--- mgmt/cumin/python/cumin/exchange.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/exchange.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -20,7 +20,7 @@
self.add_parameter(param)
self.set_parameter(param)
- def get_items(self, session, vhost):
+ def do_get_items(self, session, vhost):
return sorted_by(vhost.exchanges)
def render_item_value(self, session, exchange):
@@ -45,7 +45,7 @@
def render_unit_plural(self, session, vhost):
return self.unit.get(session) == "b" and "Bytes" or "Msgs."
- def get_items(self, session, vhost):
+ def do_get_items(self, session, vhost):
if vhost:
return sorted_by(vhost.exchanges)
@@ -196,7 +196,7 @@
def get_title(self, session, exchange):
return "Queue Bindings %s" % fmt_count(len(exchange.bindings))
- def get_items(self, session, exchange):
+ def do_get_items(self, session, exchange):
return sorted_by(exchange.bindings, "id")
def render_item_href(self, session, binding):
@@ -371,7 +371,7 @@
def get_title(self, session, queue):
return "Producers %s" % fmt_count(len(queue.producers))
- def get_items(self, session, queue):
+ def do_get_items(self, session, queue):
return sorted_by(queue.producers)
def render_item_name(self, session, producer):
Modified: mgmt/cumin/python/cumin/measurement.py
===================================================================
--- mgmt/cumin/python/cumin/measurement.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/measurement.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -22,7 +22,7 @@
self.object = Attribute(app, "object");
self.add_attribute(self.object);
- def get_items(self, session, object):
+ def do_get_items(self, session, object):
stats = list()
cls = self.app.cmodel.get_class(object)
Modified: mgmt/cumin/python/cumin/queue.py
===================================================================
--- mgmt/cumin/python/cumin/queue.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/queue.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -29,7 +29,7 @@
def render_unit_plural(self, session, vhost):
return self.unit.get(session) == "b" and "Bytes" or "Msgs."
- def get_items(self, session, vhost):
+ def do_get_items(self, session, vhost):
if vhost:
return sorted_by(vhost.queues)
@@ -204,7 +204,7 @@
def get_title(self, session, queue):
return "Exchange Bindings %s" % fmt_count(len(queue.bindings))
- def get_items(self, session, queue):
+ def do_get_items(self, session, queue):
return sorted_by(queue.bindings, "id")
def render_item_href(self, session, binding):
@@ -421,7 +421,7 @@
self.process_cancel(session, queue)
class Exchanges(ExchangeInputSet):
- def get_items(self, session, queue):
+ def do_get_items(self, session, queue):
return sorted_by(queue.virtual_host.exchange_items())
class QueueBindingRemove(CuminConfirmForm):
@@ -488,7 +488,7 @@
def get_title(self, session, queue):
return "Consumers" #XXX %s" % fmt_count(len(queue.consumers))
- def get_items(self, session, queue):
+ def do_get_items(self, session, queue):
return list() #XXX sorted_by(queue.consumers)
def render_item_name(self, session, consumer):
Modified: mgmt/cumin/python/cumin/realm.py
===================================================================
--- mgmt/cumin/python/cumin/realm.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/realm.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -13,7 +13,7 @@
def get_title(self, session, vhost):
return "Realms %s" % fmt_count(len(vhost.realm_items()))
- def get_items(self, session, vhost):
+ def do_get_items(self, session, vhost):
return sorted_by(vhost.realm_items())
def render_item_name(self, session, realm):
@@ -27,7 +27,7 @@
self.add_parameter(param)
self.set_parameter(param)
- def get_items(self, session, vhost):
+ def do_get_items(self, session, vhost):
return sorted_by(vhost.realm_items())
# just parked here
Modified: mgmt/cumin/python/cumin/virtualhost.py
===================================================================
--- mgmt/cumin/python/cumin/virtualhost.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/virtualhost.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -16,7 +16,7 @@
return "Functional Hosts %s" % \
fmt_count(len(model.get_virtual_hosts()))
- def get_items(self, session, model):
+ def do_get_items(self, session, model):
return sorted_by(model.get_virtual_hosts())
def render_item_link(self, session, vhost):
Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/cumin/widgets.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -1,4 +1,5 @@
from math import ceil
+from sqlobject.sresults import SelectResults
from wooly import *
from wooly.widgets import *
from wooly.forms import *
@@ -283,7 +284,7 @@
page = self.get(session)
return (self.page_size * page, self.page_size * (page + 1))
- def get_items(self, session, object):
+ def do_get_items(self, session, object):
return range(0, int(ceil(len(object) / float(self.page_size))))
def render_item_class_attr(self, session, page):
@@ -297,3 +298,13 @@
def render_item_content(self, session, page):
return page + 1
+
+class SQLObjectItemSet(ItemSet):
+ def get_item_count(self, session, object):
+ items = self.get_items(session, object)
+
+ if isinstance(items, SelectResults):
+ return items.count()
+ else:
+ return super(SQLObjectItemSet, self).get_item_count \
+ (session, object)
Modified: mgmt/cumin/python/wooly/widgets.py
===================================================================
--- mgmt/cumin/python/wooly/widgets.py 2007-12-03 15:08:14 UTC (rev 1410)
+++ mgmt/cumin/python/wooly/widgets.py 2007-12-03 15:57:29 UTC (rev 1411)
@@ -120,16 +120,31 @@
def __init__(self, app, name):
super(ItemSet, self).__init__(app, name)
+ self.items = Attribute(app, "items")
+ self.add_attribute(self.items)
+
self.item_tmpl = Template(self, "item_html")
+ def get_item_count(self, session, object):
+
+ return len(self.get_items(session, object))
+
def get_items(self, session, object):
- return None
+ items = self.items.get(session)
+ if items is None:
+ items = self.do_get_items(session, object)
+
+ if items is None:
+ items = ()
+
+ return items
+
+ def do_get_items(self, session, object):
+ return ()
+
def do_render(self, session, object):
- # XXX don't do this twice
- items = self.get_items(session, object)
-
- if items:
+ if self.get_item_count(session, object):
html = super(ItemSet, self).do_render(session, object)
else:
html = self.render_none(session, object)
More information about the rhmessaging-commits
mailing list