def create_user(request): user_form = RegistrationForm(request.POST or None) if 'password' in request.POST: hash_pw = hashlib.sha512(request.POST.get("password")) if user_form.is_valid: user_form = RegistrationForm({'username': request.POST.get('username'), 'password': hash_pw, 'first_name': request.POST.get('first_name'), 'last_name': request.POST.get('last_name')} or None) save_it = user_form.save(commit=False) save_it.save() user_form = RegistrationForm(None) else: print("aaaa") # user_form.password = hashlib.sha512(request.POST.get("password")) # save_it = user_form.save(commit=False) # save_it.user = request.user # save_it.save() context = {"form": user_form} template = 'poll/AccountsManagement/AuthorizedUser/CreateUser/createUser.html' return render(request, template, context)
def update_user(request): if "username" in request.POST: a = Staff.objects.get(username=request.POST.get("username2")) if type(a) is not None: if "usr" in request.POST: usr = request.POST.get("usr") if usr == "search": user_form = RegistrationForm( {'username': a.username, 'password': a.password, 'last_name': a.last_name, 'first_name': a.first_name}, instance=a) print "Submit, Search" if user_form.is_valid: user_form.save(commit=False) elif usr == "update": user_form = RegistrationForm(request.POST or None, instance=a) print "Submit, Update" if user_form.is_valid: save_it = user_form.save(commit=False) save_it.user = request.user save_it.save() elif usr == "delete": user_form = RegistrationForm(request.POST or None, instance=a) print "Submit delete" if user_form.is_valid: delete_it = user_form.save(commit=False) delete_it.user = request.user delete_it.delete() else: user_form = RegistrationForm() else: # show a page without any post user_form = RegistrationForm() context = {"form": user_form} template = "poll/AccountsManagement/AuthorizedUser/UpdateDeleteUser/updateDeleteUser.html" return render(request, template, context)