--- a/reg/views.py Mon Apr 12 15:14:03 2010 +0530
+++ b/reg/views.py Mon Apr 12 16:17:53 2010 +0530
@@ -21,7 +21,7 @@
user = request.user
events = Event.objects.all()[:10]
- return render_to_response('index.html', {'user':user})
+ return render_to_response('index.html', {'user':user, 'events':events})
def user_login(request):
""" get the user object from e-mail and then check for password.
@@ -64,8 +64,8 @@
data = form.cleaned_data
reg_events.create_user(email=data['email'],
password=data['password'],
- firstname=data['first_name'],
- lastname=data['last_name'],
+ first_name=data['first_name'],
+ last_name=data['last_name'],
gender=data['gender'],
profession=data['profession'],
affiliated_to=data['affiliated_to'],
@@ -284,5 +284,44 @@
else:
return redirect("/reg")
+def view_profile(request):
+ """ check if user is logged in.
+ then show the profile.
+ """
+
+ user = request.user
+ if not user.is_authenticated():
+ return redirect('/reg')
+
+ user_profile = user.get_profile()
+ return render_to_response('view_profile.html', {'user':user, 'user_profile':user_profile})
+
+def edit_profile(request):
+ """ check if user is logged in.
+ """
+
+ user = request.user
+ if not user.is_authenticated():
+ return redirect('/reg')
+
+ user_profile = user.get_profile()
+
+ if request.method == "POST":
+ form = reg_forms.EditProfileForm(request.POST)
+ if form.is_valid():
+ reg_events.update_profile(user, form.cleaned_data)
+ return redirect('/reg/profile/view')
+ else:
+ return render_to_response('edit_profile.html', {'user':user, 'form':form})
+ else:
+ old_info = {'first_name': user.first_name,
+ 'last_name': user.last_name,
+ 'gender':user_profile.gender,
+ 'profession': user_profile.profession,
+ 'affiliated_to': user_profile.affiliated_to,
+ 'interests': user_profile.interests,
+ }
+ form = reg_forms.EditProfileForm(old_info)
+ return render_to_response('edit_profile.html', {'user':user, 'form':form})