[rhmessaging-commits] rhmessaging commits: r4253 - in mgmt/newdata: cumin/python/cumin and 2 other directories.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Fri Sep 3 15:41:53 EDT 2010


Author: eallen
Date: 2010-09-03 15:41:52 -0400 (Fri, 03 Sep 2010)
New Revision: 4253

Modified:
   mgmt/newdata/cumin/model/rosemary.xml
   mgmt/newdata/cumin/python/cumin/messaging/binding.py
   mgmt/newdata/cumin/python/cumin/messaging/exchange.py
   mgmt/newdata/cumin/python/cumin/objectframe.py
   mgmt/newdata/cumin/python/cumin/widgets.py
   mgmt/newdata/rosemary/python/rosemary/model.py
   mgmt/newdata/rosemary/python/rosemary/util.py
Log:
Re-fix BZ 537851: Display "Default exchange" when exchange name is empty string.
Extented rosemary.xml to allow specifying a method to use to format a property for display.

Modified: mgmt/newdata/cumin/model/rosemary.xml
===================================================================
--- mgmt/newdata/cumin/model/rosemary.xml	2010-09-02 22:23:10 UTC (rev 4252)
+++ mgmt/newdata/cumin/model/rosemary.xml	2010-09-03 19:41:52 UTC (rev 4253)
@@ -80,6 +80,7 @@
     <class name="Exchange">
       <property name="name">
         <title>Name</title>
+        <formatter>fmt_exchange_name</formatter>
       </property>
 
       <statistic name="producerCount">

Modified: mgmt/newdata/cumin/python/cumin/messaging/binding.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/binding.py	2010-09-02 22:23:10 UTC (rev 4252)
+++ mgmt/newdata/cumin/python/cumin/messaging/binding.py	2010-09-03 19:41:52 UTC (rev 4253)
@@ -115,6 +115,9 @@
         def render_header_content(self, session):
             return "Exchange"
 
+        def render_cell_content(self, session, record):
+            return record[self.field.index] or "Default exchange"
+
     class Queue(ObjectLinkColumn):
         def render_header_content(self, session):
             return "Queue"
@@ -419,6 +422,8 @@
     def get_exchange(self, session):
         exchange_string = self.exchange.get(session)
         if exchange_string:
+            if exchange_string == "Default exchange":
+                exchange_string = ""
             obj = self.form.object.get(session)
             cls = self.app.model.org_apache_qpid_broker.Exchange
             vhostid = obj._class._name == "Vhost" and obj._id or obj._vhostRef_id
@@ -528,6 +533,8 @@
         if not self.errors.get(session):
             queue = self.queue.get(session)
             exchange = self.exchange.get(session)
+            if exchange == "Default exchange":
+                exchange = ""
             key = self.key.get(session)
             arguments = self.bindings.get(session)
             obj = self.object.get(session)

Modified: mgmt/newdata/cumin/python/cumin/messaging/exchange.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/exchange.py	2010-09-02 22:23:10 UTC (rev 4252)
+++ mgmt/newdata/cumin/python/cumin/messaging/exchange.py	2010-09-03 19:41:52 UTC (rev 4253)
@@ -35,14 +35,6 @@
         self.remove = ExchangeRemove(app, self)
         self.add_binding = ExchangeBindingAdd(app, self)
 
-    def get_title(self, session):
-        title = super(ExchangeFrame, self).get_title(session)
-
-        if title == "":
-            title = "Default exchange"
-
-        return title
-
 class ExchangeRemove(ObjectFrameTask):
     def get_title(self, session):
         return "Remove"
@@ -78,7 +70,7 @@
         self.vhost = vhost
 
         frame = "main.messaging.broker.exchange"
-        col = ObjectLinkColumn(app, "name", cls.name, cls._id, frame)
+        col = self.ExchangeNameColumn(app, "name", cls.name, cls._id, frame)
         self.add_column(col)
 
         self.add_attribute_column(cls.producerCount)
@@ -90,10 +82,17 @@
 
         self.remove = ExchangeSelectionRemove(app, self)
 
+    class ExchangeNameColumn(ObjectLinkColumn):
+        def render_cell_content(self, session, record):
+            return record[self.field.index] or "Default exchange"
+
 class ExchangeSelectionRemove(ObjectSelectorTask):
     def get_title(self, session):
         return "Remove"
 
+    def get_item_content(self, session, item):
+        return item.name or "Default exchange"
+
     def do_invoke(self, invoc, exchange):
         session = self.app.model.get_session_by_object(exchange)
         session.exchange_delete(exchange=exchange.name)

Modified: mgmt/newdata/cumin/python/cumin/objectframe.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/objectframe.py	2010-09-02 22:23:10 UTC (rev 4252)
+++ mgmt/newdata/cumin/python/cumin/objectframe.py	2010-09-03 19:41:52 UTC (rev 4253)
@@ -93,7 +93,7 @@
 
         for attr in self.get_attributes(session):
             name = attr.title
-            value = getattr(obj, attr.name, None)
+            value = obj.get_formatted_value(attr.name)
 
             writer.write(self.entry.render(session, name, value))
     

Modified: mgmt/newdata/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/widgets.py	2010-09-02 22:23:10 UTC (rev 4252)
+++ mgmt/newdata/cumin/python/cumin/widgets.py	2010-09-03 19:41:52 UTC (rev 4253)
@@ -1483,7 +1483,7 @@
     def render_value(self, session):
         if self.disabled:
             field = self.form.object.get(session)
-            return fmt_shorten(field.name, pre=36, post=4)
+            return fmt_shorten(field.get_formatted_value("name"), pre=36, post=4)
         else:
             input_value = self.param.get(session)
             return input_value and input_value or ""

Modified: mgmt/newdata/rosemary/python/rosemary/model.py
===================================================================
--- mgmt/newdata/rosemary/python/rosemary/model.py	2010-09-02 22:23:10 UTC (rev 4252)
+++ mgmt/newdata/rosemary/python/rosemary/model.py	2010-09-03 19:41:52 UTC (rev 4253)
@@ -2,7 +2,7 @@
 from sqlmodel import *
 from sqlquery import *
 from sqltype import *
-from util import *
+import util
 
 log = logging.getLogger("rosemary.model")
 
@@ -506,6 +506,7 @@
         self.index = None
         self.optional = None
         self.unique = None
+        self.formatter = None
 
         self.title = None
         self.description = None
@@ -524,7 +525,13 @@
     def extend(self, elem):
         self.title = elem.findtext("title")
         self.unique = elem.get("unique", "n") == "y" and True
+        formatter = elem.findtext("formatter")
+        if formatter:
+            meth = getattr(util, formatter, None)
 
+            if meth and callable(meth):
+                self.formatter = meth
+
     def init(self):
         if not self.title:
             self.title = generate_title(self.name)
@@ -751,8 +758,16 @@
 
         for attr in ("name", "Name"):
             if hasattr(self, attr):
-                return getattr(self, attr)
+                return self.get_formatted_value(attr)
 
+    def get_formatted_value(self, attr):
+        value = getattr(self, attr, None)
+        formatter = None
+        if attr in self._class._properties_by_name:
+            formatter = self._class._properties_by_name[attr].formatter
+        #TODO: handle formatters on statistics and headers as well
+        return formatter and formatter(value) or value
+
     def __repr__(self):
         name = self.__class__.__name__
         args = (name, self._class, self._id, self._sync_time)

Modified: mgmt/newdata/rosemary/python/rosemary/util.py
===================================================================
--- mgmt/newdata/rosemary/python/rosemary/util.py	2010-09-02 22:23:10 UTC (rev 4252)
+++ mgmt/newdata/rosemary/python/rosemary/util.py	2010-09-03 19:41:52 UTC (rev 4253)
@@ -9,3 +9,5 @@
 except ImportError:
     from elementtree.ElementTree import *
 
+def fmt_exchange_name(value):
+    return value and value or "Default exchange"



More information about the rhmessaging-commits mailing list