testappproj/templates/code.html
author amit@thunder
Mon, 14 Jun 2010 01:00:59 +0530
changeset 3 34d0c21e3352
parent 1 0eda880b3d25
permissions -rw-r--r--
Checking if exam has been previously done by the user or not

{# {%extends "base.html"%} #}
<script type="text/javascript">
function run_code(params){

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
   
   xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
 document.getElementById("code_form").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("POST","/run/",true);
xmlhttp.send(params);
}
function process_form(element) {
      
      var poststr = "user_code=" + encodeURI( document.getElementById("code-area").value ) +
                    "&problem_id=" + encodeURI( document.getElementById("problem_id").value );
      run_code(poststr);
   }

</script>
{%block body%}
<h2>{{ problem.name }}</h2>

{% comment %}
{% load pykata_extras %}
{% autoescape off %}
<p>
{{problem.description|force_escape|spacify_code|linebreaksbr}}
</p>
{% endautoescape %}
{% endcomment %}

<pre>
{{ problem.examples }}
</pre>
  <div id="code_form">
    <form method="post" action="javascript:process_form(document.getElementById('code_form'));">
    <p><strong>Enter your solution here:</strong></p>
    <p><textarea id="code-area" name="user_code" rows="22" cols="80">
{% ifequal pu.classname "ProblemUser" %}{{ pu.solution }}{% else %}{{ problem.skeleton }}{% endifequal %}
    </textarea></p>
    <input id="problem_id" type="hidden" name="problem_id" value="{{ problem.id }}" />
    <p><input type="submit" name="submit" value="Done" ></p>
  </form>
</div>
  <script language="javascript" type="text/javascript" src="/static/edit_area_full.js"></script>
  <script language="javascript" type="text/javascript">
    editAreaLoader.init({
      id: "code-area",
      syntax: "python",
      start_highlight: true,
      allow_resize: "both",
      cursor_position: "begin",
      font_size: 14,
      toolbar: "new_document, select_font, |, help",
      replace_tab_by_spaces: 4
    });
  </script>
  {%endblock%}