diff options
author | Nishanth Amuluru | 2011-01-07 11:42:34 +0530 |
---|---|---|
committer | Nishanth Amuluru | 2011-01-07 11:42:34 +0530 |
commit | 89e01c60efdcb6eb5151370e2b211fbf2a844de5 (patch) | |
tree | c3fd7dd9e0686900d262af423485d0f69c4290c2 | |
parent | 5e4a908ac4397a4b1070b8ecf6a85a5031956a42 (diff) | |
download | pytask-89e01c60efdcb6eb5151370e2b211fbf2a844de5.tar.gz pytask-89e01c60efdcb6eb5151370e2b211fbf2a844de5.tar.bz2 pytask-89e01c60efdcb6eb5151370e2b211fbf2a844de5.zip |
created view for editing profile and created corresponding template
-rw-r--r-- | profile/forms.py | 6 | ||||
-rw-r--r-- | profile/forms.pyc | bin | 3317 -> 3845 bytes | |||
-rw-r--r-- | profile/urls.py | 3 | ||||
-rwxr-xr-x | profile/views.py | 31 |
4 files changed, 37 insertions, 3 deletions
diff --git a/profile/forms.py b/profile/forms.py index ed4b455..e1662b8 100644 --- a/profile/forms.py +++ b/profile/forms.py @@ -1,4 +1,3 @@ - import os import PIL @@ -82,3 +81,8 @@ class CustomRegistrationForm(RegistrationFormUniqueEmail): return new_user +class EditProfileForm(forms.ModelForm): + + class Meta: + model = Profile + fields = ['aboutme', 'gender', 'dob', 'address', 'phonenum'] diff --git a/profile/forms.pyc b/profile/forms.pyc Binary files differindex 657cbf5..a9a5609 100644 --- a/profile/forms.pyc +++ b/profile/forms.pyc diff --git a/profile/urls.py b/profile/urls.py index b13cc25..a577d56 100644 --- a/profile/urls.py +++ b/profile/urls.py @@ -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 --git a/profile/views.py b/profile/views.py index d0840fe..68e22d0 100755 --- a/profile/views.py +++ b/profile/views.py @@ -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) |