Mercurial > kallithea
changeset 4817:0ee5a36aaa99
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
author | Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com> |
---|---|
date | Tue, 27 Jan 2015 21:57:38 +0100 |
parents | 2b132bc99d6c |
children | 051624cb5f3a |
files | kallithea/templates/changeset/changeset.html kallithea/templates/changeset/changeset_file_comment.html kallithea/templates/pullrequests/pullrequest_show.html kallithea/tests/functional/test_changeset_comments.py |
diffstat | 4 files changed, 31 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/templates/changeset/changeset.html Wed Feb 11 02:40:28 2015 +0100 +++ b/kallithea/templates/changeset/changeset.html Tue Jan 27 21:57:38 2015 +0100 @@ -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 @@ ${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 @@ % endif ## template for inline comment form - <%namespace name="comment" file="/changeset/changeset_file_comment.html"/> ${comment.comment_inline_form()} ## render comments and inlines
--- a/kallithea/templates/changeset/changeset_file_comment.html Wed Feb 11 02:40:28 2015 +0100 +++ b/kallithea/templates/changeset/changeset_file_comment.html Tue Jan 27 21:57:38 2015 +0100 @@ -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))}">
--- a/kallithea/templates/pullrequests/pullrequest_show.html Wed Feb 11 02:40:28 2015 +0100 +++ b/kallithea/templates/pullrequests/pullrequest_show.html Tue Jan 27 21:57:38 2015 +0100 @@ -1,5 +1,7 @@ <%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 @@ <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 @@ ## template for inline comment form - <%namespace name="comment" file="/changeset/changeset_file_comment.html"/> ${comment.comment_inline_form()} ## render comments and inlines
--- a/kallithea/tests/functional/test_changeset_comments.py Wed Feb 11 02:40:28 2015 +0100 +++ b/kallithea/tests/functional/test_changeset_comments.py Tue Jan 27 21:57:38 2015 +0100 @@ -41,8 +41,10 @@ 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 @@ #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 @@ 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 @@ 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)''' + )