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