Mercurial > kallithea
annotate rhodecode/controllers/forks.py @ 2215:2c2bdaeca912 codereview
code-review initial
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 30 Apr 2012 12:32:29 +0200 |
parents | 162bf5c978f8 |
children | 133209bf300c |
rev | line source |
---|---|
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 rhodecode.controllers.forks |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 forks controller for rhodecode |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 :created_on: Apr 23, 2011 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :author: marcink |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1807
diff
changeset
|
10 :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 """ |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # (at your option) any later version. |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # This program is distributed in the hope that it will be useful, |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # GNU General Public License for more details. |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 import logging |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
26 import formencode |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
27 import traceback |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
28 from formencode import htmlfill |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
30 from pylons import tmpl_context as c, request, url |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
31 from pylons.controllers.util import redirect |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
32 from pylons.i18n.translation import _ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
33 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
34 import rhodecode.lib.helpers as h |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 from rhodecode.lib.helpers import Page |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
37 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator, \ |
2176
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
38 NotAnonymous, HasRepoPermissionAny |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 from rhodecode.lib.base import BaseRepoController, render |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
40 from rhodecode.model.db import Repository, RepoGroup, UserFollowing, User |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
41 from rhodecode.model.repo import RepoModel |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
42 from rhodecode.model.forms import RepoForkForm |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 log = logging.getLogger(__name__) |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 class ForksController(BaseRepoController): |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 @LoginRequired() |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 def __before__(self): |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 super(ForksController, self).__before__() |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
53 def __load_defaults(self): |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
54 c.repo_groups = RepoGroup.groups_choices() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
55 c.repo_groups_choices = map(lambda k: unicode(k[0]), c.repo_groups) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
56 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
57 def __load_data(self, repo_name=None): |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
58 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
59 Load defaults settings for edit, and update |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
60 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
61 :param repo_name: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
62 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
63 self.__load_defaults() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
64 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
65 c.repo_info = db_repo = Repository.get_by_repo_name(repo_name) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
66 repo = db_repo.scm_instance |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
67 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
68 if c.repo_info is None: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
69 h.flash(_('%s repository is not mapped to db perhaps' |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
70 ' it was created or renamed from the filesystem' |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
71 ' please run the application again' |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
72 ' in order to rescan repositories') % repo_name, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
73 category='error') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
74 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
75 return redirect(url('repos')) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
76 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
77 c.default_user_id = User.get_by_username('default').user_id |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
78 c.in_public_journal = UserFollowing.query()\ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
79 .filter(UserFollowing.user_id == c.default_user_id)\ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
80 .filter(UserFollowing.follows_repository == c.repo_info).scalar() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
81 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
82 if c.repo_info.stats: |
1807
1635a21485d6
- fixed issue with missing commits on some repos commands
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
83 last_rev = c.repo_info.stats.stat_on_revision+1 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
84 else: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
85 last_rev = 0 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
86 c.stats_revision = last_rev |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
87 |
1807
1635a21485d6
- fixed issue with missing commits on some repos commands
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
88 c.repo_last_rev = repo.count() if repo.revisions else 0 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
89 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
90 if last_rev == 0 or c.repo_last_rev == 0: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
91 c.stats_percentage = 0 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
92 else: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
93 c.stats_percentage = '%.2f' % ((float((last_rev)) / |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
94 c.repo_last_rev) * 100) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
95 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
96 defaults = RepoModel()._get_defaults(repo_name) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
97 # add prefix to fork |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
98 defaults['repo_name'] = 'fork-' + defaults['repo_name'] |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
99 return defaults |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
100 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
101 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
102 'repository.admin') |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 def forks(self, repo_name): |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 p = int(request.params.get('page', 1)) |
1375
f9559677c953
added tests for forks and followers pages
Marcin Kuzminski <marcin@python-works.com>
parents:
1301
diff
changeset
|
105 repo_id = c.rhodecode_db_repo.repo_id |
2176
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
106 d = [] |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
107 for r in Repository.get_repo_forks(repo_id): |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
108 if not HasRepoPermissionAny( |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
109 'repository.read', 'repository.write', 'repository.admin' |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
110 )(r.repo_name, 'get forks check'): |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
111 continue |
162bf5c978f8
fixed missing permissions check on forks page
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
112 d.append(r) |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 c.forks_pager = Page(d, page=p, items_per_page=20) |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 c.forks_data = render('/forks/forks_data.html') |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 |
1421
c6b811f11c94
Javascripts rewrite: updated yui to latest 2.9, simplified ajax loading for multiple pages. Removed YUI dev package
Marcin Kuzminski <marcin@python-works.com>
parents:
1375
diff
changeset
|
117 if request.environ.get('HTTP_X_PARTIAL_XHR'): |
1301
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
118 return c.forks_data |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 |
7e75af301842
Added simple forks page, resolves issue #179
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 return render('/forks/forks.html') |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
121 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
122 @NotAnonymous() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
123 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
124 'repository.admin') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
125 def fork(self, repo_name): |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
126 c.repo_info = Repository.get_by_repo_name(repo_name) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
127 if not c.repo_info: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
128 h.flash(_('%s repository is not mapped to db perhaps' |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
129 ' it was created or renamed from the file system' |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
130 ' please run the application again' |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
131 ' in order to rescan repositories') % repo_name, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
132 category='error') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
133 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
134 return redirect(url('home')) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
135 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
136 defaults = self.__load_data(repo_name) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
137 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
138 return htmlfill.render( |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
139 render('forks/fork.html'), |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
140 defaults=defaults, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
141 encoding="UTF-8", |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
142 force_defaults=False |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
143 ) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
144 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
145 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
146 @NotAnonymous() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
147 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
148 'repository.admin') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
149 def fork_create(self, repo_name): |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
150 self.__load_defaults() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
151 c.repo_info = Repository.get_by_repo_name(repo_name) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
152 _form = RepoForkForm(old_data={'repo_type': c.repo_info.repo_type}, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
153 repo_groups=c.repo_groups_choices,)() |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
154 form_result = {} |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
155 try: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
156 form_result = _form.to_python(dict(request.POST)) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
157 # add org_path of repo so we can do a clone from it later |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
158 form_result['org_path'] = c.repo_info.repo_name |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
159 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
160 # create fork is done sometimes async on celery, db transaction |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
161 # management is handled there. |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
162 RepoModel().create_fork(form_result, self.rhodecode_user) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
163 h.flash(_('forked %s repository as %s') \ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
164 % (repo_name, form_result['repo_name']), |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
165 category='success') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
166 except formencode.Invalid, errors: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
167 c.new_repo = errors.value['repo_name'] |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
168 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
169 return htmlfill.render( |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
170 render('forks/fork.html'), |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
171 defaults=errors.value, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
172 errors=errors.error_dict or {}, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
173 prefix_error=False, |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
174 encoding="UTF-8") |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
175 except Exception: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
176 log.error(traceback.format_exc()) |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
177 h.flash(_('An error occurred during repository forking %s') % |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
178 repo_name, category='error') |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
179 |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1421
diff
changeset
|
180 return redirect(url('home')) |