From 03b8f4b678324381153e799efe57c0f2ac8168b0 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Aug 31 2014 10:54:29 +0000 Subject: Update the format_loc filter With the new format_loc filter if a commit is provided at the same time as the line of code, the filter will add an extra column (hidden by default) containing the image that the user should click on to add a comment on that line of code. This new filter will also add some meta information used by our tool to find out which row of which commit the comment should be added to. --- diff --git a/progit/__init__.py b/progit/__init__.py index f5d06de..9af0e3c 100644 --- a/progit/__init__.py +++ b/progit/__init__.py @@ -237,7 +237,7 @@ def rst2html(rst_string): @APP.template_filter('format_loc') -def format_loc(loc): +def format_loc(loc, commit=None): """ Template filter putting the provided lines of code into a table """ output = [ @@ -246,9 +246,29 @@ def format_loc(loc): ] cnt = 1 for line in loc.split('\n'): - output.append( - '%s' % ( - cnt, cnt, cnt)) + if commit: + output.append( + '' + '%(cnt)s' + '' + '

' + 'Add comment' + '

' + '' % ( + { + 'cnt': cnt, + 'img': flask.url_for('static', filename='users.png'), + 'commitid': commit.oid.hex, + } + ) + ) + else: + output.append( + '' + '%(cnt)s' + % ({'cnt': cnt}) + ) + cnt += 1 if not line: output.append(line)