summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/db.cnf5
-rw-r--r--yaksh/forms.py4
-rw-r--r--yaksh/models.py16
-rw-r--r--yaksh/templates/exam.html8
-rw-r--r--yaksh/templates/yaksh/add_question.html1
-rw-r--r--yaksh/templates/yaksh/grade_user.html7
-rw-r--r--yaksh/templates/yaksh/question.html13
-rw-r--r--yaksh/templates/yaksh/user_data.html8
-rw-r--r--yaksh/templates/yaksh/view_answerpaper.html7
-rw-r--r--yaksh/views.py11
10 files changed, 75 insertions, 5 deletions
diff --git a/yaksh/db.cnf b/yaksh/db.cnf
new file mode 100644
index 0000000..22c68e3
--- /dev/null
+++ b/yaksh/db.cnf
@@ -0,0 +1,5 @@
+# new.cnf
+[client]
+database = online_test
+user = root
+default-character-set = utf8
diff --git a/yaksh/forms.py b/yaksh/forms.py
index 6ec031c..4bf4fcf 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -1,7 +1,7 @@
from django import forms
from yaksh.models import get_model_class, Profile, Quiz, Question, TestCase, Course,\
QuestionPaper, StandardTestCase, StdIOBasedTestCase, \
- HookTestCase
+ HookTestCase, IntegerTestCase
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
@@ -35,6 +35,7 @@ question_types = (
("mcc", "Multiple Correct Choices"),
("code", "Code"),
("upload", "Assignment Upload"),
+ ("integer", "Answer in Integer"),
)
test_case_types = (
@@ -42,6 +43,7 @@ test_case_types = (
("stdiobasedtestcase", "StdIO Based Testcase"),
("mcqtestcase", "MCQ Testcase"),
("hooktestcase", "Hook Testcase"),
+ ("integertestcase", "Integer Testcase"),
)
UNAME_CHARS = letters + "._" + digits
diff --git a/yaksh/models.py b/yaksh/models.py
index 4292cc0..81b8d7f 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -40,6 +40,7 @@ question_types = (
("mcc", "Multiple Correct Choices"),
("code", "Code"),
("upload", "Assignment Upload"),
+ ("integer", "Answer in Integer"),
)
enrollment_methods = (
@@ -52,6 +53,7 @@ test_case_types = (
("stdiobasedtestcase", "StdIO Based Testcase"),
("mcqtestcase", "MCQ Testcase"),
("hooktestcase", "Hook Testcase"),
+ ("integertestcase", "Integer Testcase"),
)
attempts = [(i, i) for i in range(1, 6)]
@@ -1133,6 +1135,11 @@ class AnswerPaper(models.Model):
if set(user_answer) == set(expected_answers):
result['success'] = True
result['error'] = ['Correct answer']
+ elif question.type == 'integer':
+ expected_answer = question.get_test_case().correct
+ if expected_answer == int(user_answer):
+ result['success'] = True
+ result['error'] = ['Correct answer']
elif question.type == 'code':
user_dir = self.user.profile.get_user_dir()
json_result = code_server.run_code(
@@ -1280,3 +1287,12 @@ class HookTestCase(TestCase):
def __str__(self):
return u'Hook Testcase | Correct: {0}'.format(self.hook_code)
+
+class IntegerTestCase(TestCase):
+ correct = models.IntegerField(default=False)
+
+ def get_field_value(self):
+ return {"test_case_type": "integertestcase", "correct": self.correct}
+
+ def __str__(self):
+ return u'Integer Testcase | Correct: {0}'.format(self.correct)
diff --git a/yaksh/templates/exam.html b/yaksh/templates/exam.html
index b497cc0..ae1a620 100644
--- a/yaksh/templates/exam.html
+++ b/yaksh/templates/exam.html
@@ -84,9 +84,13 @@
<div class="panel-body"><pre><code>{{ error }}</code></pre></div>
</div>
{% endfor %}
-
+ {% if error != "Incorrect answer" %}
+ <div class="panel-heading">Testcase No. {{ forloop.counter }}</div>
+ <div class="panel-body"><pre><code>{{ error }}</code></pre></div>
+ {% endif %}
</div>
- {% endif %}
+ {% endfor %}
+ </div>
{% endif %}
</div>
</div>
diff --git a/yaksh/templates/yaksh/add_question.html b/yaksh/templates/yaksh/add_question.html
index 75802b4..a1b5e90 100644
--- a/yaksh/templates/yaksh/add_question.html
+++ b/yaksh/templates/yaksh/add_question.html
@@ -56,6 +56,7 @@
<option value="stdiobasedtestcase">StdIO </option>
<option value="mcqtestcase">MCQ/MCC </option>
<option value="hooktestcase">Hook </option>
+ <option value="integertestcase">Integer </option>
</select></p>
<center>
<button class="btn" type="submit" name="save_question">Save</button>
diff --git a/yaksh/templates/yaksh/grade_user.html b/yaksh/templates/yaksh/grade_user.html
index 63ff5eb..7801b0b 100644
--- a/yaksh/templates/yaksh/grade_user.html
+++ b/yaksh/templates/yaksh/grade_user.html
@@ -139,6 +139,13 @@ Status : <b style="color: green;"> Passed </b><br/>
{{ forloop.counter }}. {{ testcase.options|safe }}</strong>
{% endif %}
{% endfor %}
+
+ {% elif question.type == "integer" %}
+ <h5> <u>Correct Answer:</u></h5>
+ {% for testcase in question.get_test_cases %}
+ <strong>{{ testcase.correct }}</strong>
+ {% endfor %}
+
{% else %}
<h5> <u>Test cases: </u></h5>
{% for testcase in question.get_test_cases %}
diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html
index 27b2956..35c8052 100644
--- a/yaksh/templates/yaksh/question.html
+++ b/yaksh/templates/yaksh/question.html
@@ -149,6 +149,8 @@ function call_skip(url)
(PROGRAMMING)
{% elif question.type == "upload" %}
(ASSIGNMENT UPLOAD)
+ {% elif question.type == "integer" %}
+ (ANSWER IN INTEGER)
{% endif %}
</u>
<font class=pull-right>(Marks : {{ question.points }}) </font>
@@ -167,6 +169,14 @@ function call_skip(url)
<input name="answer" type="radio" value="{{ test_case.options }}" />{{ test_case.options|safe }} <br/>
{% endfor %}
{% endif %}
+
+ {% if question.type == "integer" %}
+ Enter Integer:&nbsp;&nbsp;&nbsp;&nbsp;
+ <input name="answer" type="textbox" id="integer" />
+ <br/>
+ {% endif %}
+
+
{% if question.type == "mcc" %}
{% for test_case in test_cases %}
<input name="answer" type="checkbox" value="{{ test_case.options }}"> {{ test_case.options|safe }}
@@ -192,10 +202,11 @@ function call_skip(url)
{% endif %}
<div class="from-group">
- {% if question.type == "mcq" or question.type == "mcc"%}
+ {% if question.type == "mcq" or question.type == "mcc" or question.type == "integer" %}
<br><button class="btn btn-primary" type="submit" name="check" id="check">Submit Answer</button>&nbsp;&nbsp;
{% elif question.type == "upload" %}
<br><button class="btn btn-primary" type="submit" name="check" id="check" onClick="return validate();">Upload</button>&nbsp;&nbsp;
+
{% else %}
<button class="btn btn-primary" type="submit" name="check" id="check" onClick="submitCode();">Check Answer <span class="glyphicon glyphicon-cog"></span></button>&nbsp;&nbsp;
{% endif %}
diff --git a/yaksh/templates/yaksh/user_data.html b/yaksh/templates/yaksh/user_data.html
index 9be28fb..b667676 100644
--- a/yaksh/templates/yaksh/user_data.html
+++ b/yaksh/templates/yaksh/user_data.html
@@ -75,6 +75,14 @@ User IP address: {{ paper.user_ip }}
{{ forloop.counter }}. {{ testcase.options|safe }}</strong>
{% endif %}
{% endfor %}
+
+ {% elif question.type == "integer" %}
+ <h5> <u>Correct Answer:</u></h5>
+ {% for testcase in question.get_test_cases %}
+ <strong>{{ testcase.correct }}</strong>
+ {% endfor %}
+
+
{% else %}
<h5> <u>Test cases: </u></h5>
{% for testcase in question.get_test_cases %}
diff --git a/yaksh/templates/yaksh/view_answerpaper.html b/yaksh/templates/yaksh/view_answerpaper.html
index 5eb55df..76369db 100644
--- a/yaksh/templates/yaksh/view_answerpaper.html
+++ b/yaksh/templates/yaksh/view_answerpaper.html
@@ -51,6 +51,13 @@
{{ forloop.counter }}. {{ testcase.options|safe }}</strong>
{% endif %}
{% endfor %}
+
+ {% elif question.type == "integer" %}
+ <h5> <u>Correct Answer:</u></h5>
+ {% for testcase in question.get_test_cases %}
+ <strong>{{ testcase.correct }}</strong>
+ {% endfor %}
+
{% else %}
<h5> <u>Test cases: </u></h5>
{% for testcase in question.get_test_cases %}
diff --git a/yaksh/views.py b/yaksh/views.py
index 74c409c..996a3ce 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -25,7 +25,8 @@ import six
# Local imports.
from yaksh.models import get_model_class, Quiz, Question, QuestionPaper, QuestionSet, Course
from yaksh.models import Profile, Answer, AnswerPaper, User, TestCase, FileUpload,\
- has_profile, StandardTestCase, McqTestCase, StdIOBasedTestCase, HookTestCase
+ has_profile, StandardTestCase, McqTestCase,\
+ StdIOBasedTestCase, HookTestCase, IntegerTestCase
from yaksh.forms import UserRegisterForm, UserLoginForm, QuizForm,\
QuestionForm, RandomQuestionForm,\
QuestionFilterForm, CourseForm, ProfileForm, UploadFileForm,\
@@ -468,6 +469,14 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
# Add the answer submitted, regardless of it being correct or not.
if current_question.type == 'mcq':
user_answer = request.POST.get('answer')
+
+ elif current_question.type == 'integer':
+ try:
+ user_answer = int(request.POST.get('answer'))
+ except ValueError:
+ msg = ["Please enter an Integer Value"]
+ return show_question(request, current_question, paper, msg)
+
elif current_question.type == 'mcc':
user_answer = request.POST.getlist('answer')
elif current_question.type == 'upload':