changeset 93:3a421b779396 draft

bts_queries: no need for a sorting funcion list.sort(key=) and a lambda does the job quite well
author diegoe-guest
date Wed, 01 Jul 2009 07:40:23 +0000
parents 0c3e35a8b5ed
children 4d52e764da8e
files bts_webui/amancay/bts_queries.py bts_webui/amancay/search.py bts_webui/amancay/tables.py
diffstat 3 files changed, 13 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/bts_webui/amancay/bts_queries.py
+++ b/bts_webui/amancay/bts_queries.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+# vim: set sw=4 ts=4 sts=4 noet:
 
 class BtsQueries:
 	"""
@@ -90,15 +90,3 @@
 		for user in users:
 			result[user] = self.server.get_usertag(user)
 		return result
-
-# ************************ LDAP Queries *****************************
-
-# Is it worth it?
-
-# ************************ Sorting Functions ************************
-
-class bug_sort:
-	def cmp_log_modified (x, y):
-		return cmp(x["log_modified"], y["log_modified"])
-
-	cmp_log_modified = staticmethod(cmp_log_modified)
--- a/bts_webui/amancay/search.py
+++ b/bts_webui/amancay/search.py
@@ -21,7 +21,7 @@
 from django.contrib.sessions.models import Session
 
 # Needed for SOAP
-from bts_queries import SoapQueries, bug_sort
+from bts_queries import SoapQueries
 queries = SoapQueries()
 
 # Bug views
@@ -69,7 +69,7 @@
 		start = page * amount
 		bug_list = queries.get_bugs_status(bugs[start:start+amount])
 		store_search(request, search_id, bug_list, total=len(bugs))
-		bug_list.sort(bug_sort.cmp_log_modified, reverse=True)
+		bug_list.sort(key=lambda x: x.log_modified, reverse=True)
 
 		# Start the read-ahead thread
 		reader = _ReadAhead(request, search_id, bugs, amount)
--- a/bts_webui/amancay/tables.py
+++ b/bts_webui/amancay/tables.py
@@ -1,3 +1,5 @@
+# vim: set sw=4 ts=4 sts=4 noet:
+
 import datetime
 
 # Needed to get_template, prepare context and output Response
@@ -15,7 +17,7 @@
 from django.utils import simplejson 
 
 # Needed for SOAP
-from bts_queries import SoapQueries, bug_sort
+from bts_queries import SoapQueries
 queries = SoapQueries()
 
 # Toolboxes
@@ -23,16 +25,17 @@
 
 # Bug renderer.
 def render_bug_table(request, queries, title, bugs, amount, current_view):
-	if (bugs != None and len(bugs) > 0):
+	if bugs:
 		bug_list = queries.get_bugs_status(bugs[:amount])
-		bug_list.sort(bug_sort.cmp_log_modified, reverse=True)
+		bug_list.sort(key=lambda x: x.log_modified, reverse=True)
 	else:
 		bug_list = None
-	if (request.GET.has_key('xhr')):
+
+	if request.GET.has_key('xhr'):
 		# We only need to list the data.
-		return HttpResponse( simplejson.dumps(bug_list),
-							 mimetype='application/javascript' )
-	elif (request.path.find("table") != -1):
+		return HttpResponse(simplejson.dumps(bug_list),
+							 mimetype='application/javascript')
+	elif request.path.find("table") != -1:
 		# We only need to render the table
 		return render_to_response('table.html', 
 								  {'bug_list': bug_list,