Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. def start(request):
  2.     try:
  3.         username = request.POST['username']
  4.         password = request.POST['password']
  5.     except (KeyError):
  6.         return render_to_response('user/start.html')
  7.  
  8.     user = authenticate(username=username, password=password)
  9.     if user is not None:
  10.         if user.is_active:
  11.             try:
  12.                 UserProfile.objects.get(username=user)
  13.             except:
  14.                 editprofileform = EditProfileForm()
  15.                 msg = "Welcome. \n Please fill out your personal information below in order to proceed to the site."
  16.                 return render_to_response('user/editprofile.html', {'user': user, 'msg': msg, 'editprofileform': editprofileform})
  17.     [snip]
  18.  
  19.  
  20. @login_required
  21. def editprofile(request):
  22.     if request.method == 'POST':
  23.         requestprofile = EditProfileForm(request.POST)
  24.         if requestprofile.is_valid():
  25.             insertuserprofile = UserProfile()
  26.             insertuserprofile.username = User.objects.get(id=request.user.id)
  27.             insertuserprofile.save()
  28.             addartist = Artists(name = request.POST['band'])
  29.             addartist.save()
  30.             insertuserprofile.band.add(addartist)
  31.             #( UserProfile.objects.create(band=request.POST['band']))
  32.             insertuserprofile.address = request.POST['address']
  33.             insertuserprofile.city = request.POST['city']
  34.             insertuserprofile.zip = request.POST['zip']
  35.             insertuserprofile.age = request.POST['age_year']+"-"+request.POST['age_month']+"-"+request.POST['age_day']
  36.             insertuserprofile.save()
  37.  
  38.             msg = "Thank you! Your user profile has been updated successfully"
  39.             return render_to_response('user/result.html', {'user': request.user, 'msg': msg})
  40.  
  41.  
  42.     editprofileform = EditProfileForm()
  43.     return render_to_response('user/editprofile.html', {'user': request.user, 'editprofileform': editprofileform})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement