Mercurial > kallithea
comparison rhodecode/model/comment.py @ 2439:ad19dfcdb1cc codereview
Refactoring of changeset_file_comments for more generic usage. In both It enables sharing code between changeset, and pull requests discussions
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 10 Jun 2012 16:44:06 +0200 |
parents | f29469677319 |
children | 1bc579bcd67a |
comparison
equal
deleted
inserted
replaced
2438:471ac5256400 | 2439:ad19dfcdb1cc |
---|---|
133 comment = self.__get_changeset_comment(comment) | 133 comment = self.__get_changeset_comment(comment) |
134 self.sa.delete(comment) | 134 self.sa.delete(comment) |
135 | 135 |
136 return comment | 136 return comment |
137 | 137 |
138 def get_comments(self, repo_id, revision): | 138 def get_comments(self, repo_id, revision=None, pull_request_id=None): |
139 return ChangesetComment.query()\ | 139 """ |
140 Get's main comments based on revision or pull_request_id | |
141 | |
142 :param repo_id: | |
143 :type repo_id: | |
144 :param revision: | |
145 :type revision: | |
146 :param pull_request_id: | |
147 :type pull_request_id: | |
148 """ | |
149 q = ChangesetComment.query()\ | |
140 .filter(ChangesetComment.repo_id == repo_id)\ | 150 .filter(ChangesetComment.repo_id == repo_id)\ |
141 .filter(ChangesetComment.revision == revision)\ | |
142 .filter(ChangesetComment.line_no == None)\ | 151 .filter(ChangesetComment.line_no == None)\ |
143 .filter(ChangesetComment.f_path == None).all() | 152 .filter(ChangesetComment.f_path == None) |
153 if revision: | |
154 q = q.filter(ChangesetComment.revision == revision) | |
155 elif pull_request_id: | |
156 q = q.filter(ChangesetComment.pull_request_id == pull_request_id) | |
157 else: | |
158 raise Exception('Please specify revision or pull_request_id') | |
159 return q.all() | |
144 | 160 |
145 def get_inline_comments(self, repo_id, revision): | 161 def get_inline_comments(self, repo_id, revision=None, pull_request_id=None): |
146 comments = self.sa.query(ChangesetComment)\ | 162 q = self.sa.query(ChangesetComment)\ |
147 .filter(ChangesetComment.repo_id == repo_id)\ | 163 .filter(ChangesetComment.repo_id == repo_id)\ |
148 .filter(ChangesetComment.revision == revision)\ | |
149 .filter(ChangesetComment.line_no != None)\ | 164 .filter(ChangesetComment.line_no != None)\ |
150 .filter(ChangesetComment.f_path != None)\ | 165 .filter(ChangesetComment.f_path != None)\ |
151 .order_by(ChangesetComment.comment_id.asc())\ | 166 .order_by(ChangesetComment.comment_id.asc())\ |
152 .all() | 167 |
168 if revision: | |
169 q = q.filter(ChangesetComment.revision == revision) | |
170 elif pull_request_id: | |
171 q = q.filter(ChangesetComment.pull_request_id == pull_request_id) | |
172 else: | |
173 raise Exception('Please specify revision or pull_request_id') | |
174 | |
175 comments = q.all() | |
153 | 176 |
154 paths = defaultdict(lambda: defaultdict(list)) | 177 paths = defaultdict(lambda: defaultdict(list)) |
155 | 178 |
156 for co in comments: | 179 for co in comments: |
157 paths[co.f_path][co.line_no].append(co) | 180 paths[co.f_path][co.line_no].append(co) |