Mercurial > kallithea
annotate rhodecode/model/changeset_status.py @ 2432:d3ac7491a5c8 codereview
Share common getter functions in base model, and remove duplicated functions from other models
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 09 Jun 2012 20:23:48 +0200 |
parents | 8447d35b674e |
children | 1bc579bcd67a |
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 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 from rhodecode.model import BaseModel |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2287
diff
changeset
|
29 from rhodecode.model.db import ChangesetStatus |
2216
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 log = logging.getLogger(__name__) |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 class ChangesetStatusModel(BaseModel): |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 def __get_changeset_status(self, changeset_status): |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 return self._get_instance(ChangesetStatus, changeset_status) |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 |
a2987fa580d9
dummy ChangesetStatus model
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 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
|
40 """ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
41 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
|
42 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
|
43 current one |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
44 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
45 :param repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
46 :type repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
47 :param revision: 40char hash |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
48 :type revision: str |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
49 """ |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2287
diff
changeset
|
50 repo = self._get_repo(repo) |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
51 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
52 status = ChangesetStatus.query()\ |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
53 .filter(ChangesetStatus.repo == repo)\ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
54 .filter(ChangesetStatus.revision == revision)\ |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
55 .filter(ChangesetStatus.version == 0).scalar() |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
56 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
|
57 st = status or ChangesetStatus.DEFAULT |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
58 return str(st) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
59 |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
60 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
|
61 """ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
62 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
|
63 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
|
64 |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
65 :param repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
66 :type repo: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
67 :param revision: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
68 :type revision: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
69 :param status: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
70 :type status: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
71 :param user: |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
72 :type user: |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
73 :param comment: |
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
74 :type comment: |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
75 """ |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2287
diff
changeset
|
76 repo = self._get_repo(repo) |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
77 |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
78 cur_statuses = ChangesetStatus.query()\ |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
79 .filter(ChangesetStatus.repo == repo)\ |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
80 .filter(ChangesetStatus.revision == revision)\ |
2287
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
81 .all() |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
82 if cur_statuses: |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
83 for st in cur_statuses: |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
84 st.version += 1 |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
85 self.sa.add(st) |
8447d35b674e
Added simple versioning for changeset status
Marcin Kuzminski <marcin@python-works.com>
parents:
2286
diff
changeset
|
86 new_status = ChangesetStatus() |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2287
diff
changeset
|
87 new_status.author = self._get_user(user) |
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2287
diff
changeset
|
88 new_status.repo = self._get_repo(repo) |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
89 new_status.status = status |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
90 new_status.revision = revision |
2286
9265958e33bb
Show changes of status inside comments
Marcin Kuzminski <marcin@python-works.com>
parents:
2217
diff
changeset
|
91 new_status.comment = comment |
2217
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
92 self.sa.add(new_status) |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
93 return new_status |
76947224bf27
Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents:
2216
diff
changeset
|
94 |