# HG changeset patch # User Nishanth Amuluru # Date 1294380754 -19800 # Node ID dde894b3637042293b4002791360570a025bcf10 # Parent f501fc2a9f4c06b60aaa10a51a4da1c5c389b1c2 created view for editing profile and created corresponding template diff -r f501fc2a9f4c -r dde894b36370 profile/forms.py --- a/profile/forms.py Fri Jan 07 11:27:29 2011 +0530 +++ b/profile/forms.py Fri Jan 07 11:42:34 2011 +0530 @@ -1,4 +1,3 @@ - import os import PIL @@ -82,3 +81,8 @@ return new_user +class EditProfileForm(forms.ModelForm): + + class Meta: + model = Profile + fields = ['aboutme', 'gender', 'dob', 'address', 'phonenum'] diff -r f501fc2a9f4c -r dde894b36370 profile/forms.pyc Binary file profile/forms.pyc has changed diff -r f501fc2a9f4c -r dde894b36370 profile/urls.py --- a/profile/urls.py Fri Jan 07 11:27:29 2011 +0530 +++ b/profile/urls.py Fri Jan 07 11:42:34 2011 +0530 @@ -1,9 +1,10 @@ from django.conf.urls.defaults import * -from pytask.profile.views import view_profile +from pytask.profile.views import view_profile, edit_profile urlpatterns = patterns('', (r'view', view_profile), + (r'edit', edit_profile), ) diff -r f501fc2a9f4c -r dde894b36370 profile/views.py --- a/profile/views.py Fri Jan 07 11:27:29 2011 +0530 +++ b/profile/views.py Fri Jan 07 11:42:34 2011 +0530 @@ -1,15 +1,44 @@ from django.shortcuts import render_to_response, redirect from django.contrib.auth.decorators import login_required +from django.core.context_processors import csrf +from django.views.decorators.csrf import csrf_protect + +from pytask.profile.forms import EditProfileForm @login_required def view_profile(request): user = request.user - profile = user.get_profile() context = {"user": user, "profile": profile, } return render_to_response("profile/view.html", context) + +@login_required +def edit_profile(request): + + user = request.user + profile = user.get_profile() + + context = {"user": user, + "profile": profile, + } + + context.update(csrf(request)) + + if request.method == "POST": + form = EditProfileForm(request.POST, instance=profile) + + if form.is_valid(): + form.save() + return redirect("/accounts/profile/view") + else: + context.update({"form":form}) + return render_to_response("profile/edit.html", context) + else: + form = EditProfileForm(instance=profile) + context.update({"form":form}) + return render_to_response("profile/edit.html", context)