diff options
author | Prabhu Ramachandran | 2016-04-26 17:15:31 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2016-04-26 17:15:31 +0530 |
commit | 825f8464ef1b2853c029cc23bf7fb89f6a9c1c09 (patch) | |
tree | 0b94516d5a969dce5bc0750e405ca45850880f21 /yaksh | |
parent | 97bdb23fbacc3e625beb96efdf58431f42604a81 (diff) | |
parent | 3be13f4868a881cbe591e9eb686872875272ac1d (diff) | |
download | online_test-825f8464ef1b2853c029cc23bf7fb89f6a9c1c09.tar.gz online_test-825f8464ef1b2853c029cc23bf7fb89f6a9c1c09.tar.bz2 online_test-825f8464ef1b2853c029cc23bf7fb89f6a9c1c09.zip |
Merge pull request #89 from adityacp/Editprofile
Profile change, Enroll students and change password
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/forms.py | 19 | ||||
-rw-r--r-- | yaksh/static/yaksh/css/base.css | 9 | ||||
-rw-r--r-- | yaksh/static/yaksh/css/question.css | 5 | ||||
-rw-r--r-- | yaksh/static/yaksh/js/course.js | 38 | ||||
-rw-r--r-- | yaksh/templates/base.html | 2 | ||||
-rw-r--r-- | yaksh/templates/manage.html | 6 | ||||
-rw-r--r-- | yaksh/templates/registration/password_change_done.html | 16 | ||||
-rw-r--r-- | yaksh/templates/registration/password_change_form.html | 18 | ||||
-rw-r--r-- | yaksh/templates/user.html | 12 | ||||
-rw-r--r-- | yaksh/templates/yaksh/course_detail.html | 40 | ||||
-rw-r--r-- | yaksh/templates/yaksh/editprofile.html | 23 | ||||
-rw-r--r-- | yaksh/templates/yaksh/login.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/profile_updated.html | 15 | ||||
-rw-r--r-- | yaksh/templates/yaksh/question.html | 8 | ||||
-rw-r--r-- | yaksh/templates/yaksh/view_profile.html | 50 | ||||
-rw-r--r-- | yaksh/urls.py | 15 | ||||
-rw-r--r-- | yaksh/views.py | 89 |
17 files changed, 329 insertions, 38 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index 84cf1c4..681eca0 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -140,7 +140,6 @@ class QuizForm(forms.ModelForm): self.fields['course'] = forms.ModelChoiceField( queryset=Course.objects.filter(creator=user)) - class Meta: model = Quiz fields = '__all__' @@ -187,3 +186,21 @@ class CourseForm(forms.ModelForm): class Meta: model = Course fields = ['name', 'active', 'enrollment'] + +class ProfileForm(forms.ModelForm): + """ profile form for students and moderators """ + + class Meta: + model = Profile + fields = ['first_name', 'last_name', 'institute', + 'department', 'roll_number', 'position'] + + first_name = forms.CharField(max_length=30) + last_name = forms.CharField(max_length=30) + + def __init__(self, *args, **kwargs): + if 'user' in kwargs: + user = kwargs.pop('user') + super(ProfileForm, self).__init__(*args, **kwargs) + self.fields['first_name'].initial = user.first_name + self.fields['last_name'].initial = user.last_name diff --git a/yaksh/static/yaksh/css/base.css b/yaksh/static/yaksh/css/base.css index af3ba8b..2273263 100644 --- a/yaksh/static/yaksh/css/base.css +++ b/yaksh/static/yaksh/css/base.css @@ -221,7 +221,7 @@ body { box-shadow: 0 1px 2px rgba(0,0,0,.15); } .content .span10, -.content { +.content .span14{ min-height: 475px; } .content .span4 { @@ -495,8 +495,6 @@ h4 small { } h5 { font-size: 14px; - color:white; - text-align:left; } h6 { font-size: 13px; @@ -1796,7 +1794,6 @@ footer { -ms-transition: 0.1s linear all; -o-transition: 0.1s linear all; transition: 0.1s linear all; - margin-right:50px } .btn:hover { background-position: 0 -15px; @@ -2360,7 +2357,6 @@ height:100px; width:730px; resize:None; overflow:hidden; - } .bash{ padding:0; @@ -2370,3 +2366,6 @@ resize:none; overflow:hidden; background-color:white; } +textarea[readonly]{ +cursor: not-allowed; +} diff --git a/yaksh/static/yaksh/css/question.css b/yaksh/static/yaksh/css/question.css index 06109e5..5d5607a 100644 --- a/yaksh/static/yaksh/css/question.css +++ b/yaksh/static/yaksh/css/question.css @@ -13,11 +13,11 @@ } .td1-class { - width:300px; + width:300px; } .td2-class { - width:50px; + width:50px; padding: 5px 10px 9px; } .page-header { @@ -43,4 +43,3 @@ .lineObj{ color: grey; } - diff --git a/yaksh/static/yaksh/js/course.js b/yaksh/static/yaksh/js/course.js new file mode 100644 index 0000000..3a21f0d --- /dev/null +++ b/yaksh/static/yaksh/js/course.js @@ -0,0 +1,38 @@ +$(document).ready(function(){
+$(".checkall").click( function(){
+ if($(this).attr("checked")) {
+ $("#enroll-all input:checkbox").each(function(index, element) {
+ $(this).attr('checked', true);
+ });
+ }
+ else {
+ $("#enroll-all input:checkbox").each(function(index, element) {
+ $(this).attr('checked', false);
+ });
+ }
+ });
+$(".enroll").click( function(){
+ if($(this).attr("checked")) {
+ $("#enroll input:checkbox").each(function(index, element) {
+ $(this).attr('checked', true);
+ });
+ }
+ else {
+ $("#enroll input:checkbox").each(function(index, element) {
+ $(this).attr('checked', false);
+ });
+ }
+ });
+$(".reject").click( function(){
+ if($(this).attr("checked")) {
+ $("#reject input:checkbox").each(function(index, element) {
+ $(this).attr('checked', true);
+ });
+ }
+ else {
+ $("#reject input:checkbox").each(function(index, element) {
+ $(this).attr('checked', false);
+ });
+ }
+ });
+});
diff --git a/yaksh/templates/base.html b/yaksh/templates/base.html index d3e4f91..83db7ff 100644 --- a/yaksh/templates/base.html +++ b/yaksh/templates/base.html @@ -17,7 +17,7 @@ <link rel="stylesheet" href="{{ URL_ROOT }}/static/yaksh/css/base.css" type="text/css" /> {% block css %} {% endblock %} - +<script language="JavaScript" type="text/javascript" src="{{ URL_ROOT }}/static/yaksh/js/jquery-1.4.2.min.js"></script> {% block script %} {% endblock %} </head> diff --git a/yaksh/templates/manage.html b/yaksh/templates/manage.html index 11e2187..4b9e2ba 100644 --- a/yaksh/templates/manage.html +++ b/yaksh/templates/manage.html @@ -10,12 +10,12 @@ <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 %} {% endblock %} - +<script language="JavaScript" type="text/javascript" src="{{ URL_ROOT }}/static/yaksh/js/jquery-1.4.2.min.js"></script> {% block script %} {% endblock %} </head> @@ -30,6 +30,8 @@ <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/viewprofile">My Profile</a></li> +<li><a href="{{ URL_ROOT }}/exam/changepassword">Change Password</a></li> </ul> <ul style="float:right;"> <li><strong><a style='cursor:pointer' onClick='location.replace("{{URL_ROOT}}/exam/complete/");'>Log out</a></strong></li> diff --git a/yaksh/templates/registration/password_change_done.html b/yaksh/templates/registration/password_change_done.html new file mode 100644 index 0000000..fef07d1 --- /dev/null +++ b/yaksh/templates/registration/password_change_done.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block title %}Password change successful{% endblock %} +{% block pagetitle %}Online Test {% endblock %} +{% block script %} +<script type="text/javascript"> + window.setTimeout(function() + { + location.href="{{ URL_ROOT }}/exam/" + }, 2000); +</script> +{% endblock %} +{% block content %} +<h3>Your password has been changed successfully.</h3> +<h4>Redirecting ...</h4> +{% endblock %}
\ No newline at end of file diff --git a/yaksh/templates/registration/password_change_form.html b/yaksh/templates/registration/password_change_form.html new file mode 100644 index 0000000..48292f8 --- /dev/null +++ b/yaksh/templates/registration/password_change_form.html @@ -0,0 +1,18 @@ +{% extends "base.html" %} +<!DOCTYPE html> +{% block title %} Change Password {% endblock %} + +{% block pagetitle %} Online Test {% endblock %} + +{% block content %} +<form action="" method="post" > + {% csrf_token %} + <center> + <table class=span1> + {{ form }} + </table> + </center> + <center><button class="btn" type="submit">Change Password</button> + <button class="btn" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/");'>Cancel</button></center> +</form> +{% endblock content %} diff --git a/yaksh/templates/user.html b/yaksh/templates/user.html index 00151d2..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 %} @@ -28,9 +28,11 @@ <div class="container"> <h3 class="brand"><strong>Online Test</h3></strong> <ul> - <li><a href="{{ URL_ROOT }}/exam/quizzes">Quizzes</a></li> - <li><a href="{{ URL_ROOT }}/exam/results">Results</a></li> - </ul> + <li><a href="{{ URL_ROOT }}/exam/quizzes">Quizzes</a></li> + <li><a href="{{ URL_ROOT }}/exam/results">Results</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;"> <li><strong><a style='cursor:pointer' onClick='location.replace("{{URL_ROOT}}/exam/complete/");'>Log out</a></strong></li> </ul> diff --git a/yaksh/templates/yaksh/course_detail.html b/yaksh/templates/yaksh/course_detail.html index ed56585..7169667 100644 --- a/yaksh/templates/yaksh/course_detail.html +++ b/yaksh/templates/yaksh/course_detail.html @@ -7,50 +7,82 @@ {% block css %} <link rel="stylesheet" media="all" type="text/css" href="{{ URL_ROOT }}/static/yaksh/css/course.css" /> {% endblock %} - +{% block script %} +<script language="JavaScript" type="text/javascript" src="{{ URL_ROOT }}/static/yaksh/js/course.js"></script> +{% endblock %} {% block manage %} <div class="row"> <div class="span6 wrap"> <center><b><u>Requests</u></b></center><br> + {% if course.get_requests %} + <input type="checkbox" class="checkall"/> <font size="2">Select all</font> + <div id="enroll-all"> + <form action="{{URL_ROOT}}/exam/manage/enroll/{{ course.id }}/" method="post"> + {% csrf_token %} {% for request in course.get_requests %} <div class="well"> <div class="row"> <div class="span3" style="padding-top:10px"> - {{ request.username }} + <input type="checkbox" name="check" value="{{ request.id }}"> + <a href="#" data-toggle="tooltip" title=" Full Name: {{ request.get_full_name }}
Institute: {{ request.profile.institute }}
Department: {{ request.profile.department}}
Roll Number: {{ request.profile.roll_number }}"> {{ request.username }}</a> </div> <a class="btn success" href="{{URL_ROOT}}/exam/manage/enroll/{{ course.id }}/{{ request.id }}/"> Enroll </a> <a class="btn danger" href="{{URL_ROOT}}/exam/manage/reject/{{ course.id }}/{{ request.id }}/"> Reject </a> </div> </div> {% endfor %} + <button class="btn success" type="submit" name='enroll' value='enroll'>Enroll Selected</button> + </div> + {% endif %} + </form> </div> <div class="span6 wrap"> <center><b><u>Rejected</u></b></center><br> + {% if course.get_rejected %} + <input type="checkbox" class="enroll"/> <font size="2">Select all</font> + <div id="enroll"> {% for rejected in course.get_rejected %} + <form action="{{URL_ROOT}}/exam/manage/enroll/rejected/{{ course.id }}/" method="post"> + {% csrf_token %} <div class="well"> <div class="row"> <div class="span4" style="padding-top:10px"> - {{ rejected.username }} + <input type="checkbox" name="check" value="{{ rejected.id }}"> + <a href="#" data-toggle="tooltip" title=" Full Name: {{ rejected.get_full_name }}
Institute: {{ rejected.profile.institute }}
Department: {{ rejected.profile.department}}
Roll Number: {{ rejected.profile.roll_number }}"> {{ rejected.username }}</a> </div> <a class="btn success" href="{{URL_ROOT}}/exam/manage/enroll/rejected/{{ course.id }}/{{ rejected.id }}/"> Enroll </a> </div> </div> {% endfor %} + <button class="btn success" type="submit" name='enroll' value='enroll'>Enroll Selected</button> + </div> + {% endif %} + </form> </div> </div> <br> <div class="row"> <div class="span6 offset4 wrap"> <center><b><u>Enrolled</u></b></center><br> + {% if course.get_enrolled %} + <input type="checkbox" class="reject"/> <font size="2">Select all</font> + <div id="reject"> {% for enrolled in course.get_enrolled %} + <form action="{{URL_ROOT}}/exam/manage/enrolled/reject/{{ course.id }}/" method="post"> + {% csrf_token %} <div class="well"> <div class="row"> <div class="span4" style="padding-top:10px"> - {{ enrolled.username }} + <input type="checkbox" name="check" value="{{ enrolled.id }}"> + <a href="#" data-toggle="tooltip" title=" Full Name: {{ enrolled.get_full_name }}
Institute: {{ enrolled.profile.institute }}
Department: {{ enrolled.profile.department}}
Roll Number: {{ enrolled.profile.roll_number }}"> {{ enrolled.username }}</a> </div> <a class="btn danger" href="{{URL_ROOT}}/exam/manage/enrolled/reject/{{ course.id }}/{{ enrolled.id }}/"> Reject </a> </div> </div> {% endfor %} + <button class="btn danger" type="submit" name='reject' value='reject'>Reject Selected</button> + </div> + {% endif %} + </form> </div> </div> <div class="pull-right"> diff --git a/yaksh/templates/yaksh/editprofile.html b/yaksh/templates/yaksh/editprofile.html new file mode 100644 index 0000000..cdccfc0 --- /dev/null +++ b/yaksh/templates/yaksh/editprofile.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} + +{% block title %} Edit Profile {% endblock %} + +{% block pagetitle %} Online Test {% endblock %} +{% block formtitle %} Please fill in the following details {% endblock %} + +{% block content %} +{% 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"> + {{ form.as_table }} + </table> + </center> + <center><button class="btn" type="submit">Save</button> + <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/login.html b/yaksh/templates/yaksh/login.html index d679748..dfeac1e 100644 --- a/yaksh/templates/yaksh/login.html +++ b/yaksh/templates/yaksh/login.html @@ -14,7 +14,7 @@ <center><table class=span1> {{ form.as_table }} </table></center> - <center><button class="btn" type="submit" style="margin-left: 50px">Login</button> <button class="btn" type="reset">Cancel</button></center> + <center><button class="btn" type="submit">Login</button> <button class="btn" type="reset">Cancel</button></center> <br><center><a href="{{URL_ROOT}}/exam/forgotpassword/">Forgot Password?</a></center><br> <center><a href="{{URL_ROOT}}/exam/register/">New User? Sign-Up </a></center> </form> diff --git a/yaksh/templates/yaksh/profile_updated.html b/yaksh/templates/yaksh/profile_updated.html new file mode 100644 index 0000000..6ccf177 --- /dev/null +++ b/yaksh/templates/yaksh/profile_updated.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} +<!DOCTYPE html> +{% block title %} Profile {% endblock %} + +{% block pagetitle %} Online Test {% endblock %} + +{% block script %} +<script> + window.setTimeout(function(){ location.href="{{ URL_ROOT }}/exam/" }, 2000); +</script> +{% endblock script %} +{% block content %} +<h3>Your Profile is changed {{ user.first_name }}</h3> +<h3>Redirecting...</h3> +{% endblock content %} diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index 1fb70b8..e542fe9 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -116,11 +116,9 @@ function call_skip(url) <div class="fill"> <div class="container"> <h3 class="brand"><strong>Online Test</h3></strong> - <ul> - <li><h5><a> Hi {{ paper.user.first_name.title}} {{ paper.user.last_name.title}} </a></h5></li> - </ul><br> - <div class=time-div id="time_left"></div> - <h5>You have {{ paper.questions_left }} question(s) left in {{ paper.question_paper.quiz.description }}</h5> + <h5><a> Hi {{ paper.user.first_name.title}} {{ paper.user.last_name.title}} </a></h5> + <div class=time-div id="time_left"></div><br> + <b style="color: white; font-size: 14px;">You have {{ paper.questions_left }} question(s) left in {{ paper.question_paper.quiz.description }}</b> </div> </div> </div> diff --git a/yaksh/templates/yaksh/view_profile.html b/yaksh/templates/yaksh/view_profile.html new file mode 100644 index 0000000..be15d14 --- /dev/null +++ b/yaksh/templates/yaksh/view_profile.html @@ -0,0 +1,50 @@ +{% extends "base.html" %} + +{% block title %} View Profile {% endblock %} + +{% block pagetitle %} Online Test {% endblock %} +{% block css %} +<link rel="stylesheet" media="all" type="text/css" href="{{ URL_ROOT }}/static/yaksh/css/base.css" /> + +{% endblock %} +{% block content %} +<ul> + <a href="{{ URL_ROOT }}/exam/editprofile/">Edit Profile</a> + <a href="{{ URL_ROOT }}/exam/">Back to Home</a> +</ul> +<div class="span14"> + <center> + <h2>Your Profile Information</h2> + <table class="span1"> + <tr> + <th><label for="id_first_name"><h5>First name:</h5></label></th> + <th><label for="id_first_name"><h5>{{ user.first_name }}</h5></label></th> + </tr> + <tr> + <th><label for="id_last_name"><h5>Last name:</h5></label></th> + <th><label for="id_last_name"><h5>{{ user.last_name }}</h5></label></th> + </tr> + <tr> + <th><label for="id_email"><h5>Email:</h5></label></th> + <th><label for="id_email"><h5>{{ user.email }}</h5></label></th> + </tr> + <tr> + <th><label for="id_institute"><h5>Institute:</h5></label></th> + <th><label for="id_institute"><h5>{{ user.profile.institute }}</h5></label></th> + </tr> + <tr> + <th><label for="id_department"><h5>Department:</h5></label></th> + <th><label for="id_department"><h5>{{ user.profile.department }}</h5></label></th> + </tr> + <tr> + <th><label for="id_roll_number"><h5>Roll number:</h5></label></th> + <th><label for="id_roll_number"><h5>{{ user.profile.roll_number }}</h5></label></th> + </tr> + <tr> + <th><label for="id_position"><h5>Position:</h5></label></th> + <th><label for="id_position"><h5>{{ user.profile.position }}</h5></label></th> + </tr> + </table> + </center> +</div> +{% endblock %} diff --git a/yaksh/urls.py b/yaksh/urls.py index b2f894f..471a36b 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -1,7 +1,8 @@ from django.conf.urls import patterns, url from yaksh import views from django.contrib.auth.views import password_reset, password_reset_confirm,\ - password_reset_done, password_reset_complete + password_reset_done, password_reset_complete, password_change,\ + password_change_done urlpatterns = [ url(r'^forgotpassword/$', password_reset, name="password_reset"), @@ -11,6 +12,10 @@ urlpatterns = [ name='password_reset_done'), url(r'^password_reset/complete/$', password_reset_complete, name='password_reset_complete'), + url(r'^changepassword/$', password_change, + name='password_change'), + url(r'^password_change/done/$', password_change_done, + name='password_change_done'), ] urlpatterns += [ url(r'^$', views.index), @@ -34,7 +39,6 @@ urlpatterns += [ views.skip), url(r'^enroll_request/(?P<course_id>\d+)/$', views.enroll_request), url(r'^self_enroll/(?P<course_id>\d+)/$', views.self_enroll), - url(r'^manage/$', views.prof_manage), url(r'^manage/addquestion/$', views.add_question), url(r'^manage/addquestion/(?P<question_id>\d+)/$', views.add_question), @@ -74,4 +78,11 @@ 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'^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}), + 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 8b0a131..1709488 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -22,7 +22,7 @@ from yaksh.models import Quiz, Question, QuestionPaper, QuestionSet, Course from yaksh.models import Profile, Answer, AnswerPaper, User, TestCase from yaksh.forms import UserRegisterForm, UserLoginForm, QuizForm,\ QuestionForm, RandomQuestionForm, TestCaseFormSet,\ - QuestionFilterForm, CourseForm + QuestionFilterForm, CourseForm, ProfileForm from yaksh.xmlrpc_clients import code_server from settings import URL_ROOT from yaksh.models import AssignmentUpload @@ -65,6 +65,9 @@ def is_moderator(user): if user.groups.filter(name='moderator').count() == 1: return True +def has_profile(user): + """ check if user has profile """ + return True if hasattr(user, 'profile') else False def index(request): """The start page. @@ -172,7 +175,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) @@ -603,31 +605,49 @@ def courses(request): @login_required def course_detail(request, course_id): user = request.user + ci = RequestContext(request) if not is_moderator(user): raise Http404('You are not allowed to view this page') course = get_object_or_404(Course, creator=user, pk=course_id) - return my_render_to_response('yaksh/course_detail.html', {'course': course}) + return my_render_to_response('yaksh/course_detail.html', {'course': course}, + context_instance=ci) @login_required -def enroll(request, course_id, user_id, was_rejected=False): +def enroll(request, course_id, user_id=None, was_rejected=False): user = request.user + ci = RequestContext(request) if not is_moderator(user): raise Http404('You are not allowed to view this page') course = get_object_or_404(Course, creator=user, pk=course_id) - user = get_object_or_404(User, pk=user_id) - course.enroll(was_rejected, user) + if request.method == 'POST': + enroll_ids = request.POST.getlist('check') + else: + enroll_ids = user_id + if not enroll_ids: + return my_render_to_response('yaksh/course_detail.html', {'course': course}, + context_instance=ci) + users = User.objects.filter(id__in=enroll_ids) + course.enroll(was_rejected, *users) return course_detail(request, course_id) @login_required -def reject(request, course_id, user_id, was_enrolled=False): +def reject(request, course_id, user_id=None, was_enrolled=False): user = request.user + ci = RequestContext(request) if not is_moderator(user): raise Http404('You are not allowed to view this page') course = get_object_or_404(Course, creator=user, pk=course_id) - user = get_object_or_404(User, pk=user_id) - course.reject(was_enrolled, user) + if request.method == 'POST': + reject_ids = request.POST.getlist('check') + else: + reject_ids = user_id + if not reject_ids: + return my_render_to_response('yaksh/course_detail.html', {'course': course}, + context_instance=ci) + users = User.objects.filter(id__in=reject_ids) + course.reject(was_enrolled, *users) return course_detail(request, course_id) @@ -954,3 +974,54 @@ def design_questionpaper(request): context = {'form': form, 'questionpaper':True} return my_render_to_response('yaksh/design_questionpaper.html', context, context_instance=ci) + +@login_required +def view_profile(request): + """ view moderators and users profile """ + + user = request.user + ci = RequestContext(request) + context = {} + if has_profile(user): + return my_render_to_response('yaksh/view_profile.html', {'user':user}) + else: + form = ProfileForm(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): + """ edit profile details facility for moderator and students """ + + context = {} + user = request.user + ci = RequestContext(request) + + if has_profile(user): + profile = Profile.objects.get(user_id=user.id) + else: + profile = None + + if request.method == 'POST': + form = ProfileForm(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'] + form_data.user.save() + form_data.save() + return my_render_to_response('yaksh/profile_updated.html', + context_instance=ci) + else: + context['form'] = form + return my_render_to_response('yaksh/editprofile.html', context, + context_instance=ci) + else: + form = ProfileForm(user=user, instance=profile) + context['form'] = form + return my_render_to_response('yaksh/editprofile.html', context, + context_instance=ci) |