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

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


Author: bh
Date: 2010-05-25 19:28:24 +0200 (Tue, 25 May 2010)
New Revision: 2739

Modified:
   base/trunk/ChangeLog
   base/trunk/mpulsweb/lib/renderer.py
Log:
Generate URLs properly so that SCRIPT_NAME is taken into account:
* mpulsweb/lib/renderer.py (icon): New function to help with icon
URL generation.
(ViewRenderer.render, ViewRenderer._renderAttributes)
(ViewRenderer._renderRepeatList, ViewRenderer._renderRepeatNav)
(ViewRenderer._renderInfo, RepeatGroupRenderer.render_digest)
(RepeatGroupRenderer.render, ErrorRenderer.render)
(ErrorRenderer.render_items): Generate URLs with the url_for and
icon functions.


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2010-05-25 17:22:55 UTC (rev 2738)
+++ base/trunk/ChangeLog	2010-05-25 17:28:24 UTC (rev 2739)
@@ -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/renderer.py (icon): New function to help with icon
+	URL generation.
+	(ViewRenderer.render, ViewRenderer._renderAttributes)
+	(ViewRenderer._renderRepeatList, ViewRenderer._renderRepeatNav)
+	(ViewRenderer._renderInfo, RepeatGroupRenderer.render_digest)
+	(RepeatGroupRenderer.render, ErrorRenderer.render)
+	(ErrorRenderer.render_items): Generate URLs with the url_for and
+	icon functions.
+
+2010-05-25  Bernhard Herzog  <bh at intevation.de>
+
 	* mpulsweb/lib/renderer.py (RepeatGroupRenderer.render): Remove
 	some debug prints.
 

Modified: base/trunk/mpulsweb/lib/renderer.py
===================================================================
--- base/trunk/mpulsweb/lib/renderer.py	2010-05-25 17:22:55 UTC (rev 2738)
+++ base/trunk/mpulsweb/lib/renderer.py	2010-05-25 17:28:24 UTC (rev 2739)
@@ -41,7 +41,7 @@
 from formed.instance.backends.common import RuleEvalContext
 
 from mpulsweb.lib.helper.filters import NA
-from mpulsweb.lib.helpers import dd_mm_YYYY as format_date
+from mpulsweb.lib.helpers import url_for, dd_mm_YYYY as format_date
 
 
 log = logging.getLogger(__name__)
@@ -165,6 +165,11 @@
             form_result[fieldid] = ""
 
 
+def icon(name):
+    """Return the url for the icon given by name."""
+    return url_for("/images/icons/" + name)
+
+
 class Text:
 
     def __init__(self, txt):
@@ -239,9 +244,11 @@
     def render(self, showNext=False):
         out = []
         if not self.ro_mode:
-            out.append('<form id="formularpage"'
-                       ' action="/formularpage/save"'
-                       ' accept-charset="UTF-8" method="POST">\n')
+            out.append(tag("form", id="formularpage",
+                           action=url_for(controller="formularpage",
+                                          action="save"),
+                           accept_charset="UTF-8",
+                           method="POST"))
             # Add submitbutton at the top of the page too
             out.append('<div class="widget formbuttons">')
             out.append(tag("input", type="submit", name="save",
@@ -326,25 +333,25 @@
 
         out = []
         if meta.hasHelp():
-            out.append(tag("a", href="/annotations/help/%s" % meta.getName(),
-                           target="_blank"))
-            out.append('<img src="/images/icons/formular/help.png" alt="help">')
+            out.append(tag("a", target="_blank",
+                           href=url_for(controller="annotations",
+                                        action="help", id=meta.getName())))
+            out.append(tag("img", src=icon("formular/help.png"), alt="help"))
             out.append('</a>')
         if is_required(meta.getFlags()):
-            out.append(tag("a",
-                           href="/annotations/required/%s" % meta.getName(),
-                           target="_blank"))
-            out.append('<img src="/images/icons/formular/required.png"'
-                       ' width="12"'
-                       ' height="12"'
-                       ' alt="required">')
+            out.append(tag("a", target="_blank",
+                           href=url_for(controller="annotations",
+                                        action="required", id=meta.getName())))
+            out.append(tag("img", src=icon("formular/required.png"),
+                           width="12", height="12", alt="required"))
             out.append('</a>')
         if is_evaluation_relevant(meta.getFlags()):
-            out.append(tag("a",
-                           href="/annotations/evaluation/%s" % meta.getName(),
-                           target="_blank"))
-            out.append('<img src="/images/icons/formular/evaluation.png"'
-                       ' alt="evaluation">')
+            out.append(tag("a", target="_blank",
+                           href=url_for(controller="annotations",
+                                        action="evaluation",
+                                        id=meta.getName())))
+            out.append(tag("img", src=icon("formular/evaluation.png"),
+                           alt="evaluation"))
             out.append('</a>')
         return "".join(out)
 
@@ -442,7 +449,7 @@
             out.append('<td class="vcontrol" width="15">')
             if not self.ro_mode:
                 out.append(tag("input", name="del_rg", type="image",
-                               src="/images/icons/delete_active_16.png",
+                               src=icon("delete_active_16.png"),
                                value=child.getIdentifier(),
                                alt=_('Delete RG'), title=_('Delete RG')))
             out.append('</td>')
@@ -454,9 +461,8 @@
             out.append('<tr>')
             out.append('<td class="hcontrol" style="text-align: right;"'
                        ' colspan="2">')
-            out.append(tag("input", width="16", name="add_rg",
-                           type="image", src="/images/icons/new_16.png",
-                           value=node.getIdentifier(),
+            out.append(tag("input", width="16", name="add_rg", type="image",
+                           src=icon("new_16.png"), value=node.getIdentifier(),
                            alt=_('Add new RG'), title=_('Add new RG')))
             out.append("</td>")
             out.append("</tr>")
@@ -477,36 +483,42 @@
         out.append('<td class="hcontrol">')
 
         out.append(tag("a", name=_('Select first'),
-                       href="/repeatgroup/select_first/%s" % child_id))
-        out.append('<img src="/images/icons/go_first_16.png"/>')
+                       href=url_for(controller="repeatgroup",
+                                    action="select_first", id=child_id)))
+        out.append(tag("img", src=icon("go_first_16.png")))
         out.append('</a>')
 
         out.append(tag("a", name=_('Select previous'),
-                       href="/repeatgroup/select_prev/%s" % child_id))
-        out.append('<img src="/images/icons/go_previous_16.png"/>')
+                       href=url_for(controller="repeatgroup",
+                                    action="select_prev", id=child_id)))
+        out.append(tag("img", src=icon("go_previous_16.png")))
         out.append('</a>')
 
         out.append(tag("a", name=_('Select next'),
-                       href="/repeatgroup/select_next/%s" % child_id))
-        out.append('<img src="/images/icons/go_next_16.png"/>')
+                       href=url_for(controller="repeatgroup",
+                                    action="select_next", id=child_id)))
+        out.append(tag("img", src=icon("go_next_16.png")))
         out.append('</a>')
 
         out.append(tag("a", name=_('Select last'),
-                       href="/repeatgroup/select_last/%s" % child_id))
-        out.append('<img src="/images/icons/go_last_16.png"/>')
+                       href=url_for(controller="repeatgroup",
+                                    action="select_last", id=child_id)))
+        out.append(tag("img", src=icon("go_last_16.png")))
         out.append('</a>')
 
         out.append(' | ?/? | ')
 
         if not self.ro_mode:
             out.append(tag("a", name=_('Create new'),
-                           href="/repeatgroup/new/%s" % child_id))
-            out.append('<img src="/images/icons/formular/rg_new.png"/>')
+                           href=url_for(controller="repeatgroup", action="new",
+                                        id=child_id)))
+            out.append(tag("img", src=icon("formular/rg_new.png")))
             out.append('</a>')
 
             out.append(tag("a", name=_('Delete'),
-                           href="/repeatgroup/delete/%s" % child_id))
-            out.append('<img src="/images/icons/formular/rg_delete.png"/>')
+                           href=url_for(controller="repeatgroup",
+                                        action="delete", id=child_id)))
+            out.append(tag("img", src=icon("formular/rg_delete.png")))
             out.append('</a>')
 
         out.append('</td>')
@@ -538,7 +550,7 @@
         depth = 1 #visibleDepth(node)
         if text:
             out.append('<p class="text">')
-            out.append('<img src="/images/icons/formular/info.png"> ')
+            out.append(tag("img", src=icon("formular/info.png")))
             out.append(escape(text))
             out.append('</p>')
             self.toTarget(Item("".join(out)), meta.getTarget())
@@ -929,22 +941,23 @@
                         rg.getIdentifier())
             out.append('<tr><td>%s</td></tr>' % escape(rg.getIdentifier()))
         else:
+            child_identifier = rg.getChildren()[0].getIdentifier()
             for num, field in enumerate(fields):
                 item = self.it.getItem('%s:%s:%s'
                                        % (field, rg.getInternalIdentifier(),
                                           case_id))
                 out.append('<tr>')
                 out.append('<td class="label">')
-                out.append(tag("a",
-                               href=("/navigation/select_branch/%s"
-                                     % rg.getChildren()[0].getIdentifier())))
+                out.append(tag("a", href=url_for(controller="navigation",
+                                                 action="select_branch",
+                                                 id=child_identifier)))
                 out.append(escape(self._getMeta(item).getDescription()))
                 out.append('</a>')
                 out.append('</td>')
                 out.append('<td>')
-                out.append(tag("a",
-                               href=("/navigation/select_branch/%s"
-                                     % rg.getChildren()[0].getIdentifier())))
+                out.append(tag("a", href=url_for(controller="navigation",
+                                                 action="select_branch",
+                                                 id=child_identifier)))
                 value = item.getValue()
                 if isinstance(self._getMeta(item), data.DateLeaf):
                     value = format_date(value)
@@ -1012,15 +1025,17 @@
             out.append('</td>')
             out.append('<td class="actions">')
             out.append(tag("a",
-                           href=("/navigation/select_branch/%s"
-                                 % sd.rg.getChildren()[0].getIdentifier())))
-            out.append(tag("img", src="/images/icons/open_active_22.png",
+                           href=url_for(controller="navigation",
+                                        action="select_branch",
+                                   id=sd.rg.getChildren()[0].getIdentifier())))
+            out.append(tag("img", src=icon("open_active_22.png"),
                            border="0", alt=_('view'), title=_('view')))
             out.append("</a>")
             if not self.ro_mode:
-                out.append(tag("a", href=("/repeatgroup/delete/%s"
-                                          % sd.rg.getIdentifier())))
-                out.append(tag("img", src="/images/icons/delete_active_22.png",
+                out.append(tag("a", href=url_for(controller="repeatgroup",
+                                                 action="delete",
+                                                 id=sd.rg.getIdentifier())))
+                out.append(tag("img", src=icon("delete_active_22.png"),
                                border="0", alt=_('delete'), title=_('delete')))
                 out.append("</a>")
             out.append('</td>')
@@ -1033,8 +1048,9 @@
             out.append('<div>')
             out.append('<br>')
             out.append(tag("a", class_="button",
-                           href=("/repeatgroup/new/%s"
-                                 % self.page.getIdentifier())))
+                           href=url_for(controller="repeatgroup",
+                                        action="new",
+                                        id=self.page.getIdentifier())))
             out.append(escape(_('Create new item')))
             out.append("</a>")
             out.append("</div>")
@@ -1051,25 +1067,21 @@
         tree = page.getInstanceTree()
 
         out = []
-        out.append(self.render_items(self.error_items,
-                                     _('Formular errors'),
-                                     "/images/icons/info/alert.png",
-                                     tree))
-        out.append(self.render_items(self.warnings,
-                                     _('Formular warnings'),
-                                     "/images/icons/info/info.png",
-                                     tree,
-                                     css_class = 'warning-box'))
+        out.append(self.render_items(self.error_items, _('Formular errors'),
+                                     icon("info/alert.png"), tree))
+        out.append(self.render_items(self.warnings, _('Formular warnings'),
+                                     icon("info/info.png"), tree,
+                                     css_class='warning-box'))
         return "".join(out)
 
-    def render_items(self, items, title, icon, tree, css_class=""):
+    def render_items(self, items, title, title_icon, tree, css_class=""):
         if not items:
             return ""
 
         out = []
         out.append(tag("div", class_=("widget dialog %s" % css_class)))
         out.append('<h1>')
-        out.append(tag("img", src=icon, alt=''))
+        out.append(tag("img", src=title_icon, alt=''))
         out.append(escape(title))
         out.append('</h1>')
         out.append('<ol>')
@@ -1083,8 +1095,9 @@
                 values = [values]
             for v in values:
                 out.append('<li>')
-                out.append(tag("a", href="/formularpage/undo/%s" % k))
-                out.append(tag("img", src="/images/icons/formular/undo.png",
+                out.append(tag("a", href=url_for(controller="formularpage",
+                                                 action="undo", id=k)))
+                out.append(tag("img", src=icon("formular/undo.png"),
                                border="0", alt="undo",
                                title=_('Restore last valid value'),
                                _close=True))



More information about the Mpuls-commits mailing list