Fix links to CheckResult tabs (closes #2162091)
authorJulien Cristau <julien.cristau@logilab.fr>
Wed, 22 Feb 2012 09:19:25 +0100
changeset 811 b46fb7e23870
parent 808 2118c22e12d6
child 812 0153b3ad2308
Fix links to CheckResult tabs (closes #2162091) When a check's name includes a '.' we need to replace it with '_'.
entities.py
views/__init__.py
views/primary.py
views/reports.py
views/testexecution.py
--- a/entities.py	Thu Dec 22 17:43:34 2011 +0100
+++ b/entities.py	Wed Feb 22 09:19:25 2012 +0100
@@ -16,11 +16,18 @@
 from logilab.mtconverter import xml_escape
 
 from cubicweb import ValidationError
+from cubicweb.uilib import domid
 from cubicweb.entity import _marker
 from cubicweb.entities import AnyEntity, fetch_config
 
 from cubes.narval.entities import Plan
 
+def _anchor_name(data):
+    """escapes XML/HTML forbidden characters in attributes and PCDATA"""
+    return (data.replace('&', '').replace('<', '').replace('>','')
+            .replace('"', '').replace("'", ''))
+
+
 class ExecutionRSSMixin(object): # XXX move to an ui adapter
 
     RSS_LIMIT = 20
@@ -431,13 +438,17 @@
                                              'name', 'status'])
 
     def absolute_url(self, *args, **kwargs):
-        kwargs.setdefault('tab', self.name)
+        kwargs.setdefault('tab', domid(self.anchored_name))
         return self.execution.absolute_url(*args, **kwargs)
 
     @property
     def execution(self):
         return self.during_execution[0]
 
+    @property
+    def anchored_name(self):
+        return _anchor_name(self.name)
+
 
 class CheckResultInfo(AnyEntity):
     __regid__ = 'CheckResultInfo'
--- a/views/__init__.py	Thu Dec 22 17:43:34 2011 +0100
+++ b/views/__init__.py	Wed Feb 22 09:19:25 2012 +0100
@@ -11,11 +11,6 @@
 
 from cubes.narval.proxy import bot_proxy
 
-def anchor_name(data):
-    """escapes XML/HTML forbidden characters in attributes and PCDATA"""
-    return (data.replace('&', '').replace('<', '').replace('>','')
-            .replace('"', '').replace("'", ''))
-
 _afs = uicfg.autoform_section
 _affk = uicfg.autoform_field_kwargs
 
--- a/views/primary.py	Thu Dec 22 17:43:34 2011 +0100
+++ b/views/primary.py	Wed Feb 22 09:19:25 2012 +0100
@@ -21,7 +21,6 @@
 from cubicweb.web.views import ibreadcrumbs
 
 from cubes.narval.views import no_robot_index, startplan
-from cubes.apycot.views import anchor_name
 
 
 _pvs = uicfg.primaryview_section
--- a/views/reports.py	Thu Dec 22 17:43:34 2011 +0100
+++ b/views/reports.py	Wed Feb 22 09:19:25 2012 +0100
@@ -14,11 +14,11 @@
 
 from StringIO import StringIO
 
+from cubicweb.uilib import domid
 from cubicweb.view import EntityView
 from cubicweb.selectors import is_instance
 
 from cubes.narval.views import no_robot_index
-from cubes.apycot.views import anchor_name
 
 
 @cached
@@ -91,16 +91,16 @@
         self.w(u'<table class="summary">')
         self.w(u'<tr><th>%s</th><th>%s</th></tr>'
                % (self._cw._('name'), self._cw._('status')))
-        url = entity.absolute_url()
         for checkname in entity.configuration.all_checks():
             check = entity.check_result_by_name(checkname)
             if check is None:
                 status = 'nc'
+                url = entity.absolute_url()
             else:
                 status = entity.check_result_by_name(checkname).status
-            self.w(u'<tr><td><a href="%s?tab=%s">%s</a></td><td class="status_%s">%s</td></tr>'
-                   % (url, anchor_name(checkname), xml_escape(checkname),
-                      status, status))
+                url = check.absolute_url()
+            self.w(u'<tr><td><a href="%s">%s</a></td><td class="status_%s">%s</td></tr>'
+                   % (url, xml_escape(checkname), status, status))
         self.w(u'</table>')
 
 
--- a/views/testexecution.py	Thu Dec 22 17:43:34 2011 +0100
+++ b/views/testexecution.py	Wed Feb 22 09:19:25 2012 +0100
@@ -20,7 +20,6 @@
 from cubicweb.web.views import ibreadcrumbs, idownloadable, navigation
 
 from cubes.narval.views import no_robot_index
-from cubes.apycot.views import anchor_name
 
 from cubes.narval.views.plan import PlanOptionsCell
 
@@ -180,7 +179,7 @@
         for check in entity.reverse_during_execution:#configuration.all_checks:
             label = u'%s [<b class="status_%s">%s</b>]' % (
                 xml_escape(check.name), check.status, self._cw._(check.status))
-            tabs.append((anchor_name(check.name),
+            tabs.append((check.anchored_name,
                          {'vid': 'apycot.te.checkresult', 'label': label,
                           'rset': check.as_rset()}))
         return tabs
@@ -253,7 +252,7 @@
         checks = []
         for check in entity.reverse_during_execution:
             content = u'%s (%s)' % (self._cw._(check.name), check.status)
-            url = entity.absolute_url(tab=anchor_name(check.name))
+            url = check.absolute_url()
             title = self._cw._('see execution report for %s') % check.name
             checks.append(tags.a(content, href=url, title=title))
         if checks:
@@ -397,7 +396,7 @@
     def render_entity_title(self, entity):
         self._cw.add_css('cubes.apycot.css')
         self.w('<h4 id="%s" >%s [<span class="status_%s">%s</span>]</h4>'
-               % (anchor_name(entity.name),
+               % (entity.anchored_name,
                   xml_escape(entity.name), entity.status, entity.status))