Mercurial > kallithea
annotate rhodecode/model/changeset_status.py @ 2364:9d61aad859bc codereview
code garden
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 30 May 2012 23:12:24 +0200 |
parents | 8447d35b674e |
children | d3ac7491a5c8 |
rev | line source |
---|---|
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 rhodecode.model.changeset_status |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 :created_on: Apr 30, 2012 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 :author: marcink |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 :license: GPLv3, see COPYING for more details. |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 """ |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 # This program is free software: you can redistribute it and/or modify |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # it under the terms of the GNU General Public License as published by |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # the Free Software Foundation, either version 3 of the License, or |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # (at your option) any later version. |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # This program is distributed in the hope that it will be useful, |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # GNU General Public License for more details. |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # You should have received a copy of the GNU General Public License |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 import logging |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 import traceback |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 from pylons.i18n.translation import _ |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 from rhodecode.lib.utils2 import safe_unicode |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 from rhodecode.model import BaseModel |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
33 from rhodecode.model.db import ChangesetStatus, Repository, User |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 log = logging.getLogger(__name__) |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 class ChangesetStatusModel(BaseModel): |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 def __get_changeset_status(self, changeset_status): |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 return self._get_instance(ChangesetStatus, changeset_status) |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
43 def __get_repo(self, repository): |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
44 return self._get_instance(Repository, repository, |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
45 callback=Repository.get_by_repo_name) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
46 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
47 def __get_user(self, user): |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
48 return self._get_instance(User, user, callback=User.get_by_username) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
49 |
2216
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 def get_status(self, repo, revision): |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
51 """ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
52 Returns status of changeset for given revision and version 0 |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
53 versioning makes a history of statuses, and version == 0 is always the |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
54 current one |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
55 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
56 :param repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
57 :type repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
58 :param revision: 40char hash |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
59 :type revision: str |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
60 """ |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
61 repo = self.__get_repo(repo) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
62 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
63 status = ChangesetStatus.query()\ |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
64 .filter(ChangesetStatus.repo == repo)\ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
65 .filter(ChangesetStatus.revision == revision)\ |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
66 .filter(ChangesetStatus.version == 0).scalar() |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
67 status = status.status if status else status |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
68 st = status or ChangesetStatus.DEFAULT |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
69 return str(st) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
70 |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
71 def set_status(self, repo, revision, status, user, comment): |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
72 """ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
73 Creates new status for changeset or updates the old ones bumping their |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
74 version, leaving the current status at |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
75 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
76 :param repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
77 :type repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
78 :param revision: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
79 :type revision: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
80 :param status: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
81 :type status: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
82 :param user: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
83 :type user: |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
84 :param comment: |
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
85 :type comment: |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
86 """ |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
87 repo = self.__get_repo(repo) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
88 |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
89 cur_statuses = ChangesetStatus.query()\ |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
90 .filter(ChangesetStatus.repo == repo)\ |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
91 .filter(ChangesetStatus.revision == revision)\ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
92 .all() |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
93 if cur_statuses: |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
94 for st in cur_statuses: |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
95 st.version += 1 |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
96 self.sa.add(st) |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
97 new_status = ChangesetStatus() |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
98 new_status.author = self.__get_user(user) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
99 new_status.repo = self.__get_repo(repo) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
100 new_status.status = status |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
101 new_status.revision = revision |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
102 new_status.comment = comment |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
103 self.sa.add(new_status) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
104 return new_status |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
105 |