annotate rhodecode/model/changeset_status.py @ 2244:77e376fdc4c6 codereview

pull requests draft UI
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 08 May 2012 02:04:28 +0200
parents 76947224bf27
children 9265958e33bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 """
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
52 Returns status of changeset for given revision
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
53
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
54 :param repo:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
55 :type repo:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
56 :param revision: 40char hash
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
57 :type revision: str
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
58 """
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
59 repo = self.__get_repo(repo)
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 status = ChangesetStatus.query()\
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
62 .filter(ChangesetStatus.repo == repo)\
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
63 .filter(ChangesetStatus.revision == revision).scalar()
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
64 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
65 st = status or ChangesetStatus.DEFAULT
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
66 return str(st)
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
67
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
68 def set_status(self, repo, revision, status, user):
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
69 """
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
70 Creates new status for changeset or updates the old one
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
71
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
72 :param repo:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
73 :type repo:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
74 :param revision:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
75 :type revision:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
76 :param status:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
77 :type status:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
78 :param user:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
79 :type user:
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
80 """
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
81 repo = self.__get_repo(repo)
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
82
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
83 cur_status = ChangesetStatus.query()\
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
84 .filter(ChangesetStatus.repo == repo)\
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
85 .filter(ChangesetStatus.revision == revision)\
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
86 .scalar()
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
87 new_status = cur_status or ChangesetStatus()
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
88 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
89 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
90 new_status.status = status
76947224bf27 Implemented initial code-review status of changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2216
diff changeset
91 new_status.revision = revision
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