summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authoradityacp2016-04-21 18:52:29 +0530
committeradityacp2016-04-21 18:52:29 +0530
commitab5d550709322739629fffb7e7a3335ec1a6623c (patch)
treec2fab98b5706e79841d4127d86713268d58927be /yaksh/views.py
parent975e74ab737cfc5d9c5375931170cdc9ecb75b40 (diff)
downloadonline_test-ab5d550709322739629fffb7e7a3335ec1a6623c.tar.gz
online_test-ab5d550709322739629fffb7e7a3335ec1a6623c.tar.bz2
online_test-ab5d550709322739629fffb7e7a3335ec1a6623c.zip
final changes in edit profile
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 5c30d04..49d7179 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -65,6 +65,12 @@ def is_moderator(user):
if user.groups.filter(name='moderator').count() == 1:
return True
+def has_profile(user):
+ """ check if user is having profile """
+ if hasattr(user, 'profile'):
+ return True
+ else:
+ return False
def index(request):
"""The start page.
@@ -979,7 +985,7 @@ def view_profile(request):
user = request.user
ci = RequestContext(request)
context = {}
- if hasattr(user, 'profile'):
+ if has_profile(user):
return my_render_to_response('yaksh/view_profile.html', {'user':user})
else:
form = EditProfile(user=user)
@@ -997,12 +1003,13 @@ def edit_profile(request):
user = request.user
ci = RequestContext(request)
+ if has_profile(user):
+ profile = Profile.objects.get(user_id=user.id)
+ else:
+ profile = None
+
if request.method == 'POST':
- if not hasattr(user, 'profile'):
- form = EditProfile(request.POST, user=user)
- else:
- profile = Profile.objects.get(user_id=user.id)
- form = EditProfile(request.POST, user=user, instance=profile)
+ form = EditProfile(request.POST, user=user, instance=profile)
if form.is_valid():
form_data = form.save(commit=False)
form_data.user = user
@@ -1017,11 +1024,7 @@ def edit_profile(request):
return my_render_to_response('yaksh/editprofile.html', context,
context_instance=ci)
else:
- if not hasattr(user, 'profile'):
- form = EditProfile(user=user)
- else:
- profile = Profile.objects.get(user_id=user.id)
- form = EditProfile(user=user, instance=profile)
+ form = EditProfile(user=user, instance=profile)
context['form'] = form
return my_render_to_response('yaksh/editprofile.html', context,
context_instance=ci)