diff options
author | Prabhu Ramachandran | 2017-04-27 18:10:52 +0530 |
---|---|---|
committer | GitHub | 2017-04-27 18:10:52 +0530 |
commit | 9d93da09f1483271827099079abf97d84111330f (patch) | |
tree | a21f40a84daf2996868b41bb3ea51ad8b755d0e9 /yaksh | |
parent | 9991300f25ad9d83e0724342c38c7e0f20cee895 (diff) | |
parent | ba54ff69f0eb8ff509e4e043c42b933771e205c5 (diff) | |
download | online_test-9d93da09f1483271827099079abf97d84111330f.tar.gz online_test-9d93da09f1483271827099079abf97d84111330f.tar.bz2 online_test-9d93da09f1483271827099079abf97d84111330f.zip |
Merge pull request #272 from ankitjavalkar/course-code
Course code feature
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/forms.py | 13 | ||||
-rw-r--r-- | yaksh/models.py | 6 | ||||
-rw-r--r-- | yaksh/templates/yaksh/quizzes_user.html | 26 | ||||
-rw-r--r-- | yaksh/views.py | 23 |
4 files changed, 58 insertions, 10 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index f7f7a10..d56fb04 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -274,10 +274,21 @@ class QuestionFilterForm(forms.Form): class CourseForm(forms.ModelForm): """ course form for moderators """ + def save(self, commit=True, *args, **kwargs): + instance = super(CourseForm, self).save(commit=False) + if instance.code: + instance.hidden = True + else: + instance.hidden = False + + if commit: + instance.save() + return instance + class Meta: model = Course exclude = ['creator', 'requests', 'students', 'rejected', - 'created_on', 'is_trial', 'teachers'] + 'created_on', 'is_trial', 'hidden', 'teachers'] class ProfileForm(forms.ModelForm): diff --git a/yaksh/models.py b/yaksh/models.py index 6646615..5fa828c 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -49,7 +49,7 @@ question_types = ( enrollment_methods = ( ("default", "Enroll Request"), - ("open", "Open Course"), + ("open", "Open Enrollment"), ) test_case_types = ( @@ -112,6 +112,8 @@ class CourseManager(models.Manager): trial_course.enroll(False, user) return trial_course + def get_hidden_courses(self, code): + return self.filter(code=code, hidden=True) ############################################################################### class Course(models.Model): @@ -119,6 +121,8 @@ class Course(models.Model): name = models.CharField(max_length=128) enrollment = models.CharField(max_length=32, choices=enrollment_methods) active = models.BooleanField(default=True) + code = models.CharField(max_length=128, null=True, blank=True) + hidden = models.BooleanField(default=False) creator = models.ForeignKey(User, related_name='creator') students = models.ManyToManyField(User, related_name='students') requests = models.ManyToManyField(User, related_name='requests') diff --git a/yaksh/templates/yaksh/quizzes_user.html b/yaksh/templates/yaksh/quizzes_user.html index ce74844..90d7f8e 100644 --- a/yaksh/templates/yaksh/quizzes_user.html +++ b/yaksh/templates/yaksh/quizzes_user.html @@ -1,6 +1,26 @@ {% extends "user.html" %} {% block pagetitle %} {{ title }} {% endblock %} {% block main %} + {% if 'Enrolled Courses' not in title%} + <div class="row well"> + <form action="{{ URL_ROOT }}/exam/quizzes/" method="post" id="custom-search-form" class="form-search form-horizontal pull-right"> + {% csrf_token %} + <div class="col-md-12"> + <div class="input-group"> + <span class="input-group-addon" id="basic-addon1">Search Course</span> + <input type="text" name="course_code" class="form-control" placeholder="Course Code"> + <span class="input-group-btn"> + <button class="btn btn-default" type="submit">Search</button> + <button class="btn btn-default" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/quizzes/");'>Cancel</button> + </span> + </div> + </div> + </form> + </div> + {% endif %} +{% if not courses %} +No Courses to display +{% endif %} {% for course in courses %} <div class="row well"> <div class="col-md-12"> @@ -9,6 +29,8 @@ <h4><b><u> {{ course.name }} by {{ course.creator.get_full_name }}</u></b></h4> </div> <div class="col-md-4"> + {% if course.hidden %}<span class="label label-info">Open Course</span> + {% endif %} {% if user in course.requests.all %} <span class="label label-warning">Request Pending </span> {% elif user in course.rejected.all %}<span class="label label-danger">Request Rejected</span> {% elif user in course.students.all %}<span class="label label-info">Enrolled</span> @@ -41,7 +63,7 @@ </td> {% else %} <td> - {{ quiz.description }} <span class="label label-danger">INACTIVE</span><br> + {{ quiz.description }} <span class="label label-danger">Inactive</span><br> </td> {% endif %} <td> @@ -83,7 +105,7 @@ {% endif %} </div> </div><!--/row--> - </br> +</br> {% endfor %} {% endblock %} diff --git a/yaksh/views.py b/yaksh/views.py index 94cb0c6..d298e5e 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -122,14 +122,25 @@ def user_logout(request): def quizlist_user(request, enrolled=None): """Show All Quizzes that is available to logged-in user.""" user = request.user - if enrolled is not None: + ci = RequestContext(request) + + if request.method == "POST": + course_code = request.POST.get('course_code') + hidden_courses = Course.objects.get_hidden_courses(code=course_code) + courses = hidden_courses if hidden_courses else None + title = 'Search' + + elif enrolled is not None: courses = user.students.all() title = 'Enrolled Courses' else: - courses = Course.objects.filter(active=True, is_trial=False) + courses = Course.objects.filter(active=True, is_trial=False, hidden=False) title = 'All Courses' + context = {'user': user, 'courses': courses, 'title': title} - return my_render_to_response("yaksh/quizzes_user.html", context) + + return my_render_to_response("yaksh/quizzes_user.html", context, + context_instance=ci) @login_required @@ -639,8 +650,8 @@ def enroll_request(request, course_id): user = request.user ci = RequestContext(request) course = get_object_or_404(Course, pk=course_id) - if not course.is_active_enrollment: - msg = 'Enrollment for this course has been closed, please contact your '\ + if not course.is_active_enrollment and course.hidden: + msg = 'Unable to add enrollments for this course, please contact your '\ 'instructor/administrator.' return complete(request, msg, attempt_num=None, questionpaper_id=None) @@ -1238,7 +1249,7 @@ def search_teacher(request, course_id): if not is_moderator(user): raise Http404('You are not allowed to view this page!') - context = {} + context = {'success': False} course = get_object_or_404(Course, pk=course_id) context['course'] = course |