[Mpuls-commits] r4555 - base/trunk/mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Feb 2 16:45:43 CET 2011


Author: torsten
Date: 2011-02-02 16:45:43 +0100 (Wed, 02 Feb 2011)
New Revision: 4555

Modified:
   base/trunk/mpulsweb/lib/helpers.py
Log:
* mpulsweb/lib/helpers.py: New functions
	"get_urls_for_other_datasets", "get_num_of_other_datasets". Needed for
	switching between datasets


Modified: base/trunk/mpulsweb/lib/helpers.py
===================================================================
--- base/trunk/mpulsweb/lib/helpers.py	2011-02-02 15:43:47 UTC (rev 4554)
+++ base/trunk/mpulsweb/lib/helpers.py	2011-02-02 15:45:43 UTC (rev 4555)
@@ -33,8 +33,8 @@
 import locale
 import logging
 import re
+import os 
 import datetime
-import ConfigParser, os
 from string import printable
 from xml.sax.saxutils import quoteattr
 
@@ -214,25 +214,32 @@
 def get_app_title():
     return config.get('mpuls.app.title')
 
+def get_num_of_other_datasets():
+    n = 0
+    apps = re.compile('app:')
+    for sec in g.mpuls_ini.sections():
+        if apps.match(sec): n+=1
+    return n
+
 def get_urls_for_other_datasets():
     apps = re.compile('app:')
-    parser = ConfigParser.ConfigParser()
-    path = os.path.join(config['here'], config['__file__'])
-    parser.readfp(open(path))
     l = []
-    for sec in parser.sections():
+    k = []
+    for sec in g.mpuls_ini.sections():
         if apps.match(sec):
             try:
-                name = parser.get(sec, 'mpuls.app.name')
-                url = parser.get(sec, 'mpuls.app.url')
-                l.append((name, url, False))
+                name = g.mpuls_ini.get(sec, 'mpuls.app.name')
+                url2 = g.mpuls_ini.get(sec, 'mpuls.app.url')
+                if request.url.find(url2) < 0: # current url is not switch-url
+                    l.append((name, url2, False))
             except:
                 pass
-    if l > 1: # Administration is only needed if there are more than one datasets
+    # Administration is only needed if there are more than one datasets
+    if get_num_of_other_datasets() > 1:
         try:
-            path = parser.get('app:redirector', 'location')
-            if request.url.find(path) > 0 and hasRole(['admin']):
-                l.append((_('Userpersmissions'), os.path.join(path, 'permissions'), True))
+            url = g.mpuls_ini.get('app:redirector', 'location')
+            if request.url.find(url) > 0 and hasRole(['admin']):
+                l.append((_('Userpersmissions'), os.path.join(url, 'permissions'), True))
         except:
             pass
     return l



More information about the Mpuls-commits mailing list