Author: eallen
Date: 2008-10-17 18:45:21 -0400 (Fri, 17 Oct 2008)
New Revision: 2654
Modified:
mgmt/trunk/cumin/python/cumin/job.py
mgmt/trunk/cumin/python/wooly/tables.py
Log:
Moved find logic into SqlTable. Only search in current ItemSet.
Modified: mgmt/trunk/cumin/python/cumin/job.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/job.py 2008-10-17 21:59:48 UTC (rev 2653)
+++ mgmt/trunk/cumin/python/cumin/job.py 2008-10-17 22:45:21 UTC (rev 2654)
@@ -212,28 +212,14 @@
search = self.job_search.get(session)
if search:
self.job_search.set(session, None)
- job = self.safe_sql_find_job(session, search)
- if job:
+ object = self.frame.get_object(session)
+ data = self.find_item(session, "custom_id", search, object)
+ if data:
+ job = Identifiable(data["id"])
branch = session.branch()
self.frame.show_job(branch, job).show_view(branch)
self.page.set_redirect_url(session, branch.marshal())
-
- def safe_sql_find_job(self, session, search):
- #job = Job.select("custom_id = '%s'" % search)[0]
- try:
- conn = self.get_connection(session)
- if conn:
- cursor = conn.cursor()
- sql = "select id from job where custom_id = %(search_term)s"
- sql_values = {"search_term": search}
- cursor.execute(sql, sql_values)
- data = cursor.fetchone()
- return Identifiable(data[0])
- except:
- pass
-
-
def get_visible_columns(self, session):
return self.get_request_visible_columns(session, ["custom_group",
"scheduler", "submitter"])
Modified: mgmt/trunk/cumin/python/wooly/tables.py
===================================================================
--- mgmt/trunk/cumin/python/wooly/tables.py 2008-10-17 21:59:48 UTC (rev 2653)
+++ mgmt/trunk/cumin/python/wooly/tables.py 2008-10-17 22:45:21 UTC (rev 2654)
@@ -258,6 +258,19 @@
return writer.to_string()
+ def find_item(self, session, colname, value, *args):
+ cursor = self.get_items(session, *args)
+ cols = [spec[0] for spec in cursor.description]
+ if colname in cols:
+ data = dict()
+ for tuple in cursor:
+ for col, datum in zip(cols, tuple):
+ data[col] = datum
+
+ if data[colname] == value:
+ return data
+
+
class SqlTableColumn(ItemTableColumn):
# XXX to be consistent with similar methods, rename to
# get_sql_order_by
Show replies by date