diff options
author | adityacp | 2016-04-21 18:52:29 +0530 |
---|---|---|
committer | adityacp | 2016-04-21 18:52:29 +0530 |
commit | ab5d550709322739629fffb7e7a3335ec1a6623c (patch) | |
tree | c2fab98b5706e79841d4127d86713268d58927be | |
parent | 975e74ab737cfc5d9c5375931170cdc9ecb75b40 (diff) | |
download | online_test-ab5d550709322739629fffb7e7a3335ec1a6623c.tar.gz online_test-ab5d550709322739629fffb7e7a3335ec1a6623c.tar.bz2 online_test-ab5d550709322739629fffb7e7a3335ec1a6623c.zip |
final changes in edit profile
-rw-r--r-- | yaksh/templates/yaksh/editprofile.html | 2 | ||||
-rw-r--r-- | yaksh/views.py | 25 |
2 files changed, 15 insertions, 12 deletions
diff --git a/yaksh/templates/yaksh/editprofile.html b/yaksh/templates/yaksh/editprofile.html index 75be563..cdccfc0 100644 --- a/yaksh/templates/yaksh/editprofile.html +++ b/yaksh/templates/yaksh/editprofile.html @@ -12,7 +12,7 @@ <form action="{{URL_ROOT}}/exam/editprofile/" method="post" > {% csrf_token %} <center> - <table class=span1> + <table class="span1"> {{ form.as_table }} </table> </center> 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) |