[primary view] add 'verbatim' attribute view (closes #1947475) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 23 Sep 2011 14:56:13 +0200
branchstable
changeset 7847 7be550fb337b
parent 7844 0208c65a88a5
child 7848 db6bb2da397c
child 7849 7937cf60f2ce
[primary view] add 'verbatim' attribute view (closes #1947475) this patch has been applied to default accidentaly
web/views/cwsources.py
web/views/primary.py
--- a/web/views/cwsources.py	Fri Sep 23 12:40:50 2011 +0200
+++ b/web/views/cwsources.py	Fri Sep 23 14:56:13 2011 +0200
@@ -56,9 +56,9 @@
 _pvdc.tag_attribute(('CWSource', 'type'), {'vid': 'attribute'})# disable reledit
 
 _rc = uicfg.reledit_ctrl
-_rc.tag_attribute(('CWSource', 'config'), {'rvid': 'verbatim'})
-_rc.tag_attribute(('CWSourceHostConfig', 'config'), {'rvid': 'verbatim'})
-_rc.tag_attribute(('CWSourceSchemaConfig', 'options'), {'rvid': 'verbatim'})
+_rc.tag_attribute(('CWSource', 'config'), {'rvid': 'verbatimattr'})
+_rc.tag_attribute(('CWSourceHostConfig', 'config'), {'rvid': 'verbatimattr'})
+_rc.tag_attribute(('CWSourceSchemaConfig', 'options'), {'rvid': 'verbatimattr'})
 
 
 class CWSourcePrimaryView(tabs.TabbedPrimaryView):
--- a/web/views/primary.py	Fri Sep 23 12:40:50 2011 +0200
+++ b/web/views/primary.py	Fri Sep 23 14:56:13 2011 +0200
@@ -34,6 +34,7 @@
 
 .. autoclass:: AttributeView
 .. autoclass:: URLAttributeView
+.. autoclass:: VerbatimAttributeView
 """
 
 __docformat__ = "restructuredtext en"
@@ -421,20 +422,6 @@
                 self.w(u'</div>')
 
 
-class URLAttributeView(EntityView):
-    """:__regid__: *urlattr*
-
-    This view will wrap an attribute value (hence expect a string) into an '<a>'
-    HTML tag to display a clickable link.
-    """
-    __regid__ = 'urlattr'
-    __select__ = EntityView.__select__ & match_kwargs('rtype')
-
-    def entity_call(self, entity, rtype, **kwargs):
-        url = entity.printable_value(rtype)
-        if url:
-            self.w(u'<a href="%s">%s</a>' % (url, url))
-
 class AttributeView(EntityView):
     """:__regid__: *attribute*
 
@@ -455,6 +442,39 @@
                 self.wview('autolimited', rset, initargs={'dispctrl': dispctrl})
 
 
+class URLAttributeView(EntityView):
+    """:__regid__: *urlattr*
+
+    This view will wrap an attribute value (hence expect a string) into an '<a>'
+    HTML tag to display a clickable link.
+    """
+    __regid__ = 'urlattr'
+    __select__ = EntityView.__select__ & match_kwargs('rtype')
+
+    def entity_call(self, entity, rtype, **kwargs):
+        url = entity.printable_value(rtype)
+        if url:
+            self.w(u'<a href="%s">%s</a>' % (url, url))
+
+
+class VerbatimAttributeView(EntityView):
+    """:__regid__: *verbatimattr*
+
+    This view will wrap an attribute value into an '<pre>' HTML tag to display
+    arbitrary text where EOL will be respected. It usually make sense for
+    attributes whose value is a multi-lines string where new lines matters.
+    """
+    __regid__ = 'verbatimattr'
+    __select__ = EntityView.__select__ & match_kwargs('rtype')
+
+    def entity_call(self, entity, rtype, **kwargs):
+        value = entity.printable_value(rtype)
+        if value:
+            self.w(u'<pre>%s</pre>' % value)
+
+
+
+
 
 class ToolbarLayout(component.Layout):
     # XXX include me in the doc