[views] Split tabs in a new file
authorVincent Michel <vincent.michel@logilab.fr>
Wed, 17 Jul 2013 10:37:26 +0200
changeset 283 2920bacd4257
parent 282 46a66880dbce
child 284 6b889bd4625d
[views] Split tabs in a new file
views/components.py
views/tabs.py
--- a/views/components.py	Wed Jul 17 11:56:02 2013 +0200
+++ b/views/components.py	Wed Jul 17 10:37:26 2013 +0200
@@ -161,86 +161,6 @@
 
 
 ###############################################################################
-### TABBLABLE COMPONENTS ######################################################
-###############################################################################
-class BrainomicsTabblableSelectionComponent(component.CtxComponent):
-    """ Component of selection of the different tabs
-    """
-    __select__ = component.CtxComponent.__select__ & nonempty_rset()
-    context = 'nav-toolbar'
-    __regid__ = 'tabblable-select-ctx'
-
-    def render(self, w, **kwargs):
-        if 'ctx-entity-tabs' in self._cw.vreg:
-            tabs = list(self._cw.vreg['ctx-entity-tabs'].possible_objects(self._cw,
-                                                                          rset=self.cw_rset))
-        else:
-            tabs = []
-        if tabs:
-            w(u'<ul class="nav nav-pills" id="entity-tab">')
-            # Main info
-            w(u'<li class="active"><a href="#entity-mainview" data-toggle="pill" '
-              'class="bnt btn-warning">%s</a></li>' % xml_escape(self._cw._('Main info')))
-            # Other tabs
-            for tab in tabs:
-                w(u'<li><a href="#%s" data-toggle="pill" class="bnt btn-warning">%s</a></li>'
-                  % (tab.__regid__, tab.get_title()))
-            w(u'</ul>')
-
-
-class AbstractBrainomicsTabblable(component.EntityCtxComponent):
-    """ Component used to display a tab. """
-    __abstract__ = True
-    __registry__ = 'ctx-entity-tabs'
-
-    def get_title(self):
-        return
-
-    def render_content(self, w, **kwargs):
-        return
-
-    def render(self, w, **kwargs):
-        w(u'<div class="tab-pane" id="%s">' % self.__regid__)
-        self.render_content(w)
-        w(u'</div>')
-
-
-class BrainomicsTabblableComment(AbstractBrainomicsTabblable):
-    """ Component used to display a tab with comment. """
-    __select__ = AbstractBrainomicsTabblable.__select__ & is_instance(*COMMENTED_ENTITIES)
-    __regid__ = 'entity-comment-tab'
-
-    def get_title(self):
-        return self._cw._('Comments')
-
-    def render_content(self, w, **kwargs):
-        entity = self.cw_rset.get_entity(0, 0)
-        comp = self._cw.vreg['ctxcomponents'].select_or_none('commentsection',
-                                                             self._cw, rset=self.cw_rset,
-                                                             entity=entity, __cache=None)
-        if comp is not None:
-            comp.render(w=w)
-
-
-class BrainomicsTabblableWiki(AbstractBrainomicsTabblable):
-    """ Component used to display a tab with wiki. """
-    __select__ = AbstractBrainomicsTabblable.__select__ & is_instance(*WIKI_ENTITIES)
-    __regid__ = 'entity-comment-tab'
-
-    def get_title(self):
-        return self._cw._('Documentation')
-
-    def render_content(self, w, **kwargs):
-        entity = self.cw_rset.get_entity(0, 0)
-        card_rset = self._cw.execute('Any X WHERE X is Card, Q wiki X, Q eid %(eid)s',
-                                {'eid': entity.eid})
-        if card_rset:
-            w(self._cw.view('documentation_card', rset=card_rset))
-        else:
-            w(u'<div>%s</div>' % self._cw._('No documentation available'))
-
-
-###############################################################################
 ### ADMIN ACTION/BOX ##########################################################
 ###############################################################################
 class BrainomicsEditBox(EditBox):
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/views/tabs.py	Wed Jul 17 10:37:26 2013 +0200
@@ -0,0 +1,102 @@
+# -*- coding: utf-8 -*-
+# copyright 2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2013 CEA (Saclay, FRANCE), all rights reserved.
+# contact http://www.logilab.fr -- mailto:contact@logilab.fr
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from cubicweb.predicates import is_instance, nonempty_rset
+from cubicweb.web import component
+
+from cubes.brainomics.schema import COMMENTED_ENTITIES, WIKI_ENTITIES
+
+
+###############################################################################
+### TABBLABLE COMPONENTS ######################################################
+###############################################################################
+class BrainomicsTabblableSelectionComponent(component.CtxComponent):
+    """ Component of selection of the different tabs
+    """
+    __select__ = component.CtxComponent.__select__ & nonempty_rset()
+    context = 'nav-toolbar'
+    __regid__ = 'tabblable-select-ctx'
+
+    def render(self, w, **kwargs):
+        if 'ctx-entity-tabs' in self._cw.vreg:
+            tabs = list(self._cw.vreg['ctx-entity-tabs'].possible_objects(self._cw,
+                                                                          rset=self.cw_rset))
+        else:
+            tabs = []
+        if tabs:
+            w(u'<ul class="nav nav-pills" id="entity-tab">')
+            # Main info
+            w(u'<li class="active"><a href="#entity-mainview" data-toggle="pill" '
+              'class="bnt btn-warning">%s</a></li>' % xml_escape(self._cw._('Main info')))
+            # Other tabs
+            for tab in tabs:
+                w(u'<li><a href="#%s" data-toggle="pill" class="bnt btn-warning">%s</a></li>'
+                  % (tab.__regid__, tab.get_title()))
+            w(u'</ul>')
+
+
+class AbstractBrainomicsTabblable(component.EntityCtxComponent):
+    """ Component used to display a tab. """
+    __abstract__ = True
+    __registry__ = 'ctx-entity-tabs'
+
+    def get_title(self):
+        return
+
+    def render_content(self, w, **kwargs):
+        return
+
+    def render(self, w, **kwargs):
+        w(u'<div class="tab-pane" id="%s">' % self.__regid__)
+        self.render_content(w)
+        w(u'</div>')
+
+
+class BrainomicsTabblableComment(AbstractBrainomicsTabblable):
+    """ Component used to display a tab with comment. """
+    __select__ = AbstractBrainomicsTabblable.__select__ & is_instance(*COMMENTED_ENTITIES)
+    __regid__ = 'entity-comment-tab'
+
+    def get_title(self):
+        return self._cw._('Comments')
+
+    def render_content(self, w, **kwargs):
+        entity = self.cw_rset.get_entity(0, 0)
+        comp = self._cw.vreg['ctxcomponents'].select_or_none('commentsection',
+                                                             self._cw, rset=self.cw_rset,
+                                                             entity=entity, __cache=None)
+        if comp is not None:
+            comp.render(w=w)
+
+
+class BrainomicsTabblableWiki(AbstractBrainomicsTabblable):
+    """ Component used to display a tab with wiki. """
+    __select__ = AbstractBrainomicsTabblable.__select__ & is_instance(*WIKI_ENTITIES)
+    __regid__ = 'entity-comment-tab'
+
+    def get_title(self):
+        return self._cw._('Documentation')
+
+    def render_content(self, w, **kwargs):
+        entity = self.cw_rset.get_entity(0, 0)
+        card_rset = self._cw.execute('Any X WHERE X is Card, Q wiki X, Q eid %(eid)s',
+                                {'eid': entity.eid})
+        if card_rset:
+            w(self._cw.view('documentation_card', rset=card_rset))
+        else:
+            w(u'<div>%s</div>' % self._cw._('No documentation available'))