Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. def CreateNewUserView(request):
  2. if request.method == 'POST':
  3. user_form = UserCreationForm(request.POST, prefix='user_form')
  4. user_profile_form = UserProfileCreationForm(request.POST, request.FILES, prefix='user_profile_form')
  5. if user_form.is_valid():
  6. new_user = user_form.save()
  7.  
  8. if user_profile_form.is_valid():
  9. profile_picture = request.FILES['profile_picture']
  10.  
  11. new_user_profile = UserProfile(user=new_user, profile_picture=profile_picture,
  12. )
  13. new_user_profile.save()
  14.  
  15. username = user_form.cleaned_data['username']
  16. password = user_form.cleaned_data['password1']
  17. user = authenticate(username=username, password=password)
  18. login(request, user)
  19.  
  20. return HttpResponseRedirect('/dashboard/')
  21. else:
  22. # Allow user to select a role
  23. user_form = UserCreationForm(prefix='user_form')
  24. user_profile_form = UserProfileCreationForm(prefix='user_profile_form')
  25. return render(request, 'dashboard/create_user.html', {
  26. 'user_form':user_form,
  27. 'user_profile_form':user_profile_form,
  28. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement