diff options
-rwxr-xr-x | tbc/templates/base.html | 3 | ||||
-rw-r--r-- | tbc/templates/tbc/profile.html | 3 | ||||
-rw-r--r-- | tbc/urls.py | 1 | ||||
-rwxr-xr-x | tbc/views.py | 34 |
4 files changed, 40 insertions, 1 deletions
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 @@ <li><a href="{% url 'tbc:SubmitSample' %}">Submit Sample Notebook</a></li> <li><a href="{% url 'tbc:ConfirmBookDetails' %}">Submit Codes</a></li> <li><a href="{% url 'tbc:GetCertificate' %}">Get Certificate</a></li> + <li><a href="{% url 'tbc:UpdateProfile' %}">Update Profile</a></li> <li><a href="{% url 'tbc:UpdatePassword' %}">Update Password</a></li> <li><a href="{% url 'tbc:UserLogout' %}">Logout</a></li> </ul> </li> - {% else %} <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ user.first_name }}<b class="caret"></b></a> @@ -145,6 +145,7 @@ <li><a href="{% url 'tbc:SubmitSample' %}">Submit Sample Notebook</a></li> <li><a href="{% url 'tbc:ConfirmBookDetails' %}">Submit Codes</a></li> <li><a href="{% url 'tbc:GetCertificate' %}">Get Certificate</a></li> + <li><a href="{% url 'tbc:UpdateProfile' %}">Update Profile</a></li> <li><a href="{% url 'tbc:UpdatePassword' %}">Update Password</a></li> <li><a href="{% url 'tbc:UserLogout' %}">Logout</a></li> </ul> 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 @@ <div class="clearfix"></div> {% endif %} <div id="content-wrap" style="max-width:600px;"> + <h3>Update Your Profile</h3> + <hr> <form action="/profile/" method=POST> {% csrf_token %} {{ form.as_p }} + {{ form.errors }} <br> <input class="btn btn-primary" type=submit value=submit> </form> 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: |