Mercurial > kallithea
comparison pylons_app/controllers/admin/settings.py @ 371:5cd6616b8673
routes python 2.5 compatible
added my account settings,
some changes to routes mappers for settings to more custom ones
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 28 Jul 2010 01:44:39 +0200 |
parents | 339d1368c10d |
children | ca54622e39a1 |
comparison
equal
deleted
inserted
replaced
370:5df93e22eec0 | 371:5cd6616b8673 |
---|---|
50 # map.resource('setting', 'settings', controller='admin/settings', | 50 # map.resource('setting', 'settings', controller='admin/settings', |
51 # path_prefix='/admin', name_prefix='admin_') | 51 # path_prefix='/admin', name_prefix='admin_') |
52 | 52 |
53 | 53 |
54 @LoginRequired() | 54 @LoginRequired() |
55 #@HasPermissionAllDecorator('hg.admin') | |
56 def __before__(self): | 55 def __before__(self): |
57 c.admin_user = session.get('admin_user') | 56 c.admin_user = session.get('admin_user') |
58 c.admin_username = session.get('admin_username') | 57 c.admin_username = session.get('admin_username') |
59 super(SettingsController, self).__before__() | 58 super(SettingsController, self).__before__() |
60 | 59 |
60 | |
61 @HasPermissionAllDecorator('hg.admin') | |
61 def index(self, format='html'): | 62 def index(self, format='html'): |
62 """GET /admin/settings: All items in the collection""" | 63 """GET /admin/settings: All items in the collection""" |
63 # url('admin_settings') | 64 # url('admin_settings') |
64 | 65 |
65 hgsettings = self.sa.query(HgAppSettings).scalar() | 66 hgsettings = self.sa.query(HgAppSettings).scalar() |
69 defaults=defaults, | 70 defaults=defaults, |
70 encoding="UTF-8", | 71 encoding="UTF-8", |
71 force_defaults=False | 72 force_defaults=False |
72 ) | 73 ) |
73 | 74 |
75 @HasPermissionAllDecorator('hg.admin') | |
74 def create(self): | 76 def create(self): |
75 """POST /admin/settings: Create a new item""" | 77 """POST /admin/settings: Create a new item""" |
76 # url('admin_settings') | 78 # url('admin_settings') |
77 | 79 |
80 @HasPermissionAllDecorator('hg.admin') | |
78 def new(self, format='html'): | 81 def new(self, format='html'): |
79 """GET /admin/settings/new: Form to create a new item""" | 82 """GET /admin/settings/new: Form to create a new item""" |
80 # url('admin_new_setting') | 83 # url('admin_new_setting') |
81 | 84 |
82 def update(self, id): | 85 @HasPermissionAllDecorator('hg.admin') |
83 """PUT /admin/settings/id: Update an existing item""" | 86 def update(self, setting_id): |
87 """PUT /admin/settings/setting_id: Update an existing item""" | |
84 # Forms posted to this method should contain a hidden field: | 88 # Forms posted to this method should contain a hidden field: |
85 # <input type="hidden" name="_method" value="PUT" /> | 89 # <input type="hidden" name="_method" value="PUT" /> |
86 # Or using helpers: | 90 # Or using helpers: |
87 # h.form(url('admin_setting', id=ID), | 91 # h.form(url('admin_setting', setting_id=ID), |
88 # method='put') | 92 # method='put') |
89 # url('admin_setting', id=ID) | 93 # url('admin_setting', setting_id=ID) |
90 if id == 'mapping': | 94 if setting_id == 'mapping': |
91 rm_obsolete = request.POST.get('destroy', False) | 95 rm_obsolete = request.POST.get('destroy', False) |
92 log.debug('Rescanning directories with destroy=%s', rm_obsolete) | 96 log.debug('Rescanning directories with destroy=%s', rm_obsolete) |
93 | 97 |
94 initial = HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) | 98 initial = HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) |
95 repo2db_mapper(initial, rm_obsolete) | 99 repo2db_mapper(initial, rm_obsolete) |
96 invalidate_cache('cached_repo_list') | 100 invalidate_cache('cached_repo_list') |
97 h.flash(_('Repositories sucessfully rescanned'), category='success') | 101 h.flash(_('Repositories sucessfully rescanned'), category='success') |
98 | 102 |
99 if id == 'global': | 103 if setting_id == 'global': |
100 | 104 |
101 application_form = ApplicationSettingsForm()() | 105 application_form = ApplicationSettingsForm()() |
102 try: | 106 try: |
103 form_result = application_form.to_python(dict(request.POST)) | 107 form_result = application_form.to_python(dict(request.POST)) |
104 title = form_result['app_title'] | 108 title = form_result['app_title'] |
130 errors=errors.error_dict or {}, | 134 errors=errors.error_dict or {}, |
131 prefix_error=False, | 135 prefix_error=False, |
132 encoding="UTF-8") | 136 encoding="UTF-8") |
133 | 137 |
134 return redirect(url('admin_settings')) | 138 return redirect(url('admin_settings')) |
135 | 139 |
136 def delete(self, id): | 140 @HasPermissionAllDecorator('hg.admin') |
137 """DELETE /admin/settings/id: Delete an existing item""" | 141 def delete(self, setting_id): |
142 """DELETE /admin/settings/setting_id: Delete an existing item""" | |
138 # Forms posted to this method should contain a hidden field: | 143 # Forms posted to this method should contain a hidden field: |
139 # <input type="hidden" name="_method" value="DELETE" /> | 144 # <input type="hidden" name="_method" value="DELETE" /> |
140 # Or using helpers: | 145 # Or using helpers: |
141 # h.form(url('admin_setting', id=ID), | 146 # h.form(url('admin_setting', setting_id=ID), |
142 # method='delete') | 147 # method='delete') |
143 # url('admin_setting', id=ID) | 148 # url('admin_setting', setting_id=ID) |
144 | 149 |
145 def show(self, id, format='html'): | 150 @HasPermissionAllDecorator('hg.admin') |
146 """GET /admin/settings/id: Show a specific item""" | 151 def show(self, setting_id, format='html'): |
147 # url('admin_setting', id=ID) | 152 """GET /admin/settings/setting_id: Show a specific item""" |
148 | 153 # url('admin_setting', setting_id=ID) |
149 def edit(self, id, format='html'): | 154 |
150 """GET /admin/settings/id/edit: Form to edit an existing item""" | 155 @HasPermissionAllDecorator('hg.admin') |
151 # url('admin_edit_setting', id=ID) | 156 def edit(self, setting_id, format='html'): |
157 """GET /admin/settings/setting_id/edit: Form to edit an existing item""" | |
158 # url('admin_edit_setting', setting_id=ID) | |
159 | |
160 | |
161 def my_account(self): | |
162 """ | |
163 GET /_admin/my_account Displays info about my account | |
164 """ | |
165 # url('admin_settings_my_account') | |
166 c.user = self.sa.query(User).get(c.hg_app_user.user_id) | |
167 if c.user.username == 'default': | |
168 h.flash(_("You can't edit this user since it's" | |
169 " crucial for entire application"), category='warning') | |
170 return redirect(url('users')) | |
171 | |
172 defaults = c.user.__dict__ | |
173 return htmlfill.render( | |
174 render('admin/users/user_edit_my_account.html'), | |
175 defaults=defaults, | |
176 encoding="UTF-8", | |
177 force_defaults=False | |
178 ) | |
179 | |
180 def my_account_update(self): | |
181 """PUT /_admin/my_account_update: Update an existing item""" | |
182 # Forms posted to this method should contain a hidden field: | |
183 # <input type="hidden" name="_method" value="PUT" /> | |
184 # Or using helpers: | |
185 # h.form(url('admin_settings_my_account_update'), | |
186 # method='put') | |
187 # url('admin_settings_my_account_update', id=ID) | |
188 user_model = UserModel() | |
189 uid = c.hg_app_user.user_id | |
190 _form = UserForm(edit=True, old_data={'user_id':uid})() | |
191 form_result = {} | |
192 try: | |
193 form_result = _form.to_python(dict(request.POST)) | |
194 user_model.update_my_account(uid, form_result) | |
195 h.flash(_('Your account was updated succesfully'), category='success') | |
196 | |
197 except formencode.Invalid as errors: | |
198 #c.user = self.sa.query(User).get(c.hg_app_user.user_id) | |
199 return htmlfill.render( | |
200 render('admin/users/user_edit_my_account.html'), | |
201 defaults=errors.value, | |
202 errors=errors.error_dict or {}, | |
203 prefix_error=False, | |
204 encoding="UTF-8") | |
205 except Exception: | |
206 log.error(traceback.format_exc()) | |
207 h.flash(_('error occured during update of user %s') \ | |
208 % form_result.get('username'), category='error') | |
209 | |
210 return redirect(url('my_account')) | |
211 | |
212 |