[wiki] Add a wiki for documentation on some generic entities
authorVladimir Popescu <vladimir.popescu@logilab.fr>
Wed, 17 Jul 2013 11:37:10 +0200
changeset 274 2bebd692dedc
parent 273 2c57070b1d1f
child 275 e52dd8d14a58
[wiki] Add a wiki for documentation on some generic entities
__init__.py
schema.py
views/components.py
--- a/__init__.py	Mon Jul 15 14:09:22 2013 +0200
+++ b/__init__.py	Wed Jul 17 11:37:10 2013 +0200
@@ -6,3 +6,4 @@
 ALL_MEASURES = ('GenericMeasure', 'QuestionnaireRun', 'GenericTestRun', 'Scan', 'GenomicMeasure')
 COMMENTED_ENTITIES = ('Study', 'Subject', 'Center', 'Device', 'Scan', 'GenomicMeasure',
                       'QuestionnaireRun', 'Questionnaire', 'Question')
+WIKI_ENTITIES = ('Question', 'Questionnaire', 'Study', 'ScoreDef')
--- a/schema.py	Mon Jul 15 14:09:22 2013 +0200
+++ b/schema.py	Wed Jul 17 11:37:10 2013 +0200
@@ -25,7 +25,7 @@
 from cubes.genomics.schema import GenomicMeasure, ColumnRef
 from cubes.medicalexp.schema  import Assessment, ProcessingRun, ScoreDef, ScoreValue
 
-from cubes.brainomics import COMMENTED_ENTITIES
+from cubes.brainomics import COMMENTED_ENTITIES, WIKI_ENTITIES
 
 
 # ProcessingRun -> Measure
@@ -88,3 +88,9 @@
 class comments(RelationDefinition):
     subject = 'Comment'
     object = COMMENTED_ENTITIES
+
+# Links to "Wikis" / Cards
+class wiki(RelationDefinition):
+    subject = WIKI_ENTITIES
+    object = 'Card'
+    cardinality = '**'
--- a/views/components.py	Mon Jul 15 14:09:22 2013 +0200
+++ b/views/components.py	Wed Jul 17 11:37:10 2013 +0200
@@ -25,7 +25,7 @@
 from cubicweb.web.views.boxes import SearchBox, EditBox
 from cubicweb.web.views.bookmark import BookmarksBox
 
-from cubes.brainomics import COMMENTED_ENTITIES
+from cubes.brainomics import COMMENTED_ENTITIES, WIKI_ENTITIES
 
 
 ################################################################################
@@ -221,6 +221,23 @@
             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(rset=card_rset))
+        else:
+            w(u'<div>%s</div>' % self._cw._('No documentation available'))
+
 
 ###############################################################################
 ### DOWNLOAD BOXES ############################################################