From e9be14b09ad60e406ddc264f5cd550360ff44bb5 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Thu, 7 Apr 2016 10:54:12 +0200 Subject: delete a user --- src/web/templates/admin/dashboard.html | 2 +- src/web/views/admin.py | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'src/web') diff --git a/src/web/templates/admin/dashboard.html b/src/web/templates/admin/dashboard.html index 925d4cac..6a0793ce 100644 --- a/src/web/templates/admin/dashboard.html +++ b/src/web/templates/admin/dashboard.html @@ -34,7 +34,7 @@ {% endif %} - + {% endif %} diff --git a/src/web/views/admin.py b/src/web/views/admin.py index 1dc676de..05159807 100644 --- a/src/web/views/admin.py +++ b/src/web/views/admin.py @@ -98,6 +98,23 @@ def process_user_form(user_id=None): return redirect(url_for('admin.user_form', user_id=user.id)) +@admin_bp.route('/delete_user/', methods=['GET']) +@login_required +@admin_permission.require(http_exception=403) +def delete_user(user_id=None): + """ + Delete a user (with all its data). + """ + try: + user = UserController().delete(user_id) + flash(gettext('User %(nick)s successfully deleted', + nick=user.nickname), 'success') + except Exception as error: + flash(gettext('An error occured while trying to delete a user: ' + '%(error)', error=error), 'danger') + return redirect(redirect_url()) + + @admin_bp.route('/toggle_user/', methods=['GET']) @login_required @admin_permission.require() @@ -116,7 +133,7 @@ def toggle_user(user_id=None): else: act_txt = 'activated' if user.is_active else 'desactivated' - message = gettext('User %(login)s successfully %(is_active)s', - login=user.login, is_active=act_txt) + message = gettext('User %(nickname)s successfully %(is_active)s', + login=user.nickname, is_active=act_txt) flash(message, 'success') return redirect(url_for('admin.dashboard')) -- cgit