created view for editing profile and created corresponding template
authorNishanth Amuluru <nishanth@fossee.in>
Fri, 07 Jan 2011 11:42:34 +0530
changeset 31 dde894b36370
parent 30 f501fc2a9f4c
child 32 df56daf2178e
created view for editing profile and created corresponding template
profile/forms.py
profile/forms.pyc
profile/urls.py
profile/views.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']
Binary file profile/forms.pyc has changed
--- 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),
 )
 
--- 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)