Author: eallen
Date: 2008-09-11 12:49:57 -0400 (Thu, 11 Sep 2008)
New Revision: 2444
Modified:
mgmt/trunk/cumin/python/cumin/widgets.py
Log:
Refactoring CuminBulkActionForm to allow for a CuminBulkStringActionForm that uses string
ids instead of int ids.
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2008-09-11 16:47:27 UTC (rev 2443)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2008-09-11 16:49:57 UTC (rev 2444)
@@ -220,19 +220,33 @@
def __init__(self, app, name):
super(CuminActionSetForm, self).__init__(app, name)
-class CuminBulkActionForm(ItemSet, CuminForm, Frame):
+class CuminIntIdList(Widget):
def __init__(self, app, name):
- super(CuminBulkActionForm, self).__init__(app, name)
-
+ super(CuminIntIdList, self).__init__(app, name)
+
param = IntegerParameter(app, "param")
self.add_parameter(param)
self.ids = ListParameter(app, "id", param)
self.add_parameter(self.ids)
- def get_items(self, session, *args):
- return self.ids.get(session)
+ def render_item_content(self, session, id):
+ return "Act on object %i" % id
+
+class CuminStringIdList(Widget):
+ def __init__(self, app, name):
+ super(CuminStringIdList, self).__init__(app, name)
+
+ param = Parameter(app, "param")
+ self.add_parameter(param)
+ self.ids = ListParameter(app, "id", param)
+ self.add_parameter(self.ids)
+
+ def render_item_content(self, session, id):
+ return "Act on object %s" % id
+
+class CuminBulk(ItemSet, CuminForm, Frame):
def process_submit(self, session, *args):
items = self.get_items(session, *args)
@@ -245,18 +259,23 @@
pass
def process_return(self, session, *args):
- pass
+ self.page.set_redirect_url(session, self.get_origin(session))
def process_cancel(self, session, *args):
self.process_return(session, *args)
- def render_item_content(self, session, id):
- return "Act on object %i" % id
-
def render_form_heading(self, session, *args):
return "Actions"
+class CuminBulkActionForm(CuminBulk, CuminIntIdList):
+ def get_items(self, session, *args):
+ return self.ids.get(session)
+
+class CuminBulkStringActionForm(CuminBulk, CuminStringIdList):
+ def get_items(self, session, *args):
+ return self.ids.get(session)
+
class CuminStatus(Widget):
def get_args(self, session):
return self.frame.get_args(session)
@@ -736,6 +755,35 @@
return super(FilteredCheckboxIdColumn, self).do_render(session, data,
disabled=disabled)
+class CheckboxStringIdColumn(SqlTableColumn):
+ def __init__(self, app, name, form):
+ super(CheckboxStringIdColumn, self).__init__(app, name)
+
+ self.form = form
+ self.header_class = CheckboxIdColumnHeader
+
+ param = Parameter(app, "param")
+ self.add_parameter(param)
+
+ self.ids = ListParameter(app, "id", param)
+ self.add_parameter(self.ids)
+
+ def get(self, session):
+ return self.ids.get(session)
+
+ def clear(self, session):
+ self.ids.set(session, list())
+
+ def do_render(self, session, data, disabled=False):
+ name = self.ids.path
+ id = data[self.name]
+ attr = id in self.ids.get(session) and "checked=\"checked\""
or ""
+ disa = disabled and "disabled=\"disabled\"" or ""
+ t = "<td><input type=\"checkbox\" name=\"%s\"
value=\"%s\" %s %s/></td>"
+
+ return t % (name, id, attr, disa)
+
+
class NameField(StringField):
def __init__(self, app, name, form):
super(NameField, self).__init__(app, name, form)