diff options
-rw-r--r-- | yaksh/templates/manage.html | 4 | ||||
-rw-r--r-- | yaksh/templates/user.html | 4 | ||||
-rw-r--r-- | yaksh/templates/yaksh/editprofile.html | 8 | ||||
-rw-r--r-- | yaksh/templates/yaksh/view_profile.html | 2 | ||||
-rw-r--r-- | yaksh/urls.py | 4 | ||||
-rw-r--r-- | yaksh/views.py | 61 |
6 files changed, 46 insertions, 37 deletions
diff --git a/yaksh/templates/manage.html b/yaksh/templates/manage.html index a10291b..a4564f9 100644 --- a/yaksh/templates/manage.html +++ b/yaksh/templates/manage.html @@ -10,7 +10,7 @@ <meta name="description" content=""> <meta name="author" content=""> {% endblock %} - + <link rel="stylesheet" href="{{ URL_ROOT }}/static/yaksh/css/base.css" type="text/css" /> <link rel="stylesheet" href="{{ URL_ROOT }}/static/yaksh/css/manage.css" type="text/css" /> {% block css %} @@ -30,7 +30,7 @@ <li><a href="{{ URL_ROOT }}/exam/manage/gradeuser">Grade User</a></li> <li><a href="{{ URL_ROOT }}/exam/manage/monitor">Monitor</a></li> <li><a href="{{ URL_ROOT }}/exam/manage/courses">Courses</a></li> -<li><a href="{{ URL_ROOT }}/exam/manage/viewprofile">My Profile</a></li> +<li><a href="{{ URL_ROOT }}/exam/viewprofile">My Profile</a></li> <li><a href="{{ URL_ROOT }}/exam/changepassword">Change Password</a></li> </ul> <ul style="float:right;"> diff --git a/yaksh/templates/user.html b/yaksh/templates/user.html index 936601e..4074656 100644 --- a/yaksh/templates/user.html +++ b/yaksh/templates/user.html @@ -13,8 +13,8 @@ <meta name="description" content=""> <meta name="author" content=""> {% endblock %} - - <link rel="stylesheet" href="{{ URL_ROOT }}/static/yaksh/css/base.css" type="text/css" /> + + <link rel="stylesheet" href="{{ URL_ROOT }}/static/yaksh/css/base.css" type="text/css" /> {% block css %} {% endblock %} diff --git a/yaksh/templates/yaksh/editprofile.html b/yaksh/templates/yaksh/editprofile.html index f04f8fb..75be563 100644 --- a/yaksh/templates/yaksh/editprofile.html +++ b/yaksh/templates/yaksh/editprofile.html @@ -6,8 +6,10 @@ {% block formtitle %} Please fill in the following details {% endblock %} {% block content %} - -<form action="" method="post" > +{% if msg %} +<center><h5>Your profile does not exist. Please fill in your details</h5></center> +{% endif %} +<form action="{{URL_ROOT}}/exam/editprofile/" method="post" > {% csrf_token %} <center> <table class=span1> @@ -15,7 +17,7 @@ </table> </center> <center><button class="btn" type="submit">Save</button> - <button class="btn" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/viewprofile");'>Cancel</button> </center> + <button class="btn" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/");'>Cancel</button> </center> </form> {% endblock content %} diff --git a/yaksh/templates/yaksh/view_profile.html b/yaksh/templates/yaksh/view_profile.html index 3233510..69dac5a 100644 --- a/yaksh/templates/yaksh/view_profile.html +++ b/yaksh/templates/yaksh/view_profile.html @@ -9,7 +9,7 @@ {% endblock %} {% block content %} <ul> - <a href="{{ URL_ROOT }}/exam/manage/editprofile">Edit Profile</a> + <a href="{{ URL_ROOT }}/exam/editprofile/">Edit Profile</a> <a href="{{ URL_ROOT }}/exam/">Back to Home</a> </ul> <div class="span14"> diff --git a/yaksh/urls.py b/yaksh/urls.py index f1a0cf0..471a36b 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -78,8 +78,8 @@ urlpatterns += [ url(r'manage/toggle_status/(?P<course_id>\d+)/$', views.toggle_course_status), url(r'^ajax/questionpaper/(?P<query>.+)/$', views.ajax_questionpaper), 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'^editprofile/$', views.edit_profile), + url(r'^viewprofile/$', views.view_profile), url(r'^manage/enroll/(?P<course_id>\d+)/$', views.enroll), url(r'manage/enroll/rejected/(?P<course_id>\d+)/$', views.enroll, {'was_rejected': True}), diff --git a/yaksh/views.py b/yaksh/views.py index d76e042..5c30d04 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -172,7 +172,6 @@ def add_question(request, question_id=None): {'form': form, 'formset': test_case_formset}, context_instance=ci) - else: d = Question.objects.get(id=question_id) form = QuestionForm(request.POST, instance=d) @@ -620,15 +619,13 @@ def enroll(request, course_id, user_id=None, was_rejected=False): course = get_object_or_404(Course, creator=user, pk=course_id) if request.method == 'POST': enroll_ids = request.POST.getlist('check') - if enroll_ids is not None: - enroll_users = User.objects.filter(id__in=enroll_ids) - course.enroll(was_rejected, *enroll_users) - elif user_id is None: + else: + enroll_ids = user_id + if not enroll_ids: return my_render_to_response('yaksh/course_detail.html', {'course': course}, context_instance=ci) - else: - user = get_object_or_404(User, pk=user_id) - course.enroll(was_rejected, user) + users = User.objects.filter(id__in=enroll_ids) + course.enroll(was_rejected, *users) return course_detail(request, course_id) @@ -641,15 +638,13 @@ def reject(request, course_id, user_id=None, was_enrolled=False): course = get_object_or_404(Course, creator=user, pk=course_id) if request.method == 'POST': reject_ids = request.POST.getlist('check') - if reject_ids is not None: - reject_users = User.objects.filter(id__in=reject_ids) - course.reject(was_enrolled, *reject_users) - elif user_id is None: + else: + reject_ids = user_id + if not reject_ids: return my_render_to_response('yaksh/course_detail.html', {'course': course}, context_instance=ci) - else: - user = get_object_or_404(User, pk=user_id) - course.reject(was_enrolled, user) + users = User.objects.filter(id__in=reject_ids) + course.reject(was_enrolled, *users) return course_detail(request, course_id) @@ -982,7 +977,17 @@ def view_profile(request): """ view moderators and users profile """ user = request.user - return my_render_to_response('yaksh/view_profile.html', {'user':user}) + ci = RequestContext(request) + context = {} + if hasattr(user, 'profile'): + return my_render_to_response('yaksh/view_profile.html', {'user':user}) + else: + form = EditProfile(user=user) + msg = True + context['form'] = form + context['msg'] = msg + return my_render_to_response('yaksh/editprofile.html', context, + context_instance=ci) @login_required def edit_profile(request): @@ -992,17 +997,14 @@ def edit_profile(request): user = request.user ci = RequestContext(request) - 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': - if new_form.is_valid(): - form_data = new_form.save(commit=False) + if not hasattr(user, 'profile'): + form = EditProfile(request.POST, user=user) + else: + profile = Profile.objects.get(user_id=user.id) + form = EditProfile(request.POST, user=user, instance=profile) + if form.is_valid(): + form_data = 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'] @@ -1011,10 +1013,15 @@ def edit_profile(request): return my_render_to_response('yaksh/profile_updated.html', context_instance=ci) else: - context['form'] = new_form + context['form'] = form return my_render_to_response('yaksh/editprofile.html', context, context_instance=ci) else: + if not hasattr(user, 'profile'): + form = EditProfile(user=user) + else: + profile = Profile.objects.get(user_id=user.id) + form = EditProfile(user=user, instance=profile) context['form'] = form return my_render_to_response('yaksh/editprofile.html', context, context_instance=ci) |