[Mpuls-commits] r2737 - in base/trunk: . mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue May 25 18:30:31 CEST 2010


Author: bh
Date: 2010-05-25 18:30:29 +0200 (Tue, 25 May 2010)
New Revision: 2737

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/navigation.py
Log:
Generate URLs properly so that SCRIPT_NAME is taken into account:

* mpulsweb/lib/navigation.py (SELECT_ITEM, SELECT_BRANCH)
(CLOSE_BRANCH, OPEN_BRANCH): Removed.
(select_item_url, select_branch_url, close_branch_url)
(open_branch_url): New.  Functions replacing the removed template
strings.
(FileCache.get_image): Convert image name to byte-string and pass
it through url_for to get the correct image url.
(TreeItem.render): Adapt to template->function change.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-05-25 13:31:00 UTC (rev 2736)
+++ base/trunk/ChangeLog	2010-05-25 16:30:29 UTC (rev 2737)
@@ -1,5 +1,18 @@
 2010-05-25  Bernhard Herzog  <bh at intevation.de>
 
+	Generate URLs properly so that SCRIPT_NAME is taken into account:
+
+	* mpulsweb/lib/navigation.py (SELECT_ITEM, SELECT_BRANCH)
+	(CLOSE_BRANCH, OPEN_BRANCH): Removed.
+	(select_item_url, select_branch_url, close_branch_url)
+	(open_branch_url): New.  Functions replacing the removed template
+	strings.
+	(FileCache.get_image): Convert image name to byte-string and pass
+	it through url_for to get the correct image url.
+	(TreeItem.render): Adapt to template->function change.
+
+2010-05-25  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/model/user.py (log): Add logger.
 
 2010-05-25  Bernhard Herzog  <bh at intevation.de>

Modified: base/trunk/mpulsweb/lib/navigation.py
===================================================================
--- base/trunk/mpulsweb/lib/navigation.py	2010-05-25 13:31:00 UTC (rev 2736)
+++ base/trunk/mpulsweb/lib/navigation.py	2010-05-25 16:30:29 UTC (rev 2737)
@@ -40,18 +40,32 @@
 from formed.instance.backends.postgres import DBFactory as InstanceFactory
 
 from mpulsweb.lib.db import PostgresDBInterface
+import mpulsweb.lib.helpers
 
-SELECT_ITEM = u"/formularpage/select/%s"
-SELECT_BRANCH = u"/navigation/select_branch/%s"
-CLOSE_BRANCH = u"/navigation/close_branch/%s"
-OPEN_BRANCH = u"/navigation/open_branch/%s"
 
-CHECK_MODIFICATION = u'onclick="return checkModification();"'
+log = logging.getLogger(__name__)
 
 
-log = logging.getLogger(__name__)
+def select_item_url(id):
+    return mpulsweb.lib.helpers.url_for(controller="/formularpage",
+                                        action="select", id=id)
 
+def select_branch_url(id):
+    return mpulsweb.lib.helpers.url_for(controller="/navigation",
+                                        action="select_branch", id=id)
 
+def close_branch_url(id):
+    return mpulsweb.lib.helpers.url_for(controller="/navigation",
+                                        action="close_branch", id=id)
+
+def open_branch_url(id):
+    return mpulsweb.lib.helpers.url_for(controller="/navigation",
+                                        action="open_branch", id=id)
+
+
+CHECK_MODIFICATION = u'onclick="return checkModification();"'
+
+
 def get_navigation(id, openfolders=None):
     factory = InstanceFactory(g.formedTree, PostgresDBInterface())
     instance_tree = factory.loadInstanceTreeByIdentifier(id,
@@ -95,7 +109,10 @@
         self.cache = {}
 
     def get_image(self, name, attributes=""):
-        return '<img src="%s" %s>' % (name, attributes)
+        if isinstance(name, unicode):
+            name = name.encode("utf-8")
+        return '<img src="%s" %s>' % (mpulsweb.lib.helpers.url_for(name),
+                                      attributes)
 
     def get_base(self):
         return self.base
@@ -159,7 +176,7 @@
         icon = []
         entry = []
         if self.is_child():
-            select_link = SELECT_ITEM % self.key
+            select_link = select_item_url(self.key)
             icon.append(u'<a href="%s" %s>'
                         % (select_link, CHECK_MODIFICATION))
             icon.append(get_image("/images/icons/navigation/entry.png",
@@ -169,9 +186,9 @@
                                   % (_('entry'), _('Open page'))))
         else:
             deepest = self.deepest_item()
-            select_link = SELECT_BRANCH %  deepest.key
+            select_link = select_branch_url(deepest.key)
             if self.is_open:
-                action = CLOSE_BRANCH % self.key
+                action = close_branch_url(self.key)
                 icon.append(u'<a href="%s" %s>' % (action, CHECK_MODIFICATION))
                 icon.append(get_image("/images/icons/navigation/folder_open.png",
                                       u' border="0"'
@@ -179,7 +196,7 @@
                                       u' title="%s"'
                                       % (_('entry'), _('Open page'))))
             else:
-                action = OPEN_BRANCH % self.key
+                action = open_branch_url(self.key)
                 icon.append(u'<a href="%s" %s>' % (action, CHECK_MODIFICATION))
                 icon.append(get_image("/images/icons/navigation/folder_closed.png",
                                       u' border="0"'



More information about the Mpuls-commits mailing list