diff options
Diffstat (limited to 'testapp/exam')
-rw-r--r-- | testapp/exam/forms.py | 23 | ||||
-rw-r--r-- | testapp/exam/models.py | 12 | ||||
-rw-r--r-- | testapp/exam/static/exam/js/add_question.js | 15 | ||||
-rw-r--r-- | testapp/exam/templates/exam/add_question.html | 9 | ||||
-rw-r--r-- | testapp/exam/templates/exam/edit_question.html | 24 | ||||
-rw-r--r-- | testapp/exam/views.py | 14 |
6 files changed, 45 insertions, 52 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py index e3cef40..93584a6 100644 --- a/testapp/exam/forms.py +++ b/testapp/exam/forms.py @@ -187,8 +187,8 @@ class QuestionForm(forms.ModelForm): description = forms.CharField(widget=forms.Textarea\ (attrs={'cols': 40, 'rows': 1})) points = forms.FloatField() - # test = forms.CharField(widget=forms.Textarea\ - # (attrs={'cols': 40, 'rows': 1}), required=False) + solution = forms.CharField(widget=forms.Textarea\ + (attrs={'cols': 40, 'rows': 1}), required=False) options = forms.CharField(widget=forms.Textarea\ (attrs={'cols': 40, 'rows': 1}), required=False) language = forms.CharField(max_length=20, widget=forms.Select\ @@ -199,17 +199,18 @@ class QuestionForm(forms.ModelForm): tags = TagField(widget=TagAutocomplete(), required=False) snippet = forms.CharField(widget=forms.Textarea\ (attrs={'cols': 40, 'rows': 1}), required=False) + ref_code_path = forms.CharField(widget=forms.Textarea\ + (attrs={'cols': 40, 'rows': 1}), required=False) def save(self, commit=True): - summary = self.cleaned_data["summary"] - description = self.cleaned_data["description"] - points = self.cleaned_data['points'] - # test = self.cleaned_data["test"] - options = self.cleaned_data['options'] - language = self.cleaned_data['language'] - type = self.cleaned_data["type"] - active = self.cleaned_data["active"] - snippet = self.cleaned_data["snippet"] + summary = self.cleaned_data.get("summary") + description = self.cleaned_data.get("description") + points = self.cleaned_data.get("points") + options = self.cleaned_data.get("options") + language = self.cleaned_data.get("language") + type = self.cleaned_data.get("type") + active = self.cleaned_data.get("active") + snippet = self.cleaned_data.get("snippet") new_question = Question() new_question.summary = summary diff --git a/testapp/exam/models.py b/testapp/exam/models.py index dd0c806..5989be4 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -60,8 +60,11 @@ class Question(models.Model): # Number of points for the question. points = models.FloatField(default=1.0) - # # Test cases for the question in the form of code that is run. - # test = models.TextField(blank=True) + # Answer for MCQs. + solution = models.TextField(blank=True) + + # Test cases file paths + ref_code_path = models.TextField(blank=True) # Any multiple choice options. Place one option per line. options = models.TextField(blank=True) @@ -114,6 +117,7 @@ class Question(models.Model): info_parameter['id'] = self.id info_parameter['user_answer'] = user_answer info_parameter['test_parameter'] = test_case_parameter + info_parameter['ref_code_path'] = self.ref_code_path return json.dumps(info_parameter) @@ -449,5 +453,5 @@ class TestCase(models.Model): # Test case Expected answer in list form expected_answer = models.TextField(blank=True, null = True) - # Test case path to system test code applicable for CPP, C, Java and Scilab - ref_code_path = models.TextField(blank=True, null = True) + # # Test case path to system test code applicable for CPP, C, Java and Scilab + # ref_code_path = models.TextField(blank=True, null = True) diff --git a/testapp/exam/static/exam/js/add_question.js b/testapp/exam/static/exam/js/add_question.js index 267cdb2..5a94f4c 100644 --- a/testapp/exam/static/exam/js/add_question.js +++ b/testapp/exam/static/exam/js/add_question.js @@ -153,13 +153,17 @@ function textareaformat() if(value == 'mcq' || value == 'mcc') { document.getElementById('id_options').style.visibility='visible'; - document.getElementById('label_option').innerHTML="Options :" + document.getElementById('label_option').innerHTML="Options :"; + document.getElementById('id_solution').style.visibility='visible'; + document.getElementById('label_solution').innerHTML="Solutions :"; } else { document.getElementById('id_options').style.visibility='hidden'; document.getElementById('label_option').innerHTML = ""; + document.getElementById('id_solution').style.visibility='hidden'; + document.getElementById('label_solution').innerHTML="" } }); document.getElementById('my').innerHTML = document.getElementById('id_description').value ; @@ -168,12 +172,16 @@ function textareaformat() { document.getElementById('id_options').style.visibility='visible'; document.getElementById('label_option').innerHTML="Options :" + document.getElementById('id_solution').style.visibility='visible'; + document.getElementById('label_solution').innerHTML="Solutions :"; } else { document.getElementById('id_options').style.visibility='hidden'; document.getElementById('label_option').innerHTML = ""; + document.getElementById('id_solution').style.visibility='hidden'; + document.getElementById('label_solution').innerHTML="" } } @@ -189,8 +197,9 @@ function autosubmit() if(type.value == 'select') { type.style.border = 'solid red'; - return false; - } + return false; + } + if (type.value == 'mcq' || type.value == 'mcc') { diff --git a/testapp/exam/templates/exam/add_question.html b/testapp/exam/templates/exam/add_question.html index e5e2574..e117ef3 100644 --- a/testapp/exam/templates/exam/add_question.html +++ b/testapp/exam/templates/exam/add_question.html @@ -27,11 +27,12 @@ <tr><td>Points:<td><button class="btn-mini" type="button" onClick="increase(frm);">+</button>{{ form.points }}<button class="btn-mini" type="button" onClick="decrease(frm);">-</button>{{ form.points.errors }} <tr><td><strong>Rendered: </strong><td><p id='my'></p> <tr><td>Description: <td>{{ form.description}} {{form.description.errors}} - <!-- <tr><td>Test: <td>{{ form.test }}{{form.test.errors}} --> <tr><td>Snippet: <td>{{ form.snippet }}{{ form.snippet.errors }}</td></tD></td></tr> <tr><td>Tags: <td>{{ form.tags }} <tr><td id='label_option'>Options: <td>{{ form.options }} {{form.options.errors}} - <!-- start --> + <tr><td id='label_solution'>Solution: <td>{{ form.solution }} {{form.solution.errors}} + <tr><td id='label_ref_code_path'>Reference Code Path: <td>{{ form.ref_code_path }} {{form.ref_code_path.errors}} + <form method="post" action=""> {% if formset%} {{ formset.management_form }} @@ -41,8 +42,8 @@ {% endif %} </form> </table></center> - <center><button class="btn" type="submit" name="add_test">Add Test Case</button> <!-- --> - <button class="btn" type="submit" name="delete_test">Remove Test Case</button> <!-- --> + <center><button class="btn" type="submit" name="add_test">Add Test Case</button> + <button class="btn" type="submit" name="delete_test">Remove Test Case</button> </center><br> <center><button class="btn" type="submit" name="save_question">Save</button> <button class="btn" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/questions/");'>Cancel</button> </center> diff --git a/testapp/exam/templates/exam/edit_question.html b/testapp/exam/templates/exam/edit_question.html index 1c34dee..6deca4a 100644 --- a/testapp/exam/templates/exam/edit_question.html +++ b/testapp/exam/templates/exam/edit_question.html @@ -21,30 +21,6 @@ <table> -<!-- {% for form in forms %} - - <tr><td height=10><a id='a{{forloop.counter}}' onClick="data('contentDiv{{forloop.counter}}','myContent{{forloop.counter}}','a{{forloop.counter}}','{{form.summary.value}}');" style='cursor:pointer;'>{{form.summary.value}}</a> - - <div id="contentDiv{{forloop.counter}}" style="display:none;"> - <div id="myContent{{forloop.counter}}" style="display: none;"> - - <center><table class=span1> - <tr><td><b>Summary:</b> <td>{{ form.summary }}{{ form.summary.errors }} - <tr><td><b> Language: </b><td> {{form.language}}{{form.language.errors}} - <tr><td><b> Active: </b><td> {{ form.active }}{{form.active.errors}} Type: {{ form.type }}{{form.type.errors}} - <tr><td><b>Points:<td><button class="btn-mini" name={{forloop.counter}} type="button" onClick="increase(frm,{{forloop.counter}});">+</button>{{ form.points }}<button class="btn-mini" type="button" onClick="decrease(frm,{{forloop.counter}});">-</button>{{ form.points.errors }} - <tr><td><strong>Rendered: </strong><td><p id='my{{forloop.counter}}'></p> - <tr><td><b>Description: <td>{{ form.description }} {{form.description.errors}} - <tr><td><b>Test: <td>{{ form.test }}{{form.test.errors}} - <tr><td><b>Snippet: <td>{{ form.snippet }}{{ form.snippet.errors }}</td></b></td></tr> - <tr><td><b>Tags: </b><td>{{ form.tags }} - <tr><td id='label_option{{forloop.counter}}'><b>Options:<td>{{ form.options }} {{form.options.errors}} {{form.options.helptext}} - </table></center> - </div> - </div> - {% endfor %} -</table></center> --> - {% for question, test in data_list %} <tr><td height=10><a id='a{{forloop.counter}}' onClick="data('contentDiv{{forloop.counter}}','myContent{{forloop.counter}}','a{{forloop.counter}}','{{question.summary.value}}');" style='cursor:pointer;'>{{question.summary.value}}</a> diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 8aef5ab..840f30a 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -323,7 +323,7 @@ def add_question(request, question_id=None): def add_or_delete_test_form(post_request, instance): request_copy = post_request.copy() if 'add_test' in post_request: - request_copy['test-TOTAL_FORMS'] = int(request_copy['test-TOTAL_FORMS']) + 1 + request_copy['test-TOTAL_FORMS'] = int(request_copy['test-TOTAL_FORMS']) + 1 elif 'delete_test' in post_request: request_copy['test-TOTAL_FORMS'] = int(request_copy['test-TOTAL_FORMS']) - 1 test_case_formset = TestCaseFormSet(request_copy, prefix='test', instance=instance) @@ -402,8 +402,10 @@ def add_question(request, question_id=None): context_instance=ci) else: + test_case_formset = add_or_delete_test_form(request.POST, form.save(commit=False)) return my_render_to_response('exam/add_question.html', - {'form': form}, + {'form': form, + 'formset': test_case_formset}, context_instance=ci) else: form = QuestionForm() @@ -951,8 +953,8 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): # questions, we obtain the results via XML-RPC with the code executed # safely in a separate process (the code_server.py) running as nobody. if not question.type == 'upload': - if question.type == 'code': - info_parameter = question.consolidate_answer_data(test, user_answer) + info_parameter = question.consolidate_answer_data(test, user_answer) \ + if question.type == 'code' else None correct, result = validate_answer(user, user_answer, question, info_parameter) if correct: new_answer.correct = correct @@ -1013,11 +1015,11 @@ def validate_answer(user, user_answer, question, info_parameter=None): if user_answer is not None: if question.type == 'mcq': - if user_answer.strip() == question.test.strip(): ####add question.answer/question.solution instead of test + if user_answer.strip() == question.solution.strip(): correct = True message = 'Correct answer' elif question.type == 'mcc': - answers = set(question.test.splitlines()) ####add question.answer/question.solution instead of test + answers = set(question.solution.splitlines()) if set(user_answer) == answers: correct = True message = 'Correct answer' |