diff options
author | adityacp | 2016-04-15 18:47:01 +0530 |
---|---|---|
committer | adityacp | 2016-04-15 18:47:01 +0530 |
commit | 09e77a6065f019fe9b9d00fbedce2c11188e4589 (patch) | |
tree | 209a6b0f3deede63677a77b586179d6d355a2c6e /yaksh/views.py | |
parent | 351203587422455d803a2b92296cb8e7a8ba59a9 (diff) | |
download | online_test-09e77a6065f019fe9b9d00fbedce2c11188e4589.tar.gz online_test-09e77a6065f019fe9b9d00fbedce2c11188e4589.tar.bz2 online_test-09e77a6065f019fe9b9d00fbedce2c11188e4589.zip |
changes after rebase
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index bc54a51..d76e042 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -991,11 +991,19 @@ def edit_profile(request): context = {} user = request.user ci = RequestContext(request) - profile = Profile.objects.get(user_id=user.id) + + if not hasattr(user, 'profile'): + new_form = EditProfile(request.POST, user=user) + form = EditProfile(user=user) + else: + profile = Profile.objects.get(user_id=user.id) + new_form = EditProfile(request.POST, user=user, instance=profile) + form = EditProfile(user=user, instance=profile) + if request.method == 'POST': - form = EditProfile(user, request.POST, instance=profile) - if form.is_valid(): - form_data = form.save(commit=False) + if new_form.is_valid(): + form_data = new_form.save(commit=False) + form_data.user = user form_data.user.first_name = request.POST['first_name'] form_data.user.last_name = request.POST['last_name'] form_data.user.save() @@ -1003,11 +1011,10 @@ def edit_profile(request): return my_render_to_response('yaksh/profile_updated.html', context_instance=ci) else: - context['form'] = form + context['form'] = new_form return my_render_to_response('yaksh/editprofile.html', context, context_instance=ci) else: - form = EditProfile(user, instance=profile) context['form'] = form return my_render_to_response('yaksh/editprofile.html', context, context_instance=ci) |