From bf5b0a9a42dd68dc83bc01421f7d87d3c688be46 Mon Sep 17 00:00:00 2001 From: Retspen Date: Wed, 11 Mar 2015 14:01:21 +0200 Subject: [PATCH] Added users management --- templates/users.html | 52 ++++++++++++++++++++++++++++++++++++++++++++ users/views.py | 28 ++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/templates/users.html b/templates/users.html index 46412af..01e7d20 100644 --- a/templates/users.html +++ b/templates/users.html @@ -20,6 +20,9 @@

{{ user.username }} + + +

@@ -36,6 +39,55 @@
+ + + {% endfor %} {% endblock %} \ No newline at end of file diff --git a/users/views.py b/users/views.py index 4d1ba00..55ab801 100644 --- a/users/views.py +++ b/users/views.py @@ -35,6 +35,34 @@ def users(request): new_user = User.objects.create_user(data['name'], None, data['password']) new_user.save() return HttpResponseRedirect(request.get_full_path()) + if 'edit' in request.POST: + user_id = request.POST.get('user_id', '') + user_pass = request.POST.get('user_pass', '') + user_edit = User.objects.get(id=user_id) + user.password = user_pass + user_edit.save() + return HttpResponseRedirect(request.get_full_path()) + if 'block' in request.POST: + user_id = request.POST.get('user_id', '') + user_block = User.objects.get(id=user_id) + user_block.is_active = False + user_block.save() + return HttpResponseRedirect(request.get_full_path()) + if 'unblock' in request.POST: + user_id = request.POST.get('user_id', '') + user_unblock = User.objects.get(id=user_id) + user_unblock.is_active = True + user_unblock.save() + return HttpResponseRedirect(request.get_full_path()) + if 'delete' in request.POST: + user_id = request.POST.get('user_id', '') + try: + del_user_inst = UserInstance.objects.filter(user_id=user_id) + del_user_inst.delete() + finally: + user_delete = User.objects.get(id=user_id) + user_delete.delete() + return HttpResponseRedirect(request.get_full_path()) return render(request, 'users.html', locals())