[Mpuls-commits] r81 - in waska/trunk: . waskaweb/model

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Aug 21 08:21:28 CEST 2008


Author: torsten
Date: 2008-08-21 08:21:27 +0200 (Thu, 21 Aug 2008)
New Revision: 81

Modified:
   waska/trunk/ChangeLog.txt
   waska/trunk/waskaweb/model/logbook.py
Log:
Changed default sorting order of logbook and preparation for dynamic sorting.


Modified: waska/trunk/ChangeLog.txt
===================================================================
--- waska/trunk/ChangeLog.txt	2008-08-20 16:48:50 UTC (rev 80)
+++ waska/trunk/ChangeLog.txt	2008-08-21 06:21:27 UTC (rev 81)
@@ -1,3 +1,10 @@
+2008-08-21 	Torsten Irlaender  <torsten.irlaender at intevation.de>
+
+	Changed default sorting order of logbook and preparation for dynamic
+	sorting.
+
+	* waskaweb/model/logbook.py: Prepared model for dynanmic sorting.
+
 2008-08-18  Sascha L. Teichmann <sascha.teichmann at intevation.de>
 
 	* waskaweb/public/images/icons/required_12x12.png,

Modified: waska/trunk/waskaweb/model/logbook.py
===================================================================
--- waska/trunk/waskaweb/model/logbook.py	2008-08-20 16:48:50 UTC (rev 80)
+++ waska/trunk/waskaweb/model/logbook.py	2008-08-21 06:21:27 UTC (rev 81)
@@ -69,8 +69,8 @@
 SELECT l.id AS id, datum, b.vorname AS vorname, b.nachname AS nachname, art, kurz_notiz, notiz, dauer
 FROM ka_logbuch_tbl_view l LEFT JOIN ka_benutzer_tbl_view b
 ON l.bearbeiter = b.id
-WHERE l.master_id = %(mid)s
-ORDER BY datum
+WHERE l.master_id = %s
+ORDER BY %s %s 
 """
 
 LOAD_LOGBOOK_BY_ID = """
@@ -237,9 +237,11 @@
 
 class Logbook:
 
-    def __init__(self, mid = None):
-        self.entries = []
-        self.mid     = mid
+    def __init__(self, mid = None, sort_field = 'datum', sort_order='desc'):
+        self.entries    = []
+        self.mid        = mid
+        self.sort_field = sort_field
+        self.sort_order = sort_order
 
     def deleteEntryById(self, mid):
         conn, cur = None, None
@@ -251,13 +253,20 @@
         finally:
             db.recycleConnection(conn, cur)
 
-    def loadById(self, mid):
+    def loadById(self, mid, sort_field = 'datum', sort_order='desc'):
         self.mid = mid
+        self.sort_field = sort_field
+        self.sort_order = sort_order
         conn, cur = None, None
         try:
             conn = db.getConnection()
             cur  = conn.cursor()
-            cur.execute(LOAD_LOGBOOK, {'mid': mid})
+            try:
+                # Removed prepared statement as quoting does not work for sorting e.g
+                # cur.execute(LOAD_LOGBOOK, {'mid': mid, 'field': sort_field, 'order': sort_order})
+                cur.execute(LOAD_LOGBOOK % (mid, sort_field, sort_order))
+            except:
+                print cur.query
             while True:
                 row = cur.fetchone()
                 if not row: break



More information about the Mpuls-commits mailing list