Author: justi9
Date: 2008-10-24 21:41:54 -0400 (Fri, 24 Oct 2008)
New Revision: 2691
Modified:
mgmt/trunk/cumin/python/cumin/formats.py
mgmt/trunk/cumin/python/cumin/model.py
mgmt/trunk/cumin/python/cumin/queue.py
mgmt/trunk/cumin/python/wooly/forms.py
mgmt/trunk/cumin/python/wooly/widgets.py
Log:
William Henry's move message functionality and tool tips for shortened names
Modified: mgmt/trunk/cumin/python/cumin/formats.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/formats.py 2008-10-24 19:06:46 UTC (rev 2690)
+++ mgmt/trunk/cumin/python/cumin/formats.py 2008-10-25 01:41:54 UTC (rev 2691)
@@ -112,9 +112,9 @@
def fmt_shorten(string, pre=16, post=4):
if len(string) > pre + post:
if post:
- string = string[:pre] + "…" + string[-post:]
+ string = "<span title=\"%s\">%s</span>" %
(string, string[:pre] + "…" + string[-post:])
else:
- string = string[:pre] + "…"
+ string = "<span title=\"%s\">%s</span>" %
(string, string[:pre] + "…")
return string
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2008-10-24 19:06:46 UTC (rev 2690)
+++ mgmt/trunk/cumin/python/cumin/model.py 2008-10-25 01:41:54 UTC (rev 2691)
@@ -912,6 +912,9 @@
def init(self):
self.frame = self.model.frame.broker.queue
+ action = self.MoveMessages(self, "move_messages")
+ action.summary = True
+
def get_title(self, session):
return "Queue"
@@ -966,6 +969,18 @@
completion("OK")
+ class MoveMessages(CuminAction):
+ def show(self, session, queue):
+ frame = self.cumin_class.show_object(session, queue)
+ return frame.move_messages.show(session)
+
+ def get_title(self, session):
+ return "Move Messages"
+
+ def do_invoke(self, queue, args, completion):
+ broker = queue.vhost.broker
+ broker.queueMoveMessages(self.model.data, completion,
args["srcQueue"], args["destQueue"], args["qty"])
+
class CuminExchange(RemoteClass):
def __init__(self, model):
super(CuminExchange, self).__init__(model, "exchange",
Modified: mgmt/trunk/cumin/python/cumin/queue.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/queue.py 2008-10-24 19:06:46 UTC (rev 2690)
+++ mgmt/trunk/cumin/python/cumin/queue.py 2008-10-25 01:41:54 UTC (rev 2691)
@@ -61,6 +61,9 @@
self.__purge = self.Purge(app, "purge")
self.add_child(self.__purge)
+ self.__move_messages = self.MoveMessages(app, "move_messages")
+ self.add_child(self.__move_messages)
+
self.__remove = self.Remove(app, "remove")
self.add_child(self.__remove)
@@ -97,6 +100,20 @@
def render_content(self, session):
return "Purge"
+
+ class MoveMessages(FormButton):
+ def process_submit(self, session):
+ ids = self.parent.ids.get(session)
+ self.parent.ids.clear(session)
+
+ branch = session.branch()
+ frame = self.frame.show_queues_move(branch)
+ frame.ids.set(branch, ids)
+ self.page.set_redirect_url(session, branch.marshal())
+
+ def render_content(self, session):
+ return "Move Messages"
+
class Remove(FormButton):
def process_submit(self, session):
ids = self.parent.ids.get(session)
@@ -186,6 +203,9 @@
self.add_mode(self.remove)
self.set_remove_mode(self.remove)
+ self.move_messages = QueueMoveMessages(app, "move_messages")
+ self.add_mode(self.move_messages)
+
def show_object(self, session, queue):
reg = queue.vhost.broker.registration
self.page.main.broker.set_object(session, reg)
@@ -202,6 +222,9 @@
else:
return "Queue"
+ def show_move(self, session):
+ return self.show_mode(session, self.move_messages)
+
class QueueStatus(CuminStatus):
def render_consumers(self, session, queue):
return self.app.model.queue.consumers.value(queue)
@@ -730,3 +753,90 @@
def render_item_unacked_messages(self, session, consumer):
return self.app.model.consumer.unackedMessages.value(consumer)
+
+class QueueSelectField(FormField):
+ def __init__(self, app, name, form):
+ super(QueueSelectField, self).__init__(app, name)
+
+ param = QueueParameter(app, "param")
+ self.param = param
+ self.add_parameter(param)
+
+ self.queue_set = self.QueueInputSet(app, "queue_set", param)
+ self.add_child(self.queue_set)
+
+ def get(self, session):
+ return self.param.get(session)
+
+ def get_args(self, session):
+ return self.frame.get_args(session)
+
+ def render_title(self, session, queue):
+ return "Select the destination queue"
+
+ def render_inputs(self, session, queue):
+ return self.queue_set.render(session)
+
+ class QueueInputSet(RadioInputSet):
+ def get_args(self, session):
+ return self.frame.get_args(session)
+
+ def do_get_items(self, session, queue):
+ queue_list_full = sorted_by(list(queue.vhost.queues))
+ delta = timedelta(minutes=10)
+ queue_list = []
+ for _queue in queue_list_full:
+ if (_queue.recTime > (datetime.now() - delta)) and (_queue.name !=
queue.name):
+ queue_list.append(_queue)
+ return queue_list
+
+ def render_item_value(self, session, queue):
+ return queue.id
+
+ def render_item_content(self, session, queue):
+ return queue.name or "<em>Default</em>"
+
+ def render_item_checked_attr(self, session, queue):
+ return queue is self.param.get(session) and
"checked=\"checked\"" or None
+
+class QueueMoveMessages(CuminFieldForm):
+ def __init__(self, app, name):
+ super(QueueMoveMessages, self).__init__(app, name)
+
+ self.move_to = QueueSelectField(app, "move_to", self)
+ self.add_field(self.move_to)
+
+ self.move_qty = MultiplicityField(app, "move_qty")
+ self.add_field(self.move_qty)
+
+ def get_args(self, session):
+ return self.frame.get_args(session)
+
+ def render_title(self, session, queue):
+ return "Move Messages from Queue '%s'" % queue.name
+
+ def process_submit(self, session, queue):
+ request_qty = self.move_qty.get(session)
+ args = dict()
+ args["destQueue"] = self.move_to.get(session).name
+ args["srcQueue"] = queue.name
+
+ if request_qty == "all":
+ args["qty"] = 0
+ elif request_qty == "top":
+ args["qty"] = 1
+ elif request_qty == "N":
+ args["qty"] = self.move_qty.top_n.get_n_value(session)
+ else:
+ raise Exception("Wrong Value")
+
+ action = self.app.model.queue.move_messages
+ action.invoke(queue, args)
+ self.process_cancel(session, queue)
+
+ def render_submit_content(self, session, queue):
+ return "Yes, Move Messages from Queue '%s'" % queue.name
+
+ def render_cancel_content(self, session, queue):
+ return "No, Cancel"
+
Modified: mgmt/trunk/cumin/python/wooly/forms.py
===================================================================
--- mgmt/trunk/cumin/python/wooly/forms.py 2008-10-24 19:06:46 UTC (rev 2690)
+++ mgmt/trunk/cumin/python/wooly/forms.py 2008-10-25 01:41:54 UTC (rev 2691)
@@ -343,6 +343,9 @@
assert self.param is not None
assert isinstance(self.param, Parameter)
+ def get(self, session):
+ return self.param.get(session)
+
def add_option(self, option):
assert isinstance(option, RadioFieldOption)
Modified: mgmt/trunk/cumin/python/wooly/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/wooly/widgets.py 2008-10-24 19:06:46 UTC (rev 2690)
+++ mgmt/trunk/cumin/python/wooly/widgets.py 2008-10-25 01:41:54 UTC (rev 2691)
@@ -182,7 +182,6 @@
if items is None:
items = self.do_get_items(session, *args)
-
if items is None:
items = ()
@@ -225,7 +224,6 @@
if items is None:
items = self.do_get_items(session, *args)
-
if items is None:
items = ()