summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/forms.py4
-rw-r--r--yaksh/urls.py10
-rw-r--r--yaksh/views.py19
3 files changed, 23 insertions, 10 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py
index 8cd18a2..271b503 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -197,7 +197,9 @@ class EditProfile(forms.ModelForm):
first_name = forms.CharField(max_length=30)
last_name = forms.CharField(max_length=30)
- def __init__(self, user, *args, **kwargs):
+ def __init__(self, *args, **kwargs):
+ if 'user' in kwargs:
+ user = kwargs.pop('user')
super(EditProfile, self).__init__(*args, **kwargs)
self.fields['first_name'].initial = user.first_name
self.fields['last_name'].initial = user.last_name
diff --git a/yaksh/urls.py b/yaksh/urls.py
index ab9f90a..f1a0cf0 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -12,7 +12,7 @@ urlpatterns = [
name='password_reset_done'),
url(r'^password_reset/complete/$', password_reset_complete,
name='password_reset_complete'),
- url(r'^password_change/$', password_change,
+ url(r'^changepassword/$', password_change,
name='password_change'),
url(r'^password_change/done/$', password_change_done,
name='password_change_done'),
@@ -80,5 +80,9 @@ urlpatterns += [
url(r'^ajax/questions/filter/$', views.ajax_questions_filter),
url(r'^manage/editprofile/$', views.edit_profile),
url(r'^manage/viewprofile/$', views.view_profile),
- url(r'^manage/enroll/(?P<course_id>\d+)', views.enroll)
-] \ No newline at end of file
+ url(r'^manage/enroll/(?P<course_id>\d+)/$', views.enroll),
+ url(r'manage/enroll/rejected/(?P<course_id>\d+)/$',
+ views.enroll, {'was_rejected': True}),
+ url(r'manage/enrolled/reject/(?P<course_id>\d+)/$',
+ views.reject, {'was_enrolled': True})
+]
diff --git a/yaksh/views.py b/yaksh/views.py
index bc54a51..d76e042 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -991,11 +991,19 @@ def edit_profile(request):
context = {}
user = request.user
ci = RequestContext(request)
- profile = Profile.objects.get(user_id=user.id)
+
+ if not hasattr(user, 'profile'):
+ new_form = EditProfile(request.POST, user=user)
+ form = EditProfile(user=user)
+ else:
+ profile = Profile.objects.get(user_id=user.id)
+ new_form = EditProfile(request.POST, user=user, instance=profile)
+ form = EditProfile(user=user, instance=profile)
+
if request.method == 'POST':
- form = EditProfile(user, request.POST, instance=profile)
- if form.is_valid():
- form_data = form.save(commit=False)
+ if new_form.is_valid():
+ form_data = new_form.save(commit=False)
+ form_data.user = user
form_data.user.first_name = request.POST['first_name']
form_data.user.last_name = request.POST['last_name']
form_data.user.save()
@@ -1003,11 +1011,10 @@ def edit_profile(request):
return my_render_to_response('yaksh/profile_updated.html',
context_instance=ci)
else:
- context['form'] = form
+ context['form'] = new_form
return my_render_to_response('yaksh/editprofile.html', context,
context_instance=ci)
else:
- form = EditProfile(user, instance=profile)
context['form'] = form
return my_render_to_response('yaksh/editprofile.html', context,
context_instance=ci)