[Mpuls-commits] r4970 - in base/trunk: . mpulsweb/lib mpulsweb/templates/auth

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon May 16 15:49:09 CEST 2011


Author: torsten
Date: 2011-05-16 15:49:07 +0200 (Mon, 16 May 2011)
New Revision: 4970

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/helpers.py
   base/trunk/mpulsweb/templates/auth/login.mako
Log:
 Added filtering of dblist based on a regular expressions


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2011-05-16 08:12:39 UTC (rev 4969)
+++ base/trunk/ChangeLog	2011-05-16 13:49:07 UTC (rev 4970)
@@ -1,6 +1,10 @@
 2011-05-16  Torsten Irländer <torsten.irlaender at intevation.de>
 
 	* mpulsweb/lib/helpers.py: Fixed spliting dbname when sorting dblist.
+	* mpulsweb/lib/helpers.py: Added filtering based on a regular
+	expression to the get_db_list.
+	* mpulsweb/templates/auth/login.mako: Call
+	get_sorted_db_from_selectionlist with c.filter (default to None). 
 
 2011-05-12  Torsten Irländer <torsten.irlaender at intevation.de>
 

Modified: base/trunk/mpulsweb/lib/helpers.py
===================================================================
--- base/trunk/mpulsweb/lib/helpers.py	2011-05-16 08:12:39 UTC (rev 4969)
+++ base/trunk/mpulsweb/lib/helpers.py	2011-05-16 13:49:07 UTC (rev 4970)
@@ -99,13 +99,14 @@
 # Helper functions used in the UI to show some information like status messages
 # or icons
 
-def get_sorted_db_from_selectionlist():
+def get_sorted_db_from_selectionlist(filter=None):
     """Returns a sorted list of available dbs"""
-    d = get_db_selectionlist()
+    d = get_db_selectionlist(filter)
     s = {} 
     name = re.compile('\D*')
     for k in d.keys():
-        i = int(name.split(k)[-1])
+        num = name.split(k)[-1] or "0"
+        i = int(num)
         s[i] = k
 
     l = []
@@ -113,11 +114,17 @@
         l.append(s.get(id))
     return l
 
-def get_db_selectionlist():
+def get_db_selectionlist(filter=None):
     """Returns a dictionarie used for listing available db on the loginscreen."""
     dblist = g.mpuls_dblist.get_list()
-    return dblist
+    if filter is None: return dblist
+    filtered_dblist = {}
+    for k in dblist.keys():
+        if not filter.match(k): continue
+        filtered_dblist[k] = dblist.get(k)
+    return filtered_dblist
 
+
 def status_message(s):
     return "%s: %s" % (format_datetime(datetime.datetime.now()), s)
 

Modified: base/trunk/mpulsweb/templates/auth/login.mako
===================================================================
--- base/trunk/mpulsweb/templates/auth/login.mako	2011-05-16 08:12:39 UTC (rev 4969)
+++ base/trunk/mpulsweb/templates/auth/login.mako	2011-05-16 13:49:07 UTC (rev 4970)
@@ -38,7 +38,9 @@
 
     ## This additional selection field for choosing the DB to connect to will
     ## be available as soon as there are defined databases in the dblist json
-    ## file.
+    ## file. Note that the variable c.filter is optional and defaults to None
+    ## which means that no filtering is done. c.filter must be a compiled regular
+    ## expression.
     % if len(h.get_db_selectionlist()) > 0:
     <div class="label">
       <label for="dbname">${_('Agency')}:</label>
@@ -46,7 +48,7 @@
     <div class="input">
       <select name='dbname' size=1>
       <% dbs = h.get_db_selectionlist() %>
-      % for db in h.get_sorted_db_from_selectionlist():
+      % for db in h.get_sorted_db_from_selectionlist(c.filter):
            <option value="${db}">${dbs.get(db).get('label')}</option>
       % endfor
       </select>



More information about the Mpuls-commits mailing list