diff options
author | Marcin Kuzminski <marcin@python-works.com> | 2012-06-10 16:44:06 +0200 |
---|---|---|
committer | Marcin Kuzminski <marcin@python-works.com> | 2012-06-10 16:44:06 +0200 |
commit | b738f36d16e31761f0e0c74fc98da986025acb5e (patch) | |
tree | 471944c2f29c1766959e8505f266ac3091ae68f2 /rhodecode/model/comment.py | |
parent | 8e2add2cf060ce6d3aac41d77f45b9529cddd062 (diff) |
Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
--HG--
branch : codereview
Diffstat (limited to 'rhodecode/model/comment.py')
-rw-r--r-- | rhodecode/model/comment.py | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/rhodecode/model/comment.py b/rhodecode/model/comment.py index bd59e3f1..cdd55cf7 100644 --- 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() - - def get_inline_comments(self, repo_id, revision): - comments = self.sa.query(ChangesetComment)\ + .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=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)) |