From c5ae3d4589a71c3f3b9f622c7b67a04277269cde Mon Sep 17 00:00:00 2001 From: prathamesh Date: Tue, 4 Oct 2016 16:57:25 +0530 Subject: Edit Question Paper Feature. Can edit question paper. For creating new and editing existing question paper, same UI and view is used. Ajax previously used for creation is removed. Not necessary as post request handles the same. Removed unnecessary js. --- yaksh/forms.py | 13 +- yaksh/models.py | 4 +- yaksh/static/yaksh/css/question_paper_creation.css | 12 +- yaksh/static/yaksh/js/question_paper_creation.js | 218 ++------------------- yaksh/templates/manage.html | 6 + yaksh/templates/yaksh/add_quiz.html | 2 +- yaksh/templates/yaksh/ajax_questions.html | 31 --- yaksh/templates/yaksh/courses.html | 25 ++- yaksh/templates/yaksh/design_questionpaper.html | 178 ++++++++++------- yaksh/urls.py | 8 +- yaksh/views.py | 174 ++++++++-------- 11 files changed, 258 insertions(+), 413 deletions(-) delete mode 100644 yaksh/templates/yaksh/ajax_questions.html (limited to 'yaksh') diff --git a/yaksh/forms.py b/yaksh/forms.py index 23131b7..7d4a0d3 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -1,6 +1,6 @@ from django import forms -from yaksh.models import get_model_class, Profile, Quiz, Question, TestCase, Course, StandardTestCase, StdioBasedTestCase - +from yaksh.models import get_model_class, Profile, Quiz, Question, TestCase, Course,\ + QuestionPaper, StandardTestCase, StdioBasedTestCase from django.contrib.auth import authenticate from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType @@ -195,7 +195,7 @@ class QuestionFilterForm(forms.Form): super(QuestionFilterForm, self).__init__(*args, **kwargs) questions = Question.objects.filter(user_id=user.id) points_list = questions.values_list('points', flat=True).distinct() - points_options = [('select', 'Select Marks')] + points_options = [(None, 'Select Marks')] points_options.extend([(point, point) for point in points_list]) self.fields['marks'] = forms.FloatField(widget=forms.Select\ (choices=points_options)) @@ -211,6 +211,7 @@ class CourseForm(forms.ModelForm): model = Course fields = ['name', 'active', 'enrollment'] + class ProfileForm(forms.ModelForm): """ profile form for students and moderators """ @@ -232,3 +233,9 @@ class ProfileForm(forms.ModelForm): class UploadFileForm(forms.Form): file = forms.FileField() + + +class QuestionPaperForm(forms.ModelForm): + class Meta: + model = QuestionPaper + fields = ['shuffle_questions'] diff --git a/yaksh/models.py b/yaksh/models.py index 7c4d5c4..a6537e1 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -604,10 +604,10 @@ class QuestionPaper(models.Model): random_questions = models.ManyToManyField("QuestionSet") # Option to shuffle questions, each time a new question paper is created. - shuffle_questions = models.BooleanField(default=False) + shuffle_questions = models.BooleanField(default=False, blank=False) # Total marks for the question paper. - total_marks = models.FloatField() + total_marks = models.FloatField(default=0.0, blank=True) objects = QuestionPaperManager() diff --git a/yaksh/static/yaksh/css/question_paper_creation.css b/yaksh/static/yaksh/css/question_paper_creation.css index c915320..588b65c 100644 --- a/yaksh/static/yaksh/css/question_paper_creation.css +++ b/yaksh/static/yaksh/css/question_paper_creation.css @@ -5,9 +5,6 @@ body { line-height: 18px; color: #404040; } -.clearfix { - clear: both; -} .tabs li { text-align: center; width: 33%; @@ -48,7 +45,7 @@ body { padding: 7px 0; border: 2px solid #f5f5f5; } -#selectors .span4 { +#selectors .col-md-6 { margin-left: 0; } #id_question_type { @@ -57,8 +54,8 @@ body { #id_marks { width: 100%; } -#fixed-questions .span7 > div, -#random-questions .span7 > div{ +#fixed-questions .col-md-6 > div, +#random-questions .col-md-6 > div{ background: #f5f5f5; height: 200px; border: 1px solid #333333; @@ -111,9 +108,6 @@ body { .red-alert { border: 2px solid red; } -#myModal .qcard .remove{ - display: none; -} .well{ padding: 5px; } diff --git a/yaksh/static/yaksh/js/question_paper_creation.js b/yaksh/static/yaksh/js/question_paper_creation.js index a144540..898e491 100644 --- a/yaksh/static/yaksh/js/question_paper_creation.js +++ b/yaksh/static/yaksh/js/question_paper_creation.js @@ -1,204 +1,33 @@ $(document).ready(function(){ - /* selectors for the 3 step tabs*/ - $fixed_tab = $("#fixed-tab"); - $random_tab = $("#random-tab"); - $finish_tab = $("#finish-tab"); - - $question_type = $("#id_question_type"); - $marks = $("#id_marks"); - - $total_marks = $("#total_marks"); + $question_type = $('#id_question_type'); + $qpaper_id = $('#qpaper_id'); + $marks = $('#id_marks'); + $show = $('#show'); /* ajax requsts on selectors change */ $question_type.change(function() { - $.ajax({ - url: "/exam/ajax/questionpaper/marks/", - type: "POST", - data: { - question_type: $question_type.val() - }, - dataType: "html", - success: function(output) { - $marks.html(output); - } - }); + this.form.submit(); }); $marks.change(function() { - var fixed_question_list = []; - var fixed_inputs = $("input[name=fixed]"); - var random_question_list = []; - var random_inputs = $("input[name=random]"); - for(var i = 0; i < fixed_inputs.length; i++){ - fixed_question_list.push($(fixed_inputs[i]).val()); - } - for(var i = 0; i < random_inputs.length; i++){ - random_question_list.push($(random_inputs[i]).val()); - } - $.ajax({ - url: "/exam/ajax/questionpaper/questions/", - type: "POST", - data: { - question_type: $question_type.val(), - marks: $marks.val(), - fixed_list: fixed_question_list, - random_list: random_question_list - }, - dataType: "html", - success: function(output) { - if($fixed_tab.hasClass("active")) { - var questions = $(output).filter("#questions").html(); - $("#fixed-available").html(questions); - } else if($random_tab.hasClass("active")) { - var questions = $(output).filter("#questions").html(); - var numbers = $(output).filter("#num").html(); - $("#random-available").html(questions); - $("#number-wrapper").html(numbers); - } - } - }); - }); - - /* adding fixed questions */ - $("#add-fixed").click(function(e) { - var count = 0; - var selected = []; - var html = ""; - var $element; - var total_marks = parseFloat($total_marks.text()); - var marks_per = parseFloat($marks.val()) - $("#fixed-available input:checkbox").each(function(index, element) { - if($(this).attr("checked")) { - qid = $(this).attr("data-qid"); - if(!$(this).hasClass("ignore")) { - selected.push(qid); - $element = $("
"); - html += "
  • " + $(this).next().html() + "
  • "; - count++; - } - } - }); - html = ""; - selected = selected.join(","); - var $input = $(""); - $input.attr({ - value: selected, - name: "fixed" - }); - $remove = $("×"); - $element.html(count + " question(s) added").append(html).append($input).append($remove); - $("#fixed-added").prepend($element); - total_marks = total_marks + count * marks_per; - $total_marks.text(total_marks) - e.preventDefault(); - }); - - /* adding random questions */ - $("#add-random").click(function(e) { - $numbers = $("#numbers"); - random_number = $numbers.val() - if($numbers.val()) { - $numbers.removeClass("red-alert"); - var count = 0; - var selected = []; - var html = ""; - var $element; - var total_marks = parseFloat($total_marks.text()); - var marks_per = parseFloat($marks.val()) - $("#random-available input:checkbox").each(function(index, element) { - if($(this).attr("checked")) { - qid = $(this).attr("data-qid"); - if(!$(this).hasClass("ignore")) { - selected.push(qid); - $element = $("
    "); - html += "
  • " + $(this).next().html() + "
  • "; - count++; - } - } - }); - html = ""; - selected = selected.join(","); - var $input_random = $(""); - $input_random.attr({ - value: selected, - name: "random" - }); - var $input_number = $(""); - $input_number.attr({ - value: $numbers.val(), - name: "number" - }); - $remove = $("
    ×"); - $element.html(random_number + " question(s) will be selected from " + count + " question(s)").append(html).append($input_random).append($input_number).append($remove); - $("#random-added").prepend($element); - total_marks = total_marks + random_number * marks_per; - $total_marks.text(total_marks) - } else { - $numbers.addClass("red-alert"); - } - e.preventDefault(); - }); - - /* removing added questions */ - $(".qcard .remove").live("click", function(e) { - var marks_per = $(this).attr('data-marks'); - var num_question = $(this).attr('data-num'); - var sub_marks = marks_per*num_question; - var total_marks = parseFloat($total_marks.text()); - total_marks = total_marks - sub_marks; - $total_marks.text(total_marks); - - $(this).parent().slideUp("normal", function(){ $(this).remove(); }); - e.preventDefault(); + this.form.submit(); }); /* showing/hiding selectors on tab click */ $(".tabs li").click(function() { if($(this).attr("id") == "finish-tab") { $("#selectors").hide(); + $('#is_active').val("finish"); } else { - $question_type.val('select'); - $marks.val('select') - $("#selectors").show(); - } - }); - /* check all questions on checked*/ - $("#checkall").live("click", function(){ - if($(this).attr("checked")) { - if($("#fixed-tab").hasClass("active")) { - $("#fixed-available input:checkbox").each(function(index, element) { - $(this).attr('checked','checked'); - }); + if($(this).attr("id") == "fixed-tab") { + $('#is_active').val("fixed"); } - else { - $("#random-available input:checkbox").each(function(index, element) { - $(this).attr('checked','checked'); - }); + if($(this).attr("id") == "random-tab") { + $('#is_active').val("random"); } - } - else { - if($("#fixed-tab").hasClass("active")) { - $("#fixed-available input:checkbox").each(function(index, element) { - $(this).removeAttr('checked'); - }); - } - else { - $("#random-available input:checkbox").each(function(index, element) { - $(this).removeAttr('checked'); - }); - } - } - }); - - /* show preview on preview click */ - $("#preview").click(function(){ - questions = getQuestions() - if(questions.trim() == ""){ - $('#modal_body').html("No questions selected"); + $question_type.val('select'); + $marks.val('select') + $("#selectors").show(); } - else { - $('#modal_body').html(questions); - } - $("#myModal").modal('show'); }); /* tab change on next or previous button click */ @@ -217,21 +46,4 @@ $(document).ready(function(){ $("#random").click(); }); - /* Check at least one question is present before saving */ - $('#save').click(function(){ - questions = getQuestions(); - if(questions.trim() == ""){ - $("#modalSave").modal("show"); - } - else { - document.forms["frm"].submit(); - } - }); - - /* Fetch selected questions */ - function getQuestions(){ - var fixed_div = $("#fixed-added").html(); - var random_div = $("#random-added").html(); - return fixed_div+random_div; - } -}); //document +});//document diff --git a/yaksh/templates/manage.html b/yaksh/templates/manage.html index 63c0ea7..f4c524e 100644 --- a/yaksh/templates/manage.html +++ b/yaksh/templates/manage.html @@ -46,6 +46,12 @@ +
    +
    + {% block new_manage %} + {% endblock %} +
    +
    {% block manage %} diff --git a/yaksh/templates/yaksh/add_quiz.html b/yaksh/templates/yaksh/add_quiz.html index 5a0bee4..1c73e12 100644 --- a/yaksh/templates/yaksh/add_quiz.html +++ b/yaksh/templates/yaksh/add_quiz.html @@ -20,7 +20,7 @@ -
    +
    diff --git a/yaksh/templates/yaksh/ajax_questions.html b/yaksh/templates/yaksh/ajax_questions.html deleted file mode 100644 index e343f9b..0000000 --- a/yaksh/templates/yaksh/ajax_questions.html +++ /dev/null @@ -1,31 +0,0 @@ -
    - {% if questions %} - - Select All - {% endif %} -
      - - {% for question in questions %} -
    • - -
    • - {% endfor %} -
    -
    - -
    - -
    diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index 43f323b..dcf9af5 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -18,11 +18,10 @@ {% if user != course.creator %}

    {{course.creator.get_full_name}} added you to this course

    {% endif %} -
    -
    +

    Course {% if course.active %} @@ -35,7 +34,7 @@

    {% if user == course.creator %}

    -
    +
    Teacher(s) Added to {{ course }}
    {% if course.get_teachers %}
    @@ -65,12 +64,23 @@

    Add Teacher

    {% endif %} -
    -

    Quiz(zes)

    +
    +
    +

    Question Paper(s)

    + {% for quiz in course.get_quizzes %} + {% if quiz.questionpaper_set.get %} + Question Paper for {{ quiz.description }}
    + {% else %} +

    No Question Paper + +

    + {% endif %} {% endfor %} {% else %}

    No quiz

    @@ -79,7 +89,6 @@

    -


    diff --git a/yaksh/templates/yaksh/design_questionpaper.html b/yaksh/templates/yaksh/design_questionpaper.html index 2aa169b..435de83 100644 --- a/yaksh/templates/yaksh/design_questionpaper.html +++ b/yaksh/templates/yaksh/design_questionpaper.html @@ -1,12 +1,12 @@ {% extends "manage.html" %} -{% block subtitle %}Design Question Paper{% endblock %} +{% block title %} Design Question Paper {% endblock title %} + +{% block subtitle %} Design Question Paper {% endblock %} {% block css %} - - - - + + {% endblock %} -{% block script %} - - - - - +{% block script %} + + + + {% endblock %} -{% block manage %} - +{% block new_manage %} +
    + + {% csrf_token %} +
    Manual mode to design the {{lang}} Question Paper

    • @@ -46,42 +48,62 @@ select
    - {% csrf_token %}
    -

    Total Marks: 0

    +

    Total Marks: {{ qpaper.total_marks }}

    Please select Question type and Marks
    -
    - {{ form.question_type }} -
    -
    - {{ form.marks }} -
    -
    -
    -
    +
    + {{ filter_form.question_type }} +
    +
    + {{ filter_form.marks }} +


    -
    -
    +

    Select questions to add:

    + {% if state == "fixed" or state == "None" %} +
      + {% for question in questions %} +
    • + +
    • + {% endfor %} +
    + {% endif %}
    - Add to paper +

    +
    -
    +

    Fixed questions currently in paper:

    +
      + {% for question in fixed_questions %} +
    • + +
    • + {% endfor %} +
    +
    +
    @@ -89,25 +111,66 @@ select -
    -
    -
    +

    Select questions to add to the pool:

    + {% if state == "random" %} + +
      + {% for question in questions %} +
    • + +
    • + {% endfor %} +
    + {% endif %}
    - Add to paper +

    +
    -
    +

    Pool of questions currently in paper:

    +
      + {% for random_set in random_sets %} +
    • + +
    • + {% for question in random_set.questions.all %} +
    • + +
    • + {% endfor %} + {% endfor %} +
    +
    +
    @@ -124,11 +187,10 @@ select
    Almost finished creating your question paper


    - - +
    < Previous @@ -139,44 +201,18 @@ select
    -
    - - - - - -
    - {% endblock %} +{% block manage %} +{% endblock %} diff --git a/yaksh/urls.py b/yaksh/urls.py index c4619b6..bb8cf2e 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -68,9 +68,10 @@ urlpatterns += [ url(r'^manage/user_data/(?P\d+)/(?P\d+)/$', views.user_data), url(r'^manage/user_data/(?P\d+)/$', views.user_data), - url(r'^manage/designquestionpaper/$', views.design_questionpaper, name='design_questionpaper'), - url(r'^manage/designquestionpaper/(?P\d+)/$',\ - views.design_questionpaper), + url(r'^manage/quiz/designquestionpaper/(?P\d+)/$', views.design_questionpaper, + name='design_questionpaper'), + url(r'^manage/designquestionpaper/(?P\d+)/(?P\d+)/$', + views.design_questionpaper, name='designquestionpaper'), url(r'^manage/statistics/question/(?P\d+)/$', views.show_statistics), url(r'^manage/statistics/question/(?P\d+)/(?P\d+)/$', @@ -87,7 +88,6 @@ urlpatterns += [ url(r'manage/enrolled/reject/(?P\d+)/(?P\d+)/$', views.reject, {'was_enrolled': True}), url(r'manage/toggle_status/(?P\d+)/$', views.toggle_course_status), - url(r'^ajax/questionpaper/(?P.+)/$', views.ajax_questionpaper), url(r'^ajax/questions/filter/$', views.ajax_questions_filter), url(r'^editprofile/$', views.edit_profile, name='edit_profile'), url(r'^viewprofile/$', views.view_profile, name='view_profile'), diff --git a/yaksh/views.py b/yaksh/views.py index 4c5b9b8..f25a685 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -28,7 +28,7 @@ from yaksh.models import Profile, Answer, AnswerPaper, User, TestCase, FileUploa from yaksh.forms import UserRegisterForm, UserLoginForm, QuizForm,\ QuestionForm, RandomQuestionForm,\ QuestionFilterForm, CourseForm, ProfileForm, UploadFileForm,\ - get_object_form, FileForm + get_object_form, FileForm, QuestionPaperForm from settings import URL_ROOT from yaksh.models import AssignmentUpload from file_utils import extract_files @@ -245,7 +245,7 @@ def add_quiz(request, course_id, quiz_id=None): form = QuizForm(request.POST, user=user, course=course_id) if form.is_valid(): form.save() - return my_redirect(reverse('yaksh:design_questionpaper')) + return my_redirect("/exam/manage/courses/") else: context["form"] = form return my_render_to_response('yaksh/add_quiz.html', @@ -258,7 +258,7 @@ def add_quiz(request, course_id, quiz_id=None): if form.is_valid(): form.save() context["quiz_id"] = quiz_id - return my_redirect("/exam/manage/") + return my_redirect("/exam/manage/courses/") else: if quiz_id is None: form = QuizForm(course=course_id, user=user) @@ -630,7 +630,6 @@ def courses(request): raise Http404('You are not allowed to view this page') courses = Course.objects.filter(creator=user, is_trial=False) allotted_courses = Course.objects.filter(teachers=user, is_trial=False) - context = {'courses': courses, "allotted_courses": allotted_courses} return my_render_to_response('yaksh/courses.html', context, context_instance=ci) @@ -812,6 +811,95 @@ def ajax_questions_filter(request): {'questions': questions}) +def _get_questions(user, question_type, marks): + if question_type is None and marks is None: + return None + if question_type: + questions = Question.objects.filter(type=question_type, user=user) + if marks: + questions = questions.filter(points=marks) + return questions + + +def _remove_already_present(questionpaper_id, questions): + if questionpaper_id is None: + return questions + questionpaper = QuestionPaper.objects.get(pk=questionpaper_id) + questions = questions.exclude( + id__in=questionpaper.fixed_questions.values_list('id', flat=True)) + for random_set in questionpaper.random_questions.all(): + questions = questions.exclude( + id__in=random_set.questions.values_list('id', flat=True)) + return questions + + +@login_required +def design_questionpaper(request, quiz_id, questionpaper_id=None): + user = request.user + + if not is_moderator(user): + raise Http404('You are not allowed to view this page!') + + filter_form = QuestionFilterForm(user=user) + questions = None + marks = None + state = None + if questionpaper_id is None: + question_paper = QuestionPaper.objects.get_or_create(quiz_id=quiz_id)[0] + else: + question_paper = get_object_or_404(QuestionPaper, id=questionpaper_id) + qpaper_form = QuestionPaperForm(instance=question_paper) + + if request.method == 'POST': + + filter_form = QuestionFilterForm(request.POST, user=user) + qpaper_form = QuestionPaperForm(request.POST, instance=question_paper) + question_type = request.POST.get('question_type', None) + marks = request.POST.get('marks', None) + state = request.POST.get('is_active', None) + + if 'add-fixed' in request.POST: + question_ids = request.POST.getlist('questions', None) + for question in Question.objects.filter(id__in=question_ids): + question_paper.fixed_questions.add(question) + + if 'remove-fixed' in request.POST: + question_ids = request.POST.getlist('added-questions', None) + question_paper.fixed_questions.remove(*question_ids) + + if 'add-random' in request.POST: + question_ids = request.POST.getlist('random_questions', None) + num_of_questions = request.POST.get('num_of_questions', 1) + if question_ids and marks: + random_set = QuestionSet(marks=marks, num_questions=num_of_questions) + random_set.save() + for question in Question.objects.filter(id__in=question_ids): + random_set.questions.add(question) + question_paper.random_questions.add(random_set) + + if 'remove-random' in request.POST: + random_set_ids = request.POST.getlist('random_sets', None) + question_paper.random_questions.remove(*random_set_ids) + + if 'save' in request.POST or 'back' in request.POST: + qpaper_form.save() + return my_redirect('/exam/manage/courses/') + + if marks: + questions = _get_questions(user, question_type, marks) + questions = _remove_already_present(questionpaper_id, questions) + + question_paper.update_total_marks() + question_paper.save() + random_sets = question_paper.random_questions.all() + fixed_questions = question_paper.fixed_questions.all() + context = {'qpaper_form': qpaper_form, 'filter_form': filter_form, 'qpaper': + question_paper, 'questions': questions, 'fixed_questions': fixed_questions, + 'state': state, 'random_sets': random_sets} + return my_render_to_response('yaksh/design_questionpaper.html', context, + context_instance=RequestContext(request)) + + @login_required def show_all_questions(request): """Show a list of all the questions currently in the database.""" @@ -998,80 +1086,6 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): ) -@csrf_exempt -def ajax_questionpaper(request, query): - """ - During question paper creation, ajax call made to get question details. - """ - - user = request.user - if query == 'marks': - question_type = request.POST.get('question_type') - questions = Question.objects.filter(type=question_type, user=user) - marks = questions.values_list('points').distinct() - return my_render_to_response('yaksh/ajax_marks.html', {'marks': marks}) - elif query == 'questions': - question_type = request.POST['question_type'] - marks_selected = request.POST['marks'] - fixed_questions = request.POST.getlist('fixed_list[]') - fixed_question_list = ",".join(fixed_questions).split(',') - random_questions = request.POST.getlist('random_list[]') - random_question_list = ",".join(random_questions).split(',') - question_list = fixed_question_list + random_question_list - questions = list(Question.objects.filter(type=question_type, - points=marks_selected, user=user)) - questions = [question for question in questions \ - if not str(question.id) in question_list] - return my_render_to_response('yaksh/ajax_questions.html', - {'questions': questions}) - - -@login_required -def design_questionpaper(request): - user = request.user - ci = RequestContext(request) - - if not is_moderator(user): - raise Http404('You are not allowed to view this page!') - - if request.method == 'POST': - fixed_questions = request.POST.getlist('fixed') - random_questions = request.POST.getlist('random') - random_number = request.POST.getlist('number') - is_shuffle = request.POST.get('shuffle_questions', False) - if is_shuffle == 'on': - is_shuffle = True - - question_paper = QuestionPaper(shuffle_questions=is_shuffle) - quiz = Quiz.objects.order_by("-id")[0] - tot_marks = 0 - question_paper.quiz = quiz - question_paper.total_marks = tot_marks - question_paper.save() - if fixed_questions: - fixed_questions_ids = ",".join(fixed_questions) - fixed_questions_ids_list = fixed_questions_ids.split(',') - for question_id in fixed_questions_ids_list: - question_paper.fixed_questions.add(question_id) - if random_questions: - for random_question, num in zip(random_questions, random_number): - qid = random_question.split(',')[0] - question = Question.objects.get(id=int(qid)) - marks = question.points - question_set = QuestionSet(marks=marks, num_questions=num) - question_set.save() - for question_id in random_question.split(','): - question_set.questions.add(question_id) - question_paper.random_questions.add(question_set) - question_paper.update_total_marks() - question_paper.save() - return my_redirect('/exam/manage/courses') - else: - form = RandomQuestionForm() - 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 """ @@ -1150,7 +1164,6 @@ def search_teacher(request, course_id): Q(id=course.creator.id)) context['success'] = True context['teachers'] = teachers - return my_render_to_response('yaksh/addteacher.html', context, context_instance=ci) @@ -1179,7 +1192,6 @@ def add_teacher(request, course_id): course.add_teachers(*teachers) context['status'] = True context['teachers_added'] = teachers - return my_render_to_response('yaksh/addteacher.html', context, context_instance=ci) @@ -1187,7 +1199,7 @@ def add_teacher(request, course_id): @login_required def remove_teachers(request, course_id): """ remove user from a course """ - + user = request.user course = get_object_or_404(Course, pk=course_id) if not is_moderator(user) and (user != course.creator and user not in course.teachers.all()): -- cgit From 2ee45f6f04711c745e533abeef6b5ca55d7b4ec3 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Tue, 4 Oct 2016 18:12:54 +0530 Subject: changes in test view as redirect url changed. --- yaksh/test_views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh') diff --git a/yaksh/test_views.py b/yaksh/test_views.py index cf547b5..1d1c3f3 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -294,7 +294,7 @@ class TestAddQuiz(TestCase): self.assertEqual(updated_quiz.course, self.course) self.assertEqual(response.status_code, 302) - self.assertRedirects(response, '/exam/manage/') + self.assertRedirects(response, '/exam/manage/courses/') def test_add_quiz_post_new_quiz(self): """ @@ -340,7 +340,7 @@ class TestAddQuiz(TestCase): self.assertEqual(new_quiz.course, self.course) self.assertEqual(response.status_code, 302) - self.assertRedirects(response, '/exam/manage/designquestionpaper/') + self.assertRedirects(response, '/exam/manage/courses/') class TestAddTeacher(TestCase): def setUp(self): -- cgit From 40c43990ce2b352b85711beef2763aa22763faa9 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 4 Oct 2016 18:34:00 +0530 Subject: Hide questions instead of deletion --- yaksh/forms.py | 2 +- yaksh/models.py | 7 ++++--- yaksh/templates/yaksh/add_question.html | 2 +- yaksh/views.py | 12 +++++------- 4 files changed, 11 insertions(+), 12 deletions(-) (limited to 'yaksh') diff --git a/yaksh/forms.py b/yaksh/forms.py index bc9b4c0..1931fad 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -177,7 +177,7 @@ class QuestionForm(forms.ModelForm): class Meta: model = Question - exclude = ['user'] + exclude = ['user', 'active'] class FileForm(forms.Form): diff --git a/yaksh/models.py b/yaksh/models.py index f098cd2..432f25e 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -271,7 +271,7 @@ class Question(models.Model): return json.dumps(question_data) def dump_questions(self, question_ids, user): - questions = Question.objects.filter(id__in=question_ids, user_id=user.id) + questions = Question.objects.filter(id__in=question_ids, user_id=user.id, active=True) questions_dict = [] zip_file_name = string_io() zip_file = zipfile.ZipFile(zip_file_name, "a") @@ -764,8 +764,9 @@ class AnswerPaperManager(models.Manager): attempt_number) questions = self.get_all_questions(questionpaper_id, attempt_number) all_questions = Question.objects.filter( - id__in=set(questions) - ).order_by('type') + id__in=set(questions), + active=True + ).order_by('type') for question in all_questions: if question.id in questions_answered: question_stats[question] = [questions_answered[question.id], diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html index f003256..5a5f1ce 100644 --- a/yaksh/templates/yaksh/add_question.html +++ b/yaksh/templates/yaksh/add_question.html @@ -20,7 +20,7 @@
    Summary: {{ form.summary }}{{ form.summary.errors }}
    Language: {{form.language}}{{form.language.errors}} -
    Active: {{ form.active }}{{form.active.errors}}   Type:  {{ form.type }}{{form.type.errors}} +
    Type: {{ form.type }}{{form.type.errors}}
    Points:{{form.points }}{{ form.points.errors }}
    Rendered:

    Description: {{ form.description}} {{form.description.errors}} diff --git a/yaksh/views.py b/yaksh/views.py index 049788a..d26c5df 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -915,12 +915,10 @@ def show_all_questions(request): if request.POST.get('delete') == 'delete': data = request.POST.getlist('question') if data is not None: - questions = Question.objects.filter(id__in=data, user_id=user.id) - files = FileUpload.objects.filter(question_id__in=questions) - if files: - for file in files: - file.remove() - questions.delete() + questions = Question.objects.filter(id__in=data, user_id=user.id, active=True) + for q in questions: + q.active = False + q.save() if request.POST.get('upload') == 'upload': form = UploadFileForm(request.POST, request.FILES) @@ -959,7 +957,7 @@ def show_all_questions(request): else: context["msg"] = "Please select atleast one question to test" - questions = Question.objects.filter(user_id=user.id) + questions = Question.objects.filter(user_id=user.id, active=True) form = QuestionFilterForm(user=user) upload_form = UploadFileForm() context['papers'] = [] -- cgit From 3d1d4a50524301d03526e4857844d0e6e4536527 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Fri, 7 Oct 2016 16:04:25 +0530 Subject: Minor fixes: Hide question instead of deletion --- yaksh/models.py | 5 ++-- yaksh/views.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 432f25e..60c4349 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -623,8 +623,7 @@ class QuestionPaper(models.Model): def _get_questions_for_answerpaper(self): """ Returns fixed and random questions for the answer paper""" - questions = [] - questions = list(self.fixed_questions.all()) + questions = list(self.fixed_questions.filter(active=True)) for question_set in self.random_questions.all(): questions += question_set.get_random_questions() return questions @@ -993,7 +992,7 @@ class AnswerPaper(models.Model): return q_a def get_questions(self): - return self.questions.all() + return self.questions.filter(active=True) def get_questions_answered(self): return self.questions_answered.all() diff --git a/yaksh/views.py b/yaksh/views.py index d26c5df..1b977f9 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1085,6 +1085,86 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): ) +<<<<<<< HEAD +======= +@csrf_exempt +def ajax_questionpaper(request, query): + """ + During question paper creation, ajax call made to get question details. + """ + + user = request.user + if query == 'marks': + question_type = request.POST.get('question_type') + questions = Question.objects.filter(type=question_type, user=user, active=True) + marks = questions.values_list('points').distinct() + return my_render_to_response('yaksh/ajax_marks.html', {'marks': marks}) + elif query == 'questions': + question_type = request.POST['question_type'] + marks_selected = request.POST['marks'] + fixed_questions = request.POST.getlist('fixed_list[]') + fixed_question_list = ",".join(fixed_questions).split(',') + random_questions = request.POST.getlist('random_list[]') + random_question_list = ",".join(random_questions).split(',') + question_list = fixed_question_list + random_question_list + questions = list(Question.objects.filter(type=question_type, + points=marks_selected, + user=user, + active=True) + ) + questions = [question for question in questions \ + if not str(question.id) in question_list] + return my_render_to_response('yaksh/ajax_questions.html', + {'questions': questions}) + + +@login_required +def design_questionpaper(request): + user = request.user + ci = RequestContext(request) + + if not is_moderator(user): + raise Http404('You are not allowed to view this page!') + + if request.method == 'POST': + fixed_questions = request.POST.getlist('fixed') + random_questions = request.POST.getlist('random') + random_number = request.POST.getlist('number') + is_shuffle = request.POST.get('shuffle_questions', False) + if is_shuffle == 'on': + is_shuffle = True + + question_paper = QuestionPaper(shuffle_questions=is_shuffle) + quiz = Quiz.objects.order_by("-id")[0] + tot_marks = 0 + question_paper.quiz = quiz + question_paper.total_marks = tot_marks + question_paper.save() + if fixed_questions: + fixed_questions_ids = ",".join(fixed_questions) + fixed_questions_ids_list = fixed_questions_ids.split(',') + for question_id in fixed_questions_ids_list: + question_paper.fixed_questions.add(question_id) + if random_questions: + for random_question, num in zip(random_questions, random_number): + qid = random_question.split(',')[0] + question = Question.objects.get(id=int(qid)) + marks = question.points + question_set = QuestionSet(marks=marks, num_questions=num) + question_set.save() + for question_id in random_question.split(','): + question_set.questions.add(question_id) + question_paper.random_questions.add(question_set) + question_paper.update_total_marks() + question_paper.save() + return my_redirect('/exam/manage/courses') + else: + form = RandomQuestionForm() + context = {'form': form, 'questionpaper':True} + return my_render_to_response('yaksh/design_questionpaper.html', + context, context_instance=ci) + +>>>>>>> Minor fixes: Hide question instead of deletion @login_required def view_profile(request): """ view moderators and users profile """ -- cgit From d33e97e4081037d92f89c7ae5742f74411b51931 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 13 Oct 2016 15:11:05 +0530 Subject: Fix variable name in for loop --- yaksh/views.py | 86 ++-------------------------------------------------------- 1 file changed, 3 insertions(+), 83 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 1b977f9..270a47c 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -916,9 +916,9 @@ def show_all_questions(request): data = request.POST.getlist('question') if data is not None: questions = Question.objects.filter(id__in=data, user_id=user.id, active=True) - for q in questions: - q.active = False - q.save() + for question in questions: + question.active = False + question.save() if request.POST.get('upload') == 'upload': form = UploadFileForm(request.POST, request.FILES) @@ -1085,86 +1085,6 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): ) -<<<<<<< HEAD -======= -@csrf_exempt -def ajax_questionpaper(request, query): - """ - During question paper creation, ajax call made to get question details. - """ - - user = request.user - if query == 'marks': - question_type = request.POST.get('question_type') - questions = Question.objects.filter(type=question_type, user=user, active=True) - marks = questions.values_list('points').distinct() - return my_render_to_response('yaksh/ajax_marks.html', {'marks': marks}) - elif query == 'questions': - question_type = request.POST['question_type'] - marks_selected = request.POST['marks'] - fixed_questions = request.POST.getlist('fixed_list[]') - fixed_question_list = ",".join(fixed_questions).split(',') - random_questions = request.POST.getlist('random_list[]') - random_question_list = ",".join(random_questions).split(',') - question_list = fixed_question_list + random_question_list - questions = list(Question.objects.filter(type=question_type, - points=marks_selected, - user=user, - active=True) - ) - questions = [question for question in questions \ - if not str(question.id) in question_list] - return my_render_to_response('yaksh/ajax_questions.html', - {'questions': questions}) - - -@login_required -def design_questionpaper(request): - user = request.user - ci = RequestContext(request) - - if not is_moderator(user): - raise Http404('You are not allowed to view this page!') - - if request.method == 'POST': - fixed_questions = request.POST.getlist('fixed') - random_questions = request.POST.getlist('random') - random_number = request.POST.getlist('number') - is_shuffle = request.POST.get('shuffle_questions', False) - if is_shuffle == 'on': - is_shuffle = True - - question_paper = QuestionPaper(shuffle_questions=is_shuffle) - quiz = Quiz.objects.order_by("-id")[0] - tot_marks = 0 - question_paper.quiz = quiz - question_paper.total_marks = tot_marks - question_paper.save() - if fixed_questions: - fixed_questions_ids = ",".join(fixed_questions) - fixed_questions_ids_list = fixed_questions_ids.split(',') - for question_id in fixed_questions_ids_list: - question_paper.fixed_questions.add(question_id) - if random_questions: - for random_question, num in zip(random_questions, random_number): - qid = random_question.split(',')[0] - question = Question.objects.get(id=int(qid)) - marks = question.points - question_set = QuestionSet(marks=marks, num_questions=num) - question_set.save() - for question_id in random_question.split(','): - question_set.questions.add(question_id) - question_paper.random_questions.add(question_set) - question_paper.update_total_marks() - question_paper.save() - return my_redirect('/exam/manage/courses') - else: - form = RandomQuestionForm() - context = {'form': form, 'questionpaper':True} - return my_render_to_response('yaksh/design_questionpaper.html', - context, context_instance=ci) - ->>>>>>> Minor fixes: Hide question instead of deletion @login_required def view_profile(request): """ view moderators and users profile """ -- cgit From 1bfd71cc024dc7ea72099deff52efbeac7db87b5 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 17 Oct 2016 12:43:13 +0530 Subject: extract uploaded questions zip in temp --- yaksh/bash_code_evaluator.py | 2 +- yaksh/file_utils.py | 27 ++++++++++++++++--------- yaksh/models.py | 47 +++++++++++++++++++++++++------------------- yaksh/views.py | 4 ++-- 4 files changed, 48 insertions(+), 32 deletions(-) (limited to 'yaksh') diff --git a/yaksh/bash_code_evaluator.py b/yaksh/bash_code_evaluator.py index e148fa8..e4b961c 100644 --- a/yaksh/bash_code_evaluator.py +++ b/yaksh/bash_code_evaluator.py @@ -22,10 +22,10 @@ class BashCodeEvaluator(CodeEvaluator): def teardown(self): # Delete the created file. - super(BashCodeEvaluator, self).teardown() os.remove(self.submit_code_path) if self.files: delete_files(self.files) + super(BashCodeEvaluator, self).teardown() def check_code(self, user_answer, file_paths, test_case): """ Function validates student script using instructor script as diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py index afcf9e8..ba3ead0 100644 --- a/yaksh/file_utils.py +++ b/yaksh/file_utils.py @@ -1,7 +1,8 @@ import shutil import os import zipfile - +import tempfile +from online_test.settings import OUTPUT_DIR def copy_files(file_paths): """ Copy Files to current directory, takes @@ -14,16 +15,19 @@ def copy_files(file_paths): files.append(file_name) shutil.copy(file_path, os.getcwd()) if extract: - z_files = extract_files(file_name) + z_files, path = extract_files(file_name, OUTPUT_DIR) for file in z_files: files.append(file) return files -def delete_files(files): - """ Delete Files from current directory """ - - for file in files: +def delete_files(files, file_path=None): + """ Delete Files from directory """ + for file_name in files: + if file_path: + file = os.path.join(file_path, file_name) + else: + file = file_name if os.path.exists(file): if os.path.isfile(file): os.remove(file) @@ -31,13 +35,18 @@ def delete_files(files): shutil.rmtree(file) -def extract_files(zip_file): +def extract_files(zip_file, path=None): + """ extract files from zip """ zfiles = [] if zipfile.is_zipfile(zip_file): zip_file = zipfile.ZipFile(zip_file, 'r') for z_file in zip_file.namelist(): zfiles.append(z_file) - zip_file.extractall() + if path: + extract_path = path + else: + extract_path = tempfile.gettempdir() + zip_file.extractall(extract_path) zip_file.close() - return zfiles + return zfiles, extract_path diff --git a/yaksh/models.py b/yaksh/models.py index f098cd2..95683c5 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -22,7 +22,7 @@ from os.path import join, abspath, dirname, exists import shutil import zipfile import tempfile -from .file_utils import extract_files +from .file_utils import extract_files, delete_files from yaksh.xmlrpc_clients import code_server from django.conf import settings @@ -174,7 +174,7 @@ class Course(models.Model): demo_ques = Question() demo_ques.create_demo_questions(user) demo_que_ppr = QuestionPaper() - demo_que_ppr.create_demo_quiz_ppr(demo_quiz) + demo_que_ppr.create_demo_quiz_ppr(demo_quiz, user) success = True else: success = False @@ -290,7 +290,7 @@ class Question(models.Model): question._add_json_to_zip(zip_file, questions_dict) return zip_file_name - def load_questions(self, questions_list, user): + def load_questions(self, questions_list, user, file_path=None, files_list=None): questions = json.loads(questions_list) for question in questions: question['user'] = user @@ -298,10 +298,12 @@ class Question(models.Model): test_cases = question.pop('testcase') que, result = Question.objects.get_or_create(**question) if file_names: - que._add_files_to_db(file_names) + que._add_files_to_db(file_names, file_path) model_class = get_model_class(que.test_case_type) for test_case in test_cases: model_class.objects.get_or_create(question=que, **test_case) + if files_list: + delete_files(files_list, file_path) def get_test_cases(self, **kwargs): test_case_ctype = ContentType.objects.get(app_label="yaksh", @@ -333,15 +335,18 @@ class Question(models.Model): files_list.append(((os.path.basename(f.file.path)), f.extract)) return files_list - def _add_files_to_db(self, file_names): + def _add_files_to_db(self, file_names, path): for file_name, extract in file_names: - que_file = open(file_name, 'r') - #Converting to Python file object with some Django-specific additions - django_file = File(que_file) - FileUpload.objects.get_or_create(file=django_file, - question=self, - extract=extract) - os.remove(file_name) + q_file = os.path.join(path, file_name) + if os.path.exists(q_file): + que_file = open(q_file, 'r') + #Converting to Python file object with + # some Django-specific additions + django_file = File(que_file) + file_upload = FileUpload() + file_upload.question = self + file_upload.extract = extract + file_upload.file.save(file_name, django_file, save=True) def _add_json_to_zip(self, zip_file, q_dict): json_data = json.dumps(q_dict, indent=2) @@ -353,18 +358,19 @@ class Question(models.Model): zip_file.close() shutil.rmtree(tmp_file_path) - def read_json(self, json_file, user): + def read_json(self, file_path, user, files=None): + json_file = os.path.join(file_path, "questions_dump.json") if os.path.exists(json_file): with open(json_file, 'r') as q_file: questions_list = q_file.read() - self.load_questions(questions_list, user) - os.remove(json_file) + print(questions_list) + self.load_questions(questions_list, user, file_path, files) def create_demo_questions(self, user): zip_file_path = os.path.join(os.getcwd(), 'yaksh', - 'fixtures', 'demo_questions.zip') - extract_files(zip_file_path) - self.read_json("questions_dump.json", user) + 'fixtures', 'demo_questions.zip') + files, extract_path = extract_files(zip_file_path) + self.read_json(extract_path, user, files) def __str__(self): @@ -674,13 +680,14 @@ class QuestionPaper(models.Model): prerequisite = self._get_prequisite_paper() return prerequisite._is_questionpaper_passed(user) - def create_demo_quiz_ppr(self, demo_quiz): + def create_demo_quiz_ppr(self, demo_quiz, user): question_paper = QuestionPaper.objects.create(quiz=demo_quiz, total_marks=5.0, shuffle_questions=True ) questions = Question.objects.filter(active=True, - summary="Yaksh Demo Question") + summary="Yaksh Demo Question", + user=user) # add fixed set of questions to the question paper for question in questions: question_paper.fixed_questions.add(question) diff --git a/yaksh/views.py b/yaksh/views.py index 049788a..611403d 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -929,8 +929,8 @@ def show_all_questions(request): file_name = questions_file.name.split('.') if file_name[-1] == "zip": ques = Question() - extract_files(questions_file) - ques.read_json("questions_dump.json", user) + files, extract_path = extract_files(questions_file) + ques.read_json(extract_path, user, files) else: message = "Please Upload a ZIP file" context['message'] = message -- cgit From 908797ed67fba67bbc40eae7bb8b85381b3e5141 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 17 Oct 2016 12:59:34 +0530 Subject: changes in evaluator and file utils --- yaksh/bash_stdio_evaluator.py | 2 +- yaksh/file_utils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'yaksh') diff --git a/yaksh/bash_stdio_evaluator.py b/yaksh/bash_stdio_evaluator.py index e5e0da6..a7ea1a4 100644 --- a/yaksh/bash_stdio_evaluator.py +++ b/yaksh/bash_stdio_evaluator.py @@ -17,10 +17,10 @@ class BashStdioEvaluator(StdIOEvaluator): self.submit_code_path = self.create_submit_code_file('Test.sh') def teardown(self): - super(BashStdioEvaluator, self).teardown() os.remove(self.submit_code_path) if self.files: delete_files(self.files) + super(BashStdioEvaluator, self).teardown() def compile_code(self, user_answer, file_paths, expected_input, expected_output): self.files = [] diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py index ba3ead0..f41c531 100644 --- a/yaksh/file_utils.py +++ b/yaksh/file_utils.py @@ -2,7 +2,7 @@ import shutil import os import zipfile import tempfile -from online_test.settings import OUTPUT_DIR + def copy_files(file_paths): """ Copy Files to current directory, takes @@ -15,7 +15,7 @@ def copy_files(file_paths): files.append(file_name) shutil.copy(file_path, os.getcwd()) if extract: - z_files, path = extract_files(file_name, OUTPUT_DIR) + z_files, path = extract_files(file_name, os.getcwd()) for file in z_files: files.append(file) return files -- cgit From 4371bacf65cf6f174d0827b77efb8eecebee78a4 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 17 Oct 2016 13:55:31 +0530 Subject: removed print statement --- yaksh/models.py | 1 - 1 file changed, 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 95683c5..82b9fff 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -363,7 +363,6 @@ class Question(models.Model): if os.path.exists(json_file): with open(json_file, 'r') as q_file: questions_list = q_file.read() - print(questions_list) self.load_questions(questions_list, user, file_path, files) def create_demo_questions(self, user): -- cgit From 8e06cee7b1fea13d121d2d0677b0a8e3ea7f2e38 Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 18 Oct 2016 12:00:10 +0530 Subject: changed comment spacing --- yaksh/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 82b9fff..c4a280a 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -340,7 +340,7 @@ class Question(models.Model): q_file = os.path.join(path, file_name) if os.path.exists(q_file): que_file = open(q_file, 'r') - #Converting to Python file object with + # Converting to Python file object with # some Django-specific additions django_file = File(que_file) file_upload = FileUpload() -- cgit From 3fcf7c6772bf6a3a91c4348a309e80ccc4592bba Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 25 Oct 2016 15:01:43 +0530 Subject: removed creation of user output directory --- yaksh/models.py | 8 +------- yaksh/output/README.txt | 4 ---- yaksh/views.py | 2 -- 3 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 yaksh/output/README.txt (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index cc64b98..7f9eead 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -206,12 +206,6 @@ class Profile(models.Model): """Return the output directory for the user.""" user_dir = join(settings.OUTPUT_DIR, str(self.user.username)) - if not exists(user_dir): - os.makedirs(user_dir) - # Make it rwx by others. - os.chmod(user_dir, stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH - | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR - | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP) return user_dir @@ -680,7 +674,7 @@ class QuestionPaper(models.Model): def create_demo_quiz_ppr(self, demo_quiz, user): question_paper = QuestionPaper.objects.create(quiz=demo_quiz, - total_marks=5.0, + total_marks=7.0, shuffle_questions=True ) questions = Question.objects.filter(active=True, diff --git a/yaksh/output/README.txt b/yaksh/output/README.txt deleted file mode 100644 index 3163ed4..0000000 --- a/yaksh/output/README.txt +++ /dev/null @@ -1,4 +0,0 @@ -This directory contains files generated/saved by users as per their -username. The test executor will chdir into this user directory for each -user when they run the test. Do not delete this directory and ensure that -it is writeable by all. \ No newline at end of file diff --git a/yaksh/views.py b/yaksh/views.py index 68e641e..4706222 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -415,8 +415,6 @@ def start(request, questionpaper_id=None, attempt_num=None): msg = 'You do not have a profile and cannot take the quiz!' raise Http404(msg) new_paper = quest_paper.make_answerpaper(user, ip, attempt_num) - # Make user directory. - user_dir = new_paper.user.profile.get_user_dir() return show_question(request, new_paper.current_question(), new_paper) -- cgit From 450954e5140b5c9a447127508e324841d311386a Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 25 Oct 2016 15:03:27 +0530 Subject: creation of user output directory from code evaluator --- yaksh/code_evaluator.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'yaksh') diff --git a/yaksh/code_evaluator.py b/yaksh/code_evaluator.py index 870a67f..e2097b0 100644 --- a/yaksh/code_evaluator.py +++ b/yaksh/code_evaluator.py @@ -94,6 +94,9 @@ class CodeEvaluator(object): # Private Protocol ########## def setup(self): + if self.in_dir: + if not os.path.exists(self.in_dir): + os.mkdir(self.in_dir) self._change_dir(self.in_dir) def safe_evaluate(self, user_answer, test_case_data, file_paths=None): -- cgit From a08fab86403b7aa2f813e5bafab08f7777ac3537 Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 25 Oct 2016 16:49:47 +0530 Subject: changed mkdir to makedirs --- yaksh/code_evaluator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/code_evaluator.py b/yaksh/code_evaluator.py index e2097b0..79f616d 100644 --- a/yaksh/code_evaluator.py +++ b/yaksh/code_evaluator.py @@ -96,7 +96,7 @@ class CodeEvaluator(object): def setup(self): if self.in_dir: if not os.path.exists(self.in_dir): - os.mkdir(self.in_dir) + os.makedirs(self.in_dir) self._change_dir(self.in_dir) def safe_evaluate(self, user_answer, test_case_data, file_paths=None): -- cgit