Mercurial > public > src > rhodecode
diff pylons_app/controllers/users.py @ 265:0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 07 Jun 2010 00:18:33 +0200 |
parents | 3782a6d698af |
children | a7608dbe47fc 14478d989870 |
line wrap: on
line diff
--- a/pylons_app/controllers/users.py Sun Jun 06 23:35:21 2010 +0200 +++ b/pylons_app/controllers/users.py Mon Jun 07 00:18:33 2010 +0200 @@ -23,7 +23,6 @@ @author: marcink """ import logging -from formencode import htmlfill from pylons import request, session, tmpl_context as c, url from pylons.controllers.util import abort, redirect from pylons.i18n.translation import _ @@ -34,6 +33,7 @@ from pylons_app.model.forms import UserForm from pylons_app.model.user_model import UserModel import formencode +from formencode import htmlfill log = logging.getLogger(__name__) @@ -65,15 +65,18 @@ try: form_result = login_form.to_python(dict(request.POST)) user_model.create(form_result) - h.flash(_('created user %s') % form_result['username'], category='success') - return redirect(url('users')) - + h.flash(_('created user %s') % form_result['username'], + category='success') except formencode.Invalid as errors: c.form_errors = errors.error_dict return htmlfill.render( render('admin/users/user_add.html'), defaults=errors.value, encoding="UTF-8") + except Exception: + h.flash(_('error occured during creation of user %s') \ + % form_result['username'], category='error') + return redirect(url('users')) def new(self, format='html'): """GET /users/new: Form to create a new item""" @@ -89,12 +92,11 @@ # method='put') # url('user', id=ID) user_model = UserModel() - login_form = UserForm(edit=True)() + _form = UserForm(edit=True)() try: - form_result = login_form.to_python(dict(request.POST)) + form_result = _form.to_python(dict(request.POST)) user_model.update(id, form_result) h.flash(_('User updated succesfully'), category='success') - return redirect(url('users')) except formencode.Invalid as errors: c.user = user_model.get_user(id) @@ -103,7 +105,12 @@ render('admin/users/user_edit.html'), defaults=errors.value, encoding="UTF-8") - + except Exception: + h.flash(_('error occured during update of user %s') \ + % form_result['username'], category='error') + + return redirect(url('users')) + def delete(self, id): """DELETE /users/id: Delete an existing item""" # Forms posted to this method should contain a hidden field: @@ -112,13 +119,14 @@ # h.form(url('user', id=ID), # method='delete') # url('user', id=ID) + user_model = UserModel() try: - self.sa.delete(self.sa.query(User).get(id)) - self.sa.commit() + user_model.delete(id) h.flash(_('sucessfully deleted user'), category='success') - except: - self.sa.rollback() - raise + except Exception: + h.flash(_('An error occured during deletion of user'), + category='error') + return redirect(url('users')) def show(self, id, format='html'):