Skip to content

Commit 58fde6e

Browse files
committed
bah
1 parent 8f23310 commit 58fde6e

3 files changed

Lines changed: 59 additions & 30 deletions

File tree

‎v3/js/matrixtutor.js‎

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3636
// - opt-frontend-common.js
3737
// should all be imported BEFORE this file
3838

39+
var problemName = null;
3940

4041
var appMode = 'edit'; // 'edit', 'display', or 'display_no_frills'
4142

@@ -59,6 +60,14 @@ var pyTestInputCodeMirror; // CodeMirror object that contains the test code
5960

6061

6162
$(document).ready(function() {
63+
problemName = window.location.search;
64+
if (!problemName) {
65+
alert("Error! Pass in a valid problem name in the url as '?<problem name>'");
66+
}
67+
else {
68+
problemName = problemName.slice(1); // strip off '?'
69+
}
70+
6271

6372
$("#embedLinkDiv,#gradingPane,#pyOutputPane").hide();
6473

@@ -117,7 +126,7 @@ $(document).ready(function() {
117126
enterEditMode();
118127
});
119128

120-
$('#gradeStdout,#gradeStderr').val(''); // clear 'em
129+
$('#gradeStdout').val(''); // clear 'em
121130
$('#submitGradeBtn').html('Submit for Grading');
122131
$('#submitGradeBtn').attr('disabled', false);
123132
}
@@ -262,30 +271,35 @@ $(document).ready(function() {
262271
}
263272
});
264273

265-
$.get('load_matrix_problem.py',
266-
{problem_name: 'python_comprehension-1'},
267-
function(dataFromBackend) {
268-
pyInputCodeMirror.setValue(dataFromBackend.code.rtrim());
269-
pyTestInputCodeMirror.setValue(dataFromBackend.test.rtrim());
270-
},
271-
"json");
272-
273-
274-
$('#submitGradeBtn').bind('click', function() {
275-
$('#submitGradeBtn').html('Now Grading ...');
276-
$('#submitGradeBtn').attr('disabled', true);
277-
278-
$.get('submit_matrix_problem.py',
279-
{submitted_code: pyInputCodeMirror.getValue(),
280-
problem_name: 'python_comprehension-1'},
274+
if (problemName) {
275+
$.get('load_matrix_problem.py',
276+
{problem_name: problemName},
281277
function(dataFromBackend) {
282-
$('#gradeStdout').val(dataFromBackend.user_stdout);
283-
$('#gradeStderr').val(dataFromBackend.user_stderr);
284-
285-
$('#submitGradeBtn').html('Submit for Grading');
286-
$('#submitGradeBtn').attr('disabled', false);
278+
if (dataFromBackend.status == 'error') {
279+
alert("Error: " + problemName + " is not a valid problem name");
280+
}
281+
else {
282+
pyInputCodeMirror.setValue(dataFromBackend.code.rtrim());
283+
pyTestInputCodeMirror.setValue(dataFromBackend.test.rtrim());
284+
$(".problemDescClass").html(dataFromBackend.description);
285+
}
287286
},
288287
"json");
289288

290-
});
289+
$('#submitGradeBtn').bind('click', function() {
290+
$('#submitGradeBtn').html('Now Grading ...');
291+
$('#submitGradeBtn').attr('disabled', true);
292+
293+
$.get('submit_matrix_problem.py',
294+
{submitted_code: pyInputCodeMirror.getValue(),
295+
problem_name: problemName},
296+
function(dataFromBackend) {
297+
$('#gradeStdout').val(dataFromBackend.user_stdout);
298+
299+
$('#submitGradeBtn').html('Submit for Grading');
300+
$('#submitGradeBtn').attr('disabled', false);
301+
},
302+
"json");
303+
});
304+
}
291305
});

‎v3/load_matrix_problem.py‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,24 @@
88
form = cgi.FieldStorage()
99
prob_name = form['problem_name'].value
1010
assert type(prob_name) is str # prevent subclassing shenanigans
11-
# whitelist
12-
assert prob_name in ('python_comprehension-1',)
1311

14-
fn = 'matrix-demo/' + prob_name + '.py'
15-
cod = open(fn).read()
12+
print("Content-type: text/plain; charset=iso-8859-1\n")
13+
14+
try:
15+
16+
for line in open('coding-the-matrix/python_lab.problem2name'):
17+
p, desc = line.strip().split('%')
18+
if p == prob_name:
19+
break
20+
21+
fn = 'coding-the-matrix/python-lab/' + prob_name + '.py'
22+
cod = open(fn).read()
23+
print(json.dumps(dict(code=cod, test='', description=desc)))
24+
except:
25+
print(json.dumps(dict(code='', test='', status='error')))
26+
1627

28+
'''
1729
p = doctest.DocTestParser()
1830
examples = p.get_examples(cod)
1931
if len(examples):
@@ -22,3 +34,4 @@
2234
2335
print("Content-type: text/plain; charset=iso-8859-1\n")
2436
print(json.dumps(dict(code=cod, test=testCod)))
37+
'''

‎v3/matrix.html‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
<div id="pyInputPane">
7171

72-
<h1 style="margin-bottom: 25px; font-size: 16pt;">List Comprehension Incrementer</h1>
72+
<h1 class="problemDescClass" style="margin-bottom: 25px; font-size: 16pt;"></h1>
7373

7474
Write your solution code here (will be submitted for grading):
7575
<br/>
@@ -92,21 +92,23 @@ <h1 style="margin-bottom: 25px; font-size: 16pt;">List Comprehension Incrementer
9292
<div id="gradingPane">
9393

9494

95-
<h1 style="margin-bottom: 15px; font-size: 14pt;">List Comprehension Incrementer</h1>
95+
<h1 class="problemDescClass" style="margin-bottom: 15px; font-size: 14pt;"></h1>
9696

9797
<p>
9898
<button id="submitGradeBtn" class="bigBtn" type="button">Submit for Grading</button>
9999
</p>
100100

101101
<p>
102102
Grader output:<br/>
103-
<textarea id="gradeStdout" cols="80" rows="8" wrap="off" readonly></textarea>
103+
<textarea style="font-size: 12pt" id="gradeStdout" cols="60" rows="6" wrap="off" readonly></textarea>
104104
</p>
105105

106+
<!--
106107
<p>
107108
Grader errors:<br/>
108109
<textarea id="gradeStderr" cols="80" rows="4" wrap="off" readonly></textarea>
109110
</p>
111+
-->
110112

111113
</div>
112114

0 commit comments

Comments
 (0)