Show More
@@ -16,11 +16,6 b'' | |||
|
16 | 16 | # along with this program; if not, write to the Free Software |
|
17 | 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 | 18 | # MA 02110-1301, USA. |
|
19 | """ | |
|
20 | Created on April 7, 2010 | |
|
21 | admin controller for pylons | |
|
22 | @author: marcink | |
|
23 | """ | |
|
24 | 19 | from formencode import htmlfill |
|
25 | 20 | from operator import itemgetter |
|
26 | 21 | from pylons import request, response, session, tmpl_context as c, url |
@@ -35,6 +30,12 b' from pylons_app.model.hg_model import Hg' | |||
|
35 | 30 | from pylons_app.model.repo_model import RepoModel |
|
36 | 31 | import formencode |
|
37 | 32 | import logging |
|
33 | import traceback | |
|
34 | """ | |
|
35 | Created on April 7, 2010 | |
|
36 | admin controller for pylons | |
|
37 | @author: marcink | |
|
38 | """ | |
|
38 | 39 | log = logging.getLogger(__name__) |
|
39 | 40 | |
|
40 | 41 | class ReposController(BaseController): |
@@ -62,6 +63,7 b' class ReposController(BaseController):' | |||
|
62 | 63 | # url('repos') |
|
63 | 64 | repo_model = RepoModel() |
|
64 | 65 | _form = RepoForm()() |
|
66 | form_result = None | |
|
65 | 67 | try: |
|
66 | 68 | form_result = _form.to_python(dict(request.POST)) |
|
67 | 69 | repo_model.create(form_result, c.hg_app_user) |
@@ -70,16 +72,22 b' class ReposController(BaseController):' | |||
|
70 | 72 | category='success') |
|
71 | 73 | |
|
72 | 74 | except formencode.Invalid as errors: |
|
73 | c.form_errors = errors.error_dict | |
|
74 | 75 | c.new_repo = errors.value['repo_name'] |
|
75 | 76 | return htmlfill.render( |
|
76 |
|
|
|
77 | render('admin/repos/repo_add.html'), | |
|
77 | 78 | defaults=errors.value, |
|
78 | encoding="UTF-8") | |
|
79 | errors=errors.error_dict or {}, | |
|
80 | prefix_error=False, | |
|
81 | encoding="UTF-8") | |
|
79 | 82 | |
|
80 | 83 | except Exception: |
|
81 | h.flash(_('error occured during creation of repository %s') \ | |
|
82 | % form_result['repo_name'], category='error') | |
|
84 | log.error(traceback.format_exc()) | |
|
85 | if form_result: | |
|
86 | msg = _('error occured during creation of repository %s') \ | |
|
87 | % form_result['repo_name'] | |
|
88 | else: | |
|
89 | msg = _('error occured during creation of repository') | |
|
90 | h.flash(msg, category='error') | |
|
83 | 91 | |
|
84 | 92 | return redirect('repos') |
|
85 | 93 | |
@@ -99,27 +107,34 b' class ReposController(BaseController):' | |||
|
99 | 107 | # method='put') |
|
100 | 108 | # url('repo', repo_name=ID) |
|
101 | 109 | repo_model = RepoModel() |
|
102 | _form = RepoForm(edit=True)() | |
|
110 | changed_name = repo_name | |
|
111 | _form = RepoForm(edit=True, old_data={'repo_name':repo_name})() | |
|
112 | ||
|
103 | 113 | try: |
|
104 | 114 | form_result = _form.to_python(dict(request.POST)) |
|
105 | 115 | repo_model.update(repo_name, form_result) |
|
106 | 116 | invalidate_cache('cached_repo_list') |
|
107 | 117 | h.flash(_('Repository %s updated succesfully' % repo_name), |
|
108 | 118 | category='success') |
|
109 | ||
|
119 | changed_name = form_result['repo_name'] | |
|
110 | 120 | except formencode.Invalid as errors: |
|
111 | 121 | c.repo_info = repo_model.get(repo_name) |
|
112 | 122 | c.users_array = repo_model.get_users_js() |
|
113 | 123 | errors.value.update({'user':c.repo_info.user.username}) |
|
114 | c.form_errors = errors.error_dict | |
|
115 | 124 | return htmlfill.render( |
|
116 |
|
|
|
125 | render('admin/repos/repo_edit.html'), | |
|
117 | 126 | defaults=errors.value, |
|
127 | errors=errors.error_dict or {}, | |
|
128 | prefix_error=False, | |
|
118 | 129 | encoding="UTF-8") |
|
130 | ||
|
119 | 131 | except Exception: |
|
132 | log.error(traceback.format_exc()) | |
|
120 | 133 | h.flash(_('error occured during update of repository %s') \ |
|
121 |
% |
|
|
122 | return redirect(url('repos')) | |
|
134 | % repo_name, category='error') | |
|
135 | ||
|
136 | ||
|
137 | return redirect(url('edit_repo', repo_name=changed_name)) | |
|
123 | 138 | |
|
124 | 139 | def delete(self, repo_name): |
|
125 | 140 | """DELETE /repos/repo_name: Delete an existing item""" |
@@ -2,7 +2,7 b'' | |||
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | # settings controller for pylons |
|
4 | 4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
5 | ||
|
5 | # | |
|
6 | 6 | # This program is free software; you can redistribute it and/or |
|
7 | 7 | # modify it under the terms of the GNU General Public License |
|
8 | 8 | # as published by the Free Software Foundation; version 2 |
@@ -17,11 +17,6 b'' | |||
|
17 | 17 | # along with this program; if not, write to the Free Software |
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 | # MA 02110-1301, USA. |
|
20 | """ | |
|
21 | Created on June 30, 2010 | |
|
22 | settings controller for pylons | |
|
23 | @author: marcink | |
|
24 | """ | |
|
25 | 20 | from formencode import htmlfill |
|
26 | 21 | from pylons import tmpl_context as c, request, url |
|
27 | 22 | from pylons.controllers.util import redirect |
@@ -34,6 +29,12 b' from pylons_app.model.repo_model import ' | |||
|
34 | 29 | import formencode |
|
35 | 30 | import logging |
|
36 | 31 | import pylons_app.lib.helpers as h |
|
32 | import traceback | |
|
33 | """ | |
|
34 | Created on June 30, 2010 | |
|
35 | settings controller for pylons | |
|
36 | @author: marcink | |
|
37 | """ | |
|
37 | 38 | log = logging.getLogger(__name__) |
|
38 | 39 | |
|
39 | 40 | class SettingsController(BaseController): |
@@ -71,7 +72,7 b' class SettingsController(BaseController)' | |||
|
71 | 72 | |
|
72 | 73 | def update(self, repo_name): |
|
73 | 74 | repo_model = RepoModel() |
|
74 | _form = RepoSettingsForm(edit=True)() | |
|
75 | _form = RepoSettingsForm(edit=True, old_data={'repo_name':repo_name})() | |
|
75 | 76 | try: |
|
76 | 77 | form_result = _form.to_python(dict(request.POST)) |
|
77 | 78 | repo_model.update(repo_name, form_result) |
@@ -83,13 +84,15 b' class SettingsController(BaseController)' | |||
|
83 | 84 | c.repo_info = repo_model.get(repo_name) |
|
84 | 85 | c.users_array = repo_model.get_users_js() |
|
85 | 86 | errors.value.update({'user':c.repo_info.user.username}) |
|
86 | c.form_errors = errors.error_dict | |
|
87 | 87 | return htmlfill.render( |
|
88 |
|
|
|
88 | render('settings/repo_settings.html'), | |
|
89 | 89 | defaults=errors.value, |
|
90 | encoding="UTF-8") | |
|
90 | errors=errors.error_dict or {}, | |
|
91 | prefix_error=False, | |
|
92 | encoding="UTF-8") | |
|
91 | 93 | except Exception: |
|
94 | log.error(traceback.format_exc()) | |
|
92 | 95 | h.flash(_('error occured during update of repository %s') \ |
|
93 | 96 | % form_result['repo_name'], category='error') |
|
94 | 97 | |
|
95 | return redirect(url('repo_settings_home', repo_name=repo_name)) | |
|
98 | return redirect(url('repo_settings_home', repo_name=form_result['repo_name'])) |
@@ -124,7 +124,9 b' class ValidAuth(formencode.validators.Fa' | |||
|
124 | 124 | value, state, |
|
125 | 125 | error_dict=self.e_dict_disable) |
|
126 | 126 | |
|
127 |
meta.Session.remove() |
|
|
127 | meta.Session.remove() | |
|
128 | ||
|
129 | ||
|
128 | 130 | class ValidRepoUser(formencode.validators.FancyValidator): |
|
129 | 131 | |
|
130 | 132 | def to_python(self, value, state): |
@@ -136,9 +138,10 b' class ValidRepoUser(formencode.validator' | |||
|
136 | 138 | except Exception: |
|
137 | 139 | raise formencode.Invalid(_('This username is not valid'), |
|
138 | 140 | value, state) |
|
141 | meta.Session.remove() | |
|
139 | 142 | return self.user_db.user_id |
|
140 | 143 | |
|
141 |
def ValidRepoName(edit |
|
|
144 | def ValidRepoName(edit, old_data): | |
|
142 | 145 | class _ValidRepoName(formencode.validators.FancyValidator): |
|
143 | 146 | |
|
144 | 147 | def to_python(self, value, state): |
@@ -146,12 +149,16 b' def ValidRepoName(edit=False):' | |||
|
146 | 149 | if slug in ['_admin']: |
|
147 | 150 | raise formencode.Invalid(_('This repository name is disallowed'), |
|
148 | 151 | value, state) |
|
149 | sa = meta.Session | |
|
150 | if sa.query(Repository).get(slug) and not edit: | |
|
151 | raise formencode.Invalid(_('This repository already exists'), | |
|
152 | value, state) | |
|
153 | ||
|
152 | ||
|
153 | if old_data.get('repo_name') != value or not edit: | |
|
154 | sa = meta.Session | |
|
155 | if sa.query(Repository).get(slug): | |
|
156 | raise formencode.Invalid(_('This repository already exists') , | |
|
157 | value, state) | |
|
158 | meta.Session.remove() | |
|
154 | 159 | return slug |
|
160 | ||
|
161 | ||
|
155 | 162 | return _ValidRepoName |
|
156 | 163 | |
|
157 | 164 | class ValidPerms(formencode.validators.FancyValidator): |
@@ -243,11 +250,11 b' def UserForm(edit=False):' | |||
|
243 | 250 | |
|
244 | 251 | return _UserForm |
|
245 | 252 | |
|
246 | def RepoForm(edit=False): | |
|
253 | def RepoForm(edit=False, old_data={}): | |
|
247 | 254 | class _RepoForm(formencode.Schema): |
|
248 | 255 | allow_extra_fields = True |
|
249 | 256 | filter_extra_fields = False |
|
250 | repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit)) | |
|
257 | repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data)) | |
|
251 | 258 | description = UnicodeString(strip=True, min=3, not_empty=True) |
|
252 | 259 | private = StringBoolean(if_missing=False) |
|
253 | 260 | |
@@ -257,11 +264,11 b' def RepoForm(edit=False):' | |||
|
257 | 264 | chained_validators = [ValidPerms] |
|
258 | 265 | return _RepoForm |
|
259 | 266 | |
|
260 | def RepoSettingsForm(edit=False): | |
|
267 | def RepoSettingsForm(edit=False, old_data={}): | |
|
261 | 268 | class _RepoForm(formencode.Schema): |
|
262 | 269 | allow_extra_fields = True |
|
263 | 270 | filter_extra_fields = False |
|
264 | repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit)) | |
|
271 | repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data)) | |
|
265 | 272 | description = UnicodeString(strip=True, min=3, not_empty=True) |
|
266 | 273 | private = StringBoolean(if_missing=False) |
|
267 | 274 |
@@ -54,6 +54,7 b' class RepoModel(object):' | |||
|
54 | 54 | def update(self, repo_id, form_data): |
|
55 | 55 | try: |
|
56 | 56 | if repo_id != form_data['repo_name']: |
|
57 | #rename our data | |
|
57 | 58 | self.__rename_repo(repo_id, form_data['repo_name']) |
|
58 | 59 | cur_repo = self.sa.query(Repository).get(repo_id) |
|
59 | 60 | for k, v in form_data.items(): |
@@ -150,9 +151,13 b' class RepoModel(object):' | |||
|
150 | 151 | MercurialRepository(repo_path, create=True) |
|
151 | 152 | |
|
152 | 153 | def __rename_repo(self, old, new): |
|
153 |
log.info('renaming repo |
|
|
154 | log.info('renaming repo from %s to %s', old, new) | |
|
155 | ||
|
154 | 156 | old_path = os.path.join(g.base_path, old) |
|
155 | 157 | new_path = os.path.join(g.base_path, new) |
|
158 | if os.path.isdir(new_path): | |
|
159 | raise Exception('Was trying to rename to already existing dir %s', | |
|
160 | new_path) | |
|
156 | 161 | shutil.move(old_path, new_path) |
|
157 | 162 | |
|
158 | 163 | def __delete_repo(self, name): |
General Comments 0
You need to be logged in to leave comments.
Login now