summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/static/yaksh/js/question.js142
-rw-r--r--yaksh/templates/yaksh/question.html21
-rw-r--r--yaksh/templatetags/__init__.py0
-rw-r--r--yaksh/templatetags/custom_filters.py12
-rw-r--r--yaksh/views.py2
5 files changed, 16 insertions, 161 deletions
diff --git a/yaksh/static/yaksh/js/question.js b/yaksh/static/yaksh/js/question.js
index 2a8843c..96ff3de 100644
--- a/yaksh/static/yaksh/js/question.js
+++ b/yaksh/static/yaksh/js/question.js
@@ -10,145 +10,3 @@ function submitCode()
document.getElementById("skip").disabled = true;
}
}
-
-// function setSelectionRange(input, selectionStart, selectionEnd)
-// {
-// if (input.setSelectionRange)
-// {
-// input.focus();
-// input.setSelectionRange(selectionStart, selectionEnd);
-// }
-// else if (input.createTextRange)
-// {
-// var range = input.createTextRange();
-// range.collapse(true);
-// range.moveEnd('character', selectionEnd);
-// range.moveStart('character', selectionStart);
-// range.select();
-// }
-// }
-
-// function replaceSelection (input, replaceString)
-// {
-// if (input.setSelectionRange)
-// {
-// var selectionStart = input.selectionStart;
-// var selectionEnd = input.selectionEnd;
-// input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd);
-// if (selectionStart != selectionEnd)
-// {
-// setSelectionRange(input, selectionStart, selectionStart + replaceString.length);
-// }
-// else
-// {
-// setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length);
-// }
-// }
-// else if (document.selection)
-// {
-// var range = document.selection.createRange();
-// if (range.parentElement() == input)
-// {
-// var isCollapsed = range.text == '';
-// range.text = replaceString;
-// if (!isCollapsed)
-// {
-// range.moveStart('character', -replaceString.length);
-// range.select();
-// }
-// }
-// }
-// }
-
-// function autoresize()
-// {
-// var ta = document.getElementById('answer');
-// var divta = document.getElementById('AnswerWithLines');
-// ta.style.height="";
-// var height = ta.scrollHeight;
-// ta.style.height = 'auto';
-// ta.style.height = height+'px';
-// divta.style.height = height+'px';
-// }
-
-// function catchTab(item,e)
-// {
-// if(navigator.userAgent.match("Gecko"))
-// {
-// c=e.which;
-// }
-// else
-// {
-// c=e.keyCode;
-// }
-// if(c==9)
-// {
-// replaceSelection(item,String.fromCharCode(9));
-// setTimeout("document.getElementById('"+item.id+"').focus();",0);
-// return false;
-// }
-// }
-
-// var lineObjOffsetTop = 0;
-
-// function addLineNumbers(id)
-// {
-// var el = document.createElement('DIV');
-// var ta = document.getElementById(id);
-// var content = document.getElementById('snippet').value;
-// ta.parentNode.insertBefore(el,ta);
-// el.appendChild(ta);
-// el.style.width = (ta.offsetWidth + 30) + 'px';
-// ta.style.position = 'absolute';
-// ta.style.left = '30px';
-// ta.scrollHeight=""
-// el.style.border = 'none';
-// el.style.overflow='hidden';
-// el.style.position = 'relative';
-// el.style.width = (ta.offsetWidth + 30) + 'px';
-// var lineObj = document.createElement('DIV');
-// lineObj.style.position = 'absolute';
-// lineObj.style.top = lineObjOffsetTop + 'px';
-// lineObj.style.width = '27px';
-// lineObj.style.fontSize= '18px';
-// lineObj.style.foregroundColor='black';
-// el.insertBefore(lineObj,ta);
-// lineObj.style.textAlign = 'right';
-// lineObj.className='lineObj';
-// var string = '';
-// split_content = content.split('\n');
-// if(id == "answer")
-// {
-// el.className='AnswerWithLines';
-// el.id='AnswerWithLines';
-// el.style.height = (ta.scrollHeight) + 'px';
-// for(var no=split_content.length+1;no<1000;no++)
-// {
-// if(string.length>0)string = string + '<br>';
-// string = string + no;
-// }
-// }
-// else
-// {
-// el.className='SnippetWithLines';
-// el.id='SnippetWithLines';
-// el.style.height = (ta.scrollHeight) + 'px';
-// for(var no=1;no<=split_content.length;no++)
-// {
-// if(string.length>0)string = string + '<br>';
-// string = string + no;
-// }
-// }
-// ta.onmousedown = function() { positionLineObj(lineObj,ta); };
-// ta.onscroll = function() { positionLineObj(lineObj,ta); };
-// ta.onblur = function() { positionLineObj(lineObj,ta); };
-// ta.onfocus = function() { positionLineObj(lineObj,ta); };
-// ta.onmouseover = function() { positionLineObj(lineObj,ta); };
-// ta.onkeyup = function(){autoresize();};
-// lineObj.innerHTML = string;
-// }
-
-// function positionLineObj(obj,ta)
-// {
-// obj.style.top = (ta.scrollTop * -1 + lineObjOffsetTop) + 'px';
-// }
diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html
index 110c422..b8be99f 100644
--- a/yaksh/templates/yaksh/question.html
+++ b/yaksh/templates/yaksh/question.html
@@ -1,4 +1,5 @@
{% extends "base.html" %}
+{% load custom_filters %}
<!DOCTYPE html>
@@ -66,15 +67,6 @@ updateClock();
var timeinterval = setInterval(updateClock,1000);
}
-// function setSnippetHeight()
-// {
-// var ta = document.getElementById('snippet');
-// var height = ta.scrollHeight+'px';
-// ta.style.height = 'auto';
-// ta.style.height = height;
-// autoresize();
-// }
-
function validate(){
uploaded_file = document.getElementById("assignment").value;
if(uploaded_file == ""){
@@ -186,15 +178,9 @@ function call_skip(url)
{% if question.type == "code" %}
<h4>Program:</h4>
-<!-- <textarea rows="1" class="bash" readonly="yes" name="snippet" id="snippet" wrap="off" >{% if last_attempt %}{{ question.snippet }}{% else %}{% if question.type == "bash" %} #!/bin/bash&#13;&#10;{{ question.snippet }}{% else %}{{ question.snippet }}{% endif %}{% endif %}</textarea> -->
-<!-- <textarea rows="10" class="bash" name="answer" id="answer" wrap="off" onkeydown="return catchTab(this,event)">{% if last_attempt %}{{last_attempt}}{% else %}{% if question.type == "bash" %}{% else %}{% endif %}{% endif %}</textarea> -->
<textarea name="answer" id="answer"></textarea>
<br>
-<!-- <script type="text/javascript">
- addLineNumbers('answer');
- </script>
- <script>addLineNumbers('snippet');</script> -->
{% endif %}
{% if question.type == "mcq" or question.type == "mcc "%}
@@ -234,7 +220,6 @@ function call_skip(url)
<script>
// Codemirror object, language modes and initial content
-
// Get the textarea node
var textarea_node = document.querySelector('#answer');
@@ -253,10 +238,10 @@ function call_skip(url)
var editor = CodeMirror.fromTextArea(textarea_node, options);
// Setting code editors initial content
- editor.setValue('{{last_attempt|safe}}') //.replace(/\"|\'/g, "\'") // .replace(/^\"|\"$/g, "")
+ editor.setValue('{{ last_attempt|escape_quotes|safe }}')
function reset_editor() {
- // editor.setValue('{{ last_attempt|safe }}');
+ editor.setValue('{{ last_attempt|escape_quotes|safe }}');
editor.clearHistory();
}
diff --git a/yaksh/templatetags/__init__.py b/yaksh/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/yaksh/templatetags/__init__.py
diff --git a/yaksh/templatetags/custom_filters.py b/yaksh/templatetags/custom_filters.py
new file mode 100644
index 0000000..5baa977
--- /dev/null
+++ b/yaksh/templatetags/custom_filters.py
@@ -0,0 +1,12 @@
+from django import template
+from django.template.defaultfilters import stringfilter
+
+register = template.Library()
+
+@stringfilter
+@register.filter(name='escape_quotes')
+def escape_quotes(value):
+ escape_single_quotes = value.replace("'", "\\'")
+ escape_single_and_double_quotes = escape_single_quotes.replace('"', '\\"')
+
+ return escape_single_and_double_quotes \ No newline at end of file
diff --git a/yaksh/views.py b/yaksh/views.py
index 32b4545..d9d2d61 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -392,7 +392,7 @@ def show_question(request, question, paper, error_message=None):
answers = paper.get_previous_answers(question)
if answers:
- last_attempt = "{}\n{}".format(question.snippet, answers[0].answer)
+ last_attempt = answers[0].answer
context['last_attempt'] = last_attempt.encode('unicode-escape')
# context['last_attempt'] = answers[0].answer.encode('unicode-escape')
ci = RequestContext(request)