[views, schema, pkginfo] Add comments to relevant entities (concerns #2920258).
authorVladimir Popescu <vladimir.popescu@logilab.fr>
Wed, 17 Jul 2013 11:34:50 +0200
changeset 271 1c275b5d6168
parent 270 312bc5dba074
child 272 b38896c3e873
[views, schema, pkginfo] Add comments to relevant entities (concerns #2920258). Thus, we have comments attached to Subject, Center, Scan, GenomicMeasure, QuestionnaireRun, Questionnaire. We don't (as yet) have comments attached to Study, Device. The principle of the work has been to override the primary views of the concerned entitites (except for Scan, where the out of context view has been overridden), via a mix-in which contains a customized renderer.
__init__.py
__pkginfo__.py
schema.py
views/components.py
--- a/__init__.py	Wed Jul 17 11:32:39 2013 +0200
+++ b/__init__.py	Wed Jul 17 11:34:50 2013 +0200
@@ -2,3 +2,7 @@
 
 Cube for the Brainomics Project, see http://www.brainomics.net/
 """
+
+ALL_MEASURES = ('GenericMeasure', 'QuestionnaireRun', 'GenericTestRun', 'Scan', 'GenomicMeasure')
+COMMENTED_ENTITIES = ('Study', 'Subject', 'Center', 'Device', 'Scan', 'GenomicMeasure',
+                      'QuestionnaireRun', 'Questionnaire', 'Question')
--- a/__pkginfo__.py	Wed Jul 17 11:32:39 2013 +0200
+++ b/__pkginfo__.py	Wed Jul 17 11:34:50 2013 +0200
@@ -20,6 +20,7 @@
                 'cubicweb-medicalexp': None,
                 'cubicweb-card': None,
                 'cubicweb-cwbootstrap': None,
+                'cubicweb-comment': None,
                 }
 __recommends__ = {}
 
--- a/schema.py	Wed Jul 17 11:32:39 2013 +0200
+++ b/schema.py	Wed Jul 17 11:34:50 2013 +0200
@@ -25,7 +25,7 @@
 from cubes.genomics.schema import GenomicMeasure, ColumnRef
 from cubes.medicalexp.schema  import Assessment, ProcessingRun, ScoreDef, ScoreValue
 
-ALL_MEASURES = ('GenericMeasure', 'QuestionnaireRun', 'GenericTestRun', 'Scan', 'GenomicMeasure')
+from cubes.brainomics import COMMENTED_ENTITIES
 
 
 # ProcessingRun -> Measure
@@ -82,3 +82,9 @@
 ScoreDef.add_relation(SubjectRelation('Question', cardinality='**'), name='used_by')
 AnatomicalRegion.add_relation(SubjectRelation('ScoreValue', cardinality='**'), name='concerned_by')
 ColumnRef.add_relation(SubjectRelation('Assessment', cardinality='1*', inlined=True), name='assessment')
+
+
+# Comments for entities
+class comments(RelationDefinition):
+    subject = 'Comment'
+    object = COMMENTED_ENTITIES
--- a/views/components.py	Wed Jul 17 11:32:39 2013 +0200
+++ b/views/components.py	Wed Jul 17 11:34:50 2013 +0200
@@ -25,7 +25,7 @@
 from cubicweb.web.views.boxes import SearchBox, EditBox
 from cubicweb.web.views.bookmark import BookmarksBox
 
-from cubes.brainomics.schema import ALL_MEASURES
+from cubes.brainomics import COMMENTED_ENTITIES
 
 
 ################################################################################
@@ -204,6 +204,24 @@
         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)
+
+
+
 ###############################################################################
 ### DOWNLOAD BOXES ############################################################
 ###############################################################################