diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py +++ b/rhodecode/controllers/changeset.py @@ -220,10 +220,10 @@ class ChangesetController(BaseRepoContro c.comments.extend(ChangesetCommentsModel()\ .get_comments(c.rhodecode_db_repo.repo_id, - changeset.raw_id)) + revision=changeset.raw_id)) inlines = ChangesetCommentsModel()\ .get_inline_comments(c.rhodecode_db_repo.repo_id, - changeset.raw_id) + revision=changeset.raw_id) c.inline_comments.extend(inlines) c.changes[changeset.raw_id] = [] try: @@ -295,7 +295,7 @@ class ChangesetController(BaseRepoContro ) # count inline comments - for path, lines in c.inline_comments: + for _, lines in c.inline_comments: for comments in lines.values(): c.inline_cnt += len(comments) diff --git a/rhodecode/model/comment.py b/rhodecode/model/comment.py --- a/rhodecode/model/comment.py +++ b/rhodecode/model/comment.py @@ -135,21 +135,44 @@ class ChangesetCommentsModel(BaseModel): return comment - def get_comments(self, repo_id, revision): - return ChangesetComment.query()\ + def get_comments(self, repo_id, revision=None, pull_request_id=None): + """ + Get's main comments based on revision or pull_request_id + + :param repo_id: + :type repo_id: + :param revision: + :type revision: + :param pull_request_id: + :type pull_request_id: + """ + q = ChangesetComment.query()\ .filter(ChangesetComment.repo_id == repo_id)\ - .filter(ChangesetComment.revision == revision)\ .filter(ChangesetComment.line_no == None)\ - .filter(ChangesetComment.f_path == None).all() + .filter(ChangesetComment.f_path == None) + if revision: + q = q.filter(ChangesetComment.revision == revision) + elif pull_request_id: + q = q.filter(ChangesetComment.pull_request_id == pull_request_id) + else: + raise Exception('Please specify revision or pull_request_id') + return q.all() - def get_inline_comments(self, repo_id, revision): - comments = self.sa.query(ChangesetComment)\ + def get_inline_comments(self, repo_id, revision=None, pull_request_id=None): + q = self.sa.query(ChangesetComment)\ .filter(ChangesetComment.repo_id == repo_id)\ - .filter(ChangesetComment.revision == revision)\ .filter(ChangesetComment.line_no != None)\ .filter(ChangesetComment.f_path != None)\ .order_by(ChangesetComment.comment_id.asc())\ - .all() + + if revision: + q = q.filter(ChangesetComment.revision == revision) + elif pull_request_id: + q = q.filter(ChangesetComment.pull_request_id == pull_request_id) + else: + raise Exception('Please specify revision or pull_request_id') + + comments = q.all() paths = defaultdict(lambda: defaultdict(list)) diff --git a/rhodecode/templates/changeset/changeset.html b/rhodecode/templates/changeset/changeset.html --- a/rhodecode/templates/changeset/changeset.html +++ b/rhodecode/templates/changeset/changeset.html @@ -134,8 +134,10 @@ <%namespace name="comment" file="/changeset/changeset_file_comment.html"/> ${comment.comment_inline_form(c.changeset)} - ## render comments - ${comment.comments(c.changeset)} + ## render comments main comments form and it status + ${comment.comments(h.url('changeset_comment', repo_name=c.repo_name, revision=c.changeset.raw_id), + h.changeset_status(c.rhodecode_db_repo, c.changeset.raw_id))} + diff --git a/rhodecode/templates/changeset/changeset_file_comment.html b/rhodecode/templates/changeset/changeset_file_comment.html --- a/rhodecode/templates/changeset/changeset_file_comment.html +++ b/rhodecode/templates/changeset/changeset_file_comment.html @@ -77,7 +77,8 @@ %def> -<%def name="inlines(changeset)"> +## generates inlines taken from c.comments var +<%def name="inlines()">