2d471b406299

Add *_level_comments methods to the API and use them.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 02 Mar 2010 19:00:45 -0500
parents 8a546e4e071e
children 597da245ce41
branches/tags (none)
files review/api.py review/extension_ui.py review/web_templates/review.html

Changes

--- a/review/api.py	Tue Mar 02 18:50:26 2010 -0500
+++ b/review/api.py	Tue Mar 02 19:00:45 2010 -0500
@@ -481,11 +481,40 @@
         return ds
     
     
-    @property
     def review_level_comments(self):
         """Comments on this changeset which aren't on a particular file."""
         return filter(lambda c: not c.filename, self.comments)
     
+    def file_level_comments(self, filename=None):
+        """Comments on this changeset that are on a file, but not a line.
+        
+        If a file is given only comments for that file will be returned.
+        """
+        
+        if filename:
+            return filter(
+                lambda c: filename == c.filename and not c.lines, self.comments
+            )
+        else:
+            return filter(
+                lambda c: filename and not c.lines, self.comments
+            )
+    
+    def line_level_comments(self, filename=None):
+        """Comments on this changeset that are on a line of file.
+        
+        If a file is given only comments for that file will be returned.
+        """
+        
+        if filename:
+            return filter(
+                lambda c: filename == c.filename and c.lines, self.comments
+            )
+        else:
+            return filter(
+                lambda c: filename and c.lines, self.comments
+            )
+    
 
 class _ReviewObject(object):
     """A base object for some kind of review data (a signoff or comment)."""
--- a/review/extension_ui.py	Tue Mar 02 18:50:26 2010 -0500
+++ b/review/extension_ui.py	Tue Mar 02 19:00:45 2010 -0500
@@ -153,7 +153,7 @@
     for signoff in rcset.signoffs:
         _print_signoff(signoff, before='\n')
         
-    review_level_comments = rcset.review_level_comments
+    review_level_comments = rcset.review_level_comments()
     if review_level_comments:
         ui.write('\n')
     for comment in review_level_comments:
@@ -172,15 +172,10 @@
         header = messages.REVIEW_LOG_FILE_HEADER % filename
         print '\n\n%s %s' % (header, '-'*(80-(len(header)+1)))
         
-        file_level_comments = filter(
-            lambda c: filename == c.filename and not c.lines, rcset.comments
-        )
-        for comment in file_level_comments:
+        for comment in rcset.file_level_comments(filename):
             _print_comment(comment)
         
-        line_level_comments = filter(
-            lambda c: filename == c.filename and c.lines, rcset.comments
-        )
+        line_level_comments = rcset.line_level_comments(filename)
         prefix = '%%%dd: ' % len(str(content[-1][0]))
         previous_n = -1
         for n, line in content:
--- a/review/web_templates/review.html	Tue Mar 02 18:50:26 2010 -0500
+++ b/review/web_templates/review.html	Tue Mar 02 19:00:45 2010 -0500
@@ -3,7 +3,7 @@
 $ ctx = rd.target[rcset.node]
 <h2>Changeset ${ ctx.rev() }: ${ ctx.description() }</h2>
 
-$ review_level_comments = rcset.review_level_comments
+$ review_level_comments = rcset.review_level_comments()
 $for comment in review_level_comments:
     <div class="comment">
         <div class="avatar"><img height="52" width="52" src="http://www.gravatar.com/avatar/${ md5(email(comment.author)).hexdigest() }?s=52"/></div>
@@ -36,7 +36,7 @@
         </div>
         
         <div class="file-review-contents">
-            $ file_level_comments = filter(lambda c: c.filename == filename and not c.lines, rcset.comments)
+            $ file_level_comments = rcset.file_level_comments(filename)
             $for comment in file_level_comments:
                 <div class="comment">
                     <div class="avatar">
@@ -67,7 +67,7 @@
                 <table>
                     $ max_line = diff['max']
                     $ content = diff['content']
-                    $ line_level_comments = filter(lambda c: c.filename == filename and c.lines, rcset.comments)
+                    $ line_level_comments = rcset.line_level_comments(filename)
                     $ previous_n = -1
                     $for n, line in content:
                         $if n - 1 > previous_n: