Changeset - 0ee5a36aaa99
[Not reviewed]
default
0 4 0
Thomas De Schampheleire - 11 years ago 2015-01-27 21:57:38
thomas.de_schampheleire@alcatel-lucent.com
comment handling: factorize comment count logic

Avoid duplicating the logic to show the number of comments in three
templates (pull request, changeset, changeset comment area) by placing it in
a function.

In tests:
- take into account new line wrapping
- remove pointless %s substitution for fixed values
4 files changed with 31 insertions and 13 deletions:
0 comments (0 inline, 0 general)
kallithea/templates/changeset/changeset.html
Show inline comments
 
@@ -2,6 +2,8 @@
 

	
 
<%inherit file="/base/base.html"/>
 

	
 
<%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
 

	
 
<%block name="title">
 
    ${_('%s Changeset') % c.repo_name} - ${h.show_id(c.changeset)}
 
    %if c.site_name:
 
@@ -64,7 +66,9 @@ ${self.repo_context_bar('changelog', c.c
 
                  ${c.ignorews_url(request.GET)}
 
                  ${c.context_url(request.GET)}
 
                </div>
 
                <div class="comments-number" style="float:right;padding-right:5px">${ungettext("%d comment", "%d comments", len(c.comments)) % len(c.comments)} ${ungettext("(%d inline)", "(%d inline)", c.inline_cnt) % c.inline_cnt} <span class="firstlink"></span> </div>
 
                <div class="comments-number" style="float:right;padding-right:5px">
 
                    ${comment.comment_count(c.inline_cnt, len(c.comments))}
 
                </div>
 
            </div>
 
        </div>
 
        <div id="changeset_content">
 
@@ -166,7 +170,6 @@ ${self.repo_context_bar('changelog', c.c
 
    % endif
 

	
 
    ## template for inline comment form
 
    <%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
 
    ${comment.comment_inline_form()}
 

	
 
    ## render comments and inlines
kallithea/templates/changeset/changeset_file_comment.html
Show inline comments
 
@@ -108,9 +108,17 @@
 
</%def>
 

	
 

	
 
## show comment count
 
<%def name="comment_count(inline_cnt, general_cnt)">
 
${ungettext("%d comment", "%d comments", general_cnt) % general_cnt} ${ungettext("(%d inline)", "(%d inline)", inline_cnt) % inline_cnt}
 
<span class="firstlink"></span>
 
</%def>
 

	
 
## generates inlines taken from c.comments var
 
<%def name="inlines()">
 
    <div class="comments-number">${ungettext("%d comment", "%d comments", len(c.comments)) % len(c.comments)} ${ungettext("(%d inline)", "(%d inline)", c.inline_cnt) % c.inline_cnt} <span class="firstlink"></span> </div>
 
    <div class="comments-number">
 
        ${comment_count(c.inline_cnt, len(c.comments))}
 
    </div>
 
    %for path, lines in c.inline_comments:
 
        % for line,comments in lines.iteritems():
 
            <div style="display:none" class="inline-comment-placeholder" path="${path}" target_id="${h.safeid(h.safe_unicode(path))}">
kallithea/templates/pullrequests/pullrequest_show.html
Show inline comments
 
<%inherit file="/base/base.html"/>
 

	
 
<%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
 

	
 
<%block name="title">
 
    ${_('%s Pull Request #%s') % (c.repo_name, c.pull_request.pull_request_id)}
 
    %if c.site_name:
 
@@ -265,7 +267,7 @@ ${self.repo_context_bar('showpullrequest
 
    <div class="table">
 
          <div id="changeset_compare_view_content">
 
              <div style="font-size:1.1em;font-weight: bold;clear:both;padding-top:10px">
 
                ${ungettext("%d comment", "%d comments", len(c.comments)) % len(c.comments)} ${ungettext("(%d inline)", "(%d inline)", c.inline_cnt) % c.inline_cnt} <span class="firstlink"></span>
 
                  ${comment.comment_count(c.inline_cnt, len(c.comments))}
 
              </div>
 
              ##CS
 
              <div style="font-size:1.1em;font-weight: bold;clear:both;padding-top:10px">
 
@@ -331,7 +333,6 @@ ${self.repo_context_bar('showpullrequest
 

	
 

	
 
    ## template for inline comment form
 
    <%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
 
    ${comment.comment_inline_form()}
 

	
 
    ## render comments and inlines
kallithea/tests/functional/test_changeset_comments.py
Show inline comments
 
@@ -41,8 +41,10 @@ class TestChangeSetCommentsController(Te
 
                                repo_name=HG_REPO, revision=rev))
 
        # test DB
 
        self.assertEqual(ChangesetComment.query().count(), 1)
 
        response.mustcontain('''<div class="comments-number">%s comment '''
 
                             '''(0 inline)''' % 1)
 
        response.mustcontain(
 
            '''<div class="comments-number">'''
 
            ''' 1 comment (0 inline)'''
 
        )
 

	
 
        self.assertEqual(Notification.query().count(), 1)
 
        self.assertEqual(ChangesetComment.query().count(), 1)
 
@@ -77,8 +79,8 @@ class TestChangeSetCommentsController(Te
 
        #test DB
 
        self.assertEqual(ChangesetComment.query().count(), 1)
 
        response.mustcontain(
 
            '''<div class="comments-number">0 comments'''
 
            ''' (%s inline)''' % 1
 
            '''<div class="comments-number">'''
 
            ''' 0 comments (1 inline)'''
 
        )
 
        response.mustcontain(
 
            '''<div style="display:none" class="inline-comment-placeholder" '''
 
@@ -116,8 +118,10 @@ class TestChangeSetCommentsController(Te
 
                                repo_name=HG_REPO, revision=rev))
 
        # test DB
 
        self.assertEqual(ChangesetComment.query().count(), 1)
 
        response.mustcontain('''<div class="comments-number">%s '''
 
                             '''comment (0 inline)''' % 1)
 
        response.mustcontain(
 
            '''<div class="comments-number">'''
 
            ''' 1 comment (0 inline)'''
 
        )
 

	
 
        self.assertEqual(Notification.query().count(), 2)
 
        users = [x.user.username for x in UserNotification.query().all()]
 
@@ -149,5 +153,7 @@ class TestChangeSetCommentsController(Te
 

	
 
        response = self.app.get(url(controller='changeset', action='index',
 
                                repo_name=HG_REPO, revision=rev))
 
        response.mustcontain('''<div class="comments-number">0 comments'''
 
                             ''' (0 inline)''')
 
        response.mustcontain(
 
            '''<div class="comments-number">'''
 
            ''' 0 comments (0 inline)'''
 
        )
0 comments (0 inline, 0 general)