Mercurial > kallithea
annotate rhodecode/model/comment.py @ 1683:28eeddf81b25 beta
inline comments gui
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 14 Nov 2011 22:20:04 +0200 |
parents | 1bf03daafaf0 |
children | f23828b00b21 |
rev | line source |
---|---|
1670 | 1 # -*- coding: utf-8 -*- |
2 """ | |
3 rhodecode.model.comment | |
4 ~~~~~~~~~~~~~~~~~~~~~~~ | |
5 | |
6 comments model for RhodeCode | |
7 | |
8 :created_on: Nov 11, 2011 | |
9 :author: marcink | |
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> | |
11 :license: GPLv3, see COPYING for more details. | |
12 """ | |
13 # This program is free software: you can redistribute it and/or modify | |
14 # it under the terms of the GNU General Public License as published by | |
15 # the Free Software Foundation, either version 3 of the License, or | |
16 # (at your option) any later version. | |
17 # | |
18 # This program is distributed in the hope that it will be useful, | |
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 # GNU General Public License for more details. | |
22 # | |
23 # You should have received a copy of the GNU General Public License | |
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
25 | |
26 | |
27 import logging | |
28 import traceback | |
29 | |
30 from rhodecode.model import BaseModel | |
31 from rhodecode.model.db import ChangesetComment | |
1675
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
32 from sqlalchemy.util.compat import defaultdict |
1670 | 33 |
34 log = logging.getLogger(__name__) | |
35 | |
36 | |
37 class ChangesetCommentsModel(BaseModel): | |
38 | |
39 | |
1675
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
40 def create(self, text, repo_id, user_id, revision, f_path=None, |
1670 | 41 line_no=None): |
42 """ | |
43 Creates new comment for changeset | |
44 | |
45 :param text: | |
46 :param repo_id: | |
47 :param user_id: | |
1675
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
48 :param revision: |
1670 | 49 :param f_path: |
50 :param line_no: | |
51 """ | |
1677
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
52 if text: |
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
53 comment = ChangesetComment() |
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
54 comment.repo_id = repo_id |
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
55 comment.user_id = user_id |
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
56 comment.revision = revision |
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
57 comment.text = text |
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
58 comment.f_path = f_path |
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
59 comment.line_no = line_no |
1670 | 60 |
1677
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
61 self.sa.add(comment) |
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
62 self.sa.commit() |
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
63 return comment |
1670 | 64 |
65 def delete(self, comment_id): | |
66 """ | |
67 Deletes given comment | |
68 | |
69 :param comment_id: | |
70 """ | |
71 comment = ChangesetComment.get(comment_id) | |
72 self.sa.delete(comment) | |
73 self.sa.commit() | |
74 return comment | |
1675
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
75 |
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
76 |
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
77 def get_comments(self, repo_id, revision): |
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
78 return ChangesetComment.query()\ |
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
79 .filter(ChangesetComment.repo_id == repo_id)\ |
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
80 .filter(ChangesetComment.revision == revision)\ |
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
81 .filter(ChangesetComment.line_no == None)\ |
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
82 .filter(ChangesetComment.f_path == None).all() |
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
83 |
1677
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
84 def get_inline_comments(self, repo_id, revision): |
1675
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
85 comments = self.sa.query(ChangesetComment)\ |
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
86 .filter(ChangesetComment.repo_id == repo_id)\ |
1681
1bf03daafaf0
fixes inline comments double entries
Marcin Kuzminski <marcin@python-works.com>
parents:
1677
diff
changeset
|
87 .filter(ChangesetComment.revision == revision)\ |
1bf03daafaf0
fixes inline comments double entries
Marcin Kuzminski <marcin@python-works.com>
parents:
1677
diff
changeset
|
88 .filter(ChangesetComment.line_no != None)\ |
1bf03daafaf0
fixes inline comments double entries
Marcin Kuzminski <marcin@python-works.com>
parents:
1677
diff
changeset
|
89 .filter(ChangesetComment.f_path != None).all() |
1677
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
90 |
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
91 paths = defaultdict(lambda:defaultdict(list)) |
1675
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
92 |
7c487d2678c7
code refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1670
diff
changeset
|
93 for co in comments: |
1677
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
94 paths[co.f_path][co.line_no].append(co) |
7276b170ce8b
#71 code-review
Marcin Kuzminski <marcin@python-works.com>
parents:
1675
diff
changeset
|
95 return paths.items() |