From 09bd0ebbf3e3f4ce37cd7603ebffe696185ade37 Mon Sep 17 00:00:00 2001 From: hardythe1 Date: Mon, 23 Feb 2015 15:03:45 +0530 Subject: added upate profile feature --- tbc/templates/base.html | 3 ++- tbc/templates/tbc/profile.html | 3 +++ tbc/urls.py | 1 + tbc/views.py | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/tbc/templates/base.html b/tbc/templates/base.html index 9e7ae28..d4c3a9e 100755 --- a/tbc/templates/base.html +++ b/tbc/templates/base.html @@ -131,11 +131,11 @@
  • Submit Sample Notebook
  • Submit Codes
  • Get Certificate
  • +
  • Update Profile
  • Update Password
  • Logout
  • - {% else %}
  • Submit Sample Notebook
  • Submit Codes
  • Get Certificate
  • +
  • Update Profile
  • Update Password
  • Logout
  • diff --git a/tbc/templates/tbc/profile.html b/tbc/templates/tbc/profile.html index d7a1b56..e6f706a 100644 --- a/tbc/templates/tbc/profile.html +++ b/tbc/templates/tbc/profile.html @@ -10,9 +10,12 @@
    {% endif %}
    +

    Update Your Profile

    +
    {% csrf_token %} {{ form.as_p }} + {{ form.errors }}
    diff --git a/tbc/urls.py b/tbc/urls.py index 75a9a7d..c558b6e 100644 --- a/tbc/urls.py +++ b/tbc/urls.py @@ -10,6 +10,7 @@ urlpatterns = patterns('', url(r'^login/$', 'tbc.views.UserLogin', name='UserLogin'), url(r'^logout/$', 'tbc.views.UserLogout', name='UserLogout'), url(r'^profile/$', 'tbc.views.UserProfile', name='UserProfile'), + url(r'^update-profile/$', 'tbc.views.UpdateProfile', name='UpdateProfile'), url(r'^forgot-password/$', 'tbc.views.ForgotPassword', name='ForgotPassword'), url(r'^update-password/$', 'tbc.views.UpdatePassword', name='UpdatePassword'), diff --git a/tbc/views.py b/tbc/views.py index cee3f04..f715e3e 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -252,6 +252,40 @@ def UserProfile(request): return HttpResponseRedirect('/login/?require_login=True') +def UpdateProfile(request): + user = request.user + context = {} + context.update(csrf(request)) + if user.is_anonymous(): + return HttpResponseRedirect('/login/?require_login=True') + if not _checkProfile(user): + return HttpResponseRedirect("/profile/?update=profile") + context['user'] = user + user_profile = Profile.objects.get(user=user) + if request.method == "POST": + form = UserProfileForm(request.POST) + if form.is_valid(): + data = form.save(commit=False) + data.user = request.user + data.save() + add_log(user, user, CHANGE,'Profile entry') + return HttpResponseRedirect('/') + else: + context['form'] = form + return render_to_response('tbc/profile.html', context) + else: + form = UserProfileForm() + form.initial['about'] = user_profile.about + form.initial['insti_org'] = user_profile.insti_org + form.initial['course'] = user_profile.course + form.initial['dept_desg'] = user_profile.dept_desg + form.initial['dob'] = user_profile.dob + form.initial['gender'] = user_profile.gender + form.initial['phone_no'] = user_profile.phone_no + form.initial['about_proj'] = user_profile.about_proj + context['form'] = form + return render_to_response('tbc/profile.html', context) + def UserLogout(request): user = request.user if user.is_authenticated() and user.is_active: -- cgit