##// END OF EJS Templates
started my page rewrite
marcink -
r446:a0a93357 default
parent child Browse files
Show More
@@ -1,281 +1,286 b''
1 1 #!/usr/bin/env python
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
9 9 # of the License or (at your opinion) any later version of the license.
10 10 #
11 11 # This program is distributed in the hope that it will be useful,
12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 14 # GNU General Public License for more details.
15 15 #
16 16 # You should have received a copy of the GNU General Public License
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 20 """
21 21 Created on July 14, 2010
22 22 settings controller for pylons
23 23 @author: marcink
24 24 """
25 25 from formencode import htmlfill
26 26 from pylons import request, session, tmpl_context as c, url, app_globals as g, \
27 27 config
28 28 from pylons.controllers.util import abort, redirect
29 29 from pylons.i18n.translation import _
30 30 from pylons_app.lib import helpers as h
31 31 from pylons_app.lib.auth import LoginRequired, HasPermissionAllDecorator, \
32 32 HasPermissionAnyDecorator
33 33 from pylons_app.lib.base import BaseController, render
34 34 from pylons_app.lib.utils import repo2db_mapper, invalidate_cache, \
35 35 set_hg_app_config, get_hg_settings, get_hg_ui_settings, make_ui
36 36 from pylons_app.model.db import User, UserLog, HgAppSettings, HgAppUi
37 37 from pylons_app.model.forms import UserForm, ApplicationSettingsForm, \
38 38 ApplicationUiSettingsForm
39 39 from pylons_app.model.hg_model import HgModel
40 40 from pylons_app.model.user_model import UserModel
41 41 import formencode
42 42 import logging
43 43 import traceback
44 44
45 45 log = logging.getLogger(__name__)
46 46
47 47
48 48 class SettingsController(BaseController):
49 49 """REST Controller styled on the Atom Publishing Protocol"""
50 50 # To properly map this controller, ensure your config/routing.py
51 51 # file has a resource setup:
52 52 # map.resource('setting', 'settings', controller='admin/settings',
53 53 # path_prefix='/admin', name_prefix='admin_')
54 54
55 55
56 56 @LoginRequired()
57 57 def __before__(self):
58 58 c.admin_user = session.get('admin_user')
59 59 c.admin_username = session.get('admin_username')
60 60 super(SettingsController, self).__before__()
61 61
62 62
63 63 @HasPermissionAllDecorator('hg.admin')
64 64 def index(self, format='html'):
65 65 """GET /admin/settings: All items in the collection"""
66 66 # url('admin_settings')
67 67
68 68 defaults = get_hg_settings()
69 69 defaults.update(get_hg_ui_settings())
70 70 return htmlfill.render(
71 71 render('admin/settings/settings.html'),
72 72 defaults=defaults,
73 73 encoding="UTF-8",
74 74 force_defaults=False
75 75 )
76 76
77 77 @HasPermissionAllDecorator('hg.admin')
78 78 def create(self):
79 79 """POST /admin/settings: Create a new item"""
80 80 # url('admin_settings')
81 81
82 82 @HasPermissionAllDecorator('hg.admin')
83 83 def new(self, format='html'):
84 84 """GET /admin/settings/new: Form to create a new item"""
85 85 # url('admin_new_setting')
86 86
87 87 @HasPermissionAllDecorator('hg.admin')
88 88 def update(self, setting_id):
89 89 """PUT /admin/settings/setting_id: Update an existing item"""
90 90 # Forms posted to this method should contain a hidden field:
91 91 # <input type="hidden" name="_method" value="PUT" />
92 92 # Or using helpers:
93 93 # h.form(url('admin_setting', setting_id=ID),
94 94 # method='put')
95 95 # url('admin_setting', setting_id=ID)
96 96 if setting_id == 'mapping':
97 97 rm_obsolete = request.POST.get('destroy', False)
98 98 log.debug('Rescanning directories with destroy=%s', rm_obsolete)
99 99
100 100 initial = HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui)
101 101 repo2db_mapper(initial, rm_obsolete)
102 102 invalidate_cache('cached_repo_list')
103 103 h.flash(_('Repositories sucessfully rescanned'), category='success')
104 104
105 105 if setting_id == 'global':
106 106
107 107 application_form = ApplicationSettingsForm()()
108 108 try:
109 109 form_result = application_form.to_python(dict(request.POST))
110 110
111 111 try:
112 112 hgsettings1 = self.sa.query(HgAppSettings)\
113 113 .filter(HgAppSettings.app_settings_name == 'title').one()
114 114 hgsettings1.app_settings_value = form_result['hg_app_title']
115 115
116 116 hgsettings2 = self.sa.query(HgAppSettings)\
117 117 .filter(HgAppSettings.app_settings_name == 'realm').one()
118 118 hgsettings2.app_settings_value = form_result['hg_app_realm']
119 119
120 120
121 121 self.sa.add(hgsettings1)
122 122 self.sa.add(hgsettings2)
123 123 self.sa.commit()
124 124 set_hg_app_config(config)
125 125 h.flash(_('Updated application settings'),
126 126 category='success')
127 127
128 128 except:
129 129 log.error(traceback.format_exc())
130 130 h.flash(_('error occured during updating application settings'),
131 131 category='error')
132 132
133 133 self.sa.rollback()
134 134
135 135
136 136 except formencode.Invalid as errors:
137 137 return htmlfill.render(
138 138 render('admin/settings/settings.html'),
139 139 defaults=errors.value,
140 140 errors=errors.error_dict or {},
141 141 prefix_error=False,
142 142 encoding="UTF-8")
143 143
144 144 if setting_id == 'mercurial':
145 145 application_form = ApplicationUiSettingsForm()()
146 146 try:
147 147 form_result = application_form.to_python(dict(request.POST))
148 148
149 149 try:
150 150
151 151 hgsettings1 = self.sa.query(HgAppUi)\
152 152 .filter(HgAppUi.ui_key == 'push_ssl').one()
153 153 hgsettings1.ui_value = form_result['web_push_ssl']
154 154
155 155 hgsettings2 = self.sa.query(HgAppUi)\
156 156 .filter(HgAppUi.ui_key == '/').one()
157 157 hgsettings2.ui_value = form_result['paths_root_path']
158 158
159 159
160 160 #HOOKS
161 161 hgsettings3 = self.sa.query(HgAppUi)\
162 162 .filter(HgAppUi.ui_key == 'changegroup.update').one()
163 163 hgsettings3.ui_active = bool(form_result['hooks_changegroup_update'])
164 164
165 165 hgsettings4 = self.sa.query(HgAppUi)\
166 166 .filter(HgAppUi.ui_key == 'changegroup.repo_size').one()
167 167 hgsettings4.ui_active = bool(form_result['hooks_changegroup_repo_size'])
168 168
169 169
170 170
171 171
172 172 self.sa.add(hgsettings1)
173 173 self.sa.add(hgsettings2)
174 174 self.sa.add(hgsettings3)
175 175 self.sa.add(hgsettings4)
176 176 self.sa.commit()
177 177
178 178 h.flash(_('Updated mercurial settings'),
179 179 category='success')
180 180
181 181 except:
182 182 log.error(traceback.format_exc())
183 183 h.flash(_('error occured during updating application settings'),
184 184 category='error')
185 185
186 186 self.sa.rollback()
187 187
188 188
189 189 except formencode.Invalid as errors:
190 190 return htmlfill.render(
191 191 render('admin/settings/settings.html'),
192 192 defaults=errors.value,
193 193 errors=errors.error_dict or {},
194 194 prefix_error=False,
195 195 encoding="UTF-8")
196 196
197 197
198 198
199 199 return redirect(url('admin_settings'))
200 200
201 201 @HasPermissionAllDecorator('hg.admin')
202 202 def delete(self, setting_id):
203 203 """DELETE /admin/settings/setting_id: Delete an existing item"""
204 204 # Forms posted to this method should contain a hidden field:
205 205 # <input type="hidden" name="_method" value="DELETE" />
206 206 # Or using helpers:
207 207 # h.form(url('admin_setting', setting_id=ID),
208 208 # method='delete')
209 209 # url('admin_setting', setting_id=ID)
210 210
211 211 @HasPermissionAllDecorator('hg.admin')
212 212 def show(self, setting_id, format='html'):
213 213 """GET /admin/settings/setting_id: Show a specific item"""
214 214 # url('admin_setting', setting_id=ID)
215 215
216 216 @HasPermissionAllDecorator('hg.admin')
217 217 def edit(self, setting_id, format='html'):
218 218 """GET /admin/settings/setting_id/edit: Form to edit an existing item"""
219 219 # url('admin_edit_setting', setting_id=ID)
220 220
221 221
222 222 def my_account(self):
223 223 """
224 224 GET /_admin/my_account Displays info about my account
225 225 """
226 226 # url('admin_settings_my_account')
227 227 c.user = self.sa.query(User).get(c.hg_app_user.user_id)
228 c.user_repos = []
229 for repo in c.cached_repo_list.values():
230 if repo.dbrepo.user.username == c.user.username:
231 c.user_repos.append(repo)
232
228 233 if c.user.username == 'default':
229 234 h.flash(_("You can't edit this user since it's"
230 235 " crucial for entire application"), category='warning')
231 236 return redirect(url('users'))
232 237
233 238 defaults = c.user.__dict__
234 239 return htmlfill.render(
235 240 render('admin/users/user_edit_my_account.html'),
236 241 defaults=defaults,
237 242 encoding="UTF-8",
238 243 force_defaults=False
239 244 )
240 245
241 246 def my_account_update(self):
242 247 """PUT /_admin/my_account_update: Update an existing item"""
243 248 # Forms posted to this method should contain a hidden field:
244 249 # <input type="hidden" name="_method" value="PUT" />
245 250 # Or using helpers:
246 251 # h.form(url('admin_settings_my_account_update'),
247 252 # method='put')
248 253 # url('admin_settings_my_account_update', id=ID)
249 254 user_model = UserModel()
250 255 uid = c.hg_app_user.user_id
251 256 _form = UserForm(edit=True, old_data={'user_id':uid})()
252 257 form_result = {}
253 258 try:
254 259 form_result = _form.to_python(dict(request.POST))
255 260 user_model.update_my_account(uid, form_result)
256 261 h.flash(_('Your account was updated succesfully'),
257 262 category='success')
258 263
259 264 except formencode.Invalid as errors:
260 265 #c.user = self.sa.query(User).get(c.hg_app_user.user_id)
261 266 return htmlfill.render(
262 267 render('admin/users/user_edit_my_account.html'),
263 268 defaults=errors.value,
264 269 errors=errors.error_dict or {},
265 270 prefix_error=False,
266 271 encoding="UTF-8")
267 272 except Exception:
268 273 log.error(traceback.format_exc())
269 274 h.flash(_('error occured during update of user %s') \
270 275 % form_result.get('username'), category='error')
271 276
272 277 return redirect(url('my_account'))
273 278
274 279 @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository')
275 280 def create_repository(self):
276 281 """GET /_admin/create_repository: Form to create a new item"""
277 282 new_repo = request.GET.get('repo', '')
278 283 c.new_repo = h.repo_name_slug(new_repo)
279 284
280 285 return render('admin/repos/repo_add_create_repository.html')
281 286
@@ -1,79 +1,109 b''
1 1 ## -*- coding: utf-8 -*-
2 2 <%inherit file="/base/base.html"/>
3 3
4 4 <%def name="title()">
5 5 ${c.hg_app_user.username} ${_('account')}
6 6 </%def>
7 7
8 8 <%def name="breadcrumbs_links()">
9 9 ${_('My Account')}
10 10 </%def>
11 11
12 12 <%def name="page_nav()">
13 13 ${self.menu('admin')}
14 14 </%def>
15 15
16 16 <%def name="main()">
17 <div class="box">
17 <div class="box box-left">
18 18 <!-- box / title -->
19 19 <div class="title">
20 20 ${self.breadcrumbs()}
21 21 </div>
22 22 <!-- end box / title -->
23 23 ${h.form(url('admin_settings_my_account_update'),method='put')}
24 24 <div class="form">
25 25 <!-- fields -->
26 26 <div class="fields">
27 27 <div class="field">
28 28 <div class="label">
29 29 <label for="username">${_('Username')}:</label>
30 30 </div>
31 31 <div class="input">
32 32 ${h.text('username')}
33 33 </div>
34 34 </div>
35 35
36 36 <div class="field">
37 37 <div class="label">
38 38 <label for="new_password">${_('New password')}:</label>
39 39 </div>
40 40 <div class="input">
41 41 ${h.password('new_password')}
42 42 </div>
43 43 </div>
44 44
45 45 <div class="field">
46 46 <div class="label">
47 47 <label for="name">${_('Name')}:</label>
48 48 </div>
49 49 <div class="input">
50 50 ${h.text('name')}
51 51 </div>
52 52 </div>
53 53
54 54 <div class="field">
55 55 <div class="label">
56 56 <label for="lastname">${_('Lastname')}:</label>
57 57 </div>
58 58 <div class="input">
59 59 ${h.text('lastname')}
60 60 </div>
61 61 </div>
62 62
63 63 <div class="field">
64 64 <div class="label">
65 65 <label for="email">${_('Email')}:</label>
66 66 </div>
67 67 <div class="input">
68 68 ${h.text('email')}
69 69 </div>
70 70 </div>
71 71
72 72 <div class="buttons">
73 73 ${h.submit('save','save',class_="ui-button ui-widget ui-state-default ui-corner-all")}
74 74 </div>
75 75 </div>
76 76 </div>
77 77 ${h.end_form()}
78 78 </div>
79
80 <div class="box box-right">
81 <!-- box / title -->
82 <div class="title">
83 <h5>${_('My repositories')}</h5>
84 </div>
85 <!-- end box / title -->
86 <div class="table">
87 <table>
88 <tbody>
89 %for repo in c.user_repos:
90 <tr>
91 <td>
92 %if repo.dbrepo.private:
93 <img alt="${_('private')}" src="/images/icons/lock.png"/>
94 %else:
95 <img alt="${_('public')}" src="/images/icons/lock_open.png"/>
96 %endif
97
98 ${h.link_to(repo.name, h.url('summary_home',repo_name=repo.name))}</td>
99 ##<td>${_('created')} ${repo.dbrepo.}</td>
100 <td>${_('last changed')} ${h.age(repo.last_change)}</td>
101 <td>${h.link_to(_('[edit]'),h.url('edit_repo',repo_name=repo.name))}</td>
102 </tr>
103 %endfor
104 </tbody>
105 </table>
106 </div>
107
108 </div>
79 109 </%def> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now