Description:
fixed new submission error showing nil compiler message
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r772:72eb3ebb9aef - - 1 file changed: 3 inserted, 1 deleted
@@ -1,309 +1,311 | |||
|
1 | 1 | %h2 Live submit |
|
2 | 2 | %br |
|
3 | 3 | |
|
4 | 4 | %textarea#text_sourcecode{style: "display:none"}~ @source |
|
5 | 5 | .container |
|
6 | 6 | .row |
|
7 | 7 | .col-md-12 |
|
8 | 8 | .alert.alert-info |
|
9 | 9 | Write your code in the following box, choose language, and click submit button when finished |
|
10 | 10 | .row |
|
11 | 11 | .col-md-8 |
|
12 | 12 | %div#editor{style: 'height: 500px; border-radius: 7px; font-size: 14px;'} |
|
13 | 13 | .col-md-4 |
|
14 | 14 | - # submission form |
|
15 | 15 | = form_tag({controller: :main, :action => 'submit'}, :multipart => true, class: 'form') do |
|
16 | 16 | |
|
17 | 17 | = hidden_field_tag 'editor_text', @source |
|
18 | 18 | = hidden_field_tag 'submission[problem_id]', @problem.id |
|
19 | 19 | .form-group |
|
20 | 20 | = label_tag "Task:" |
|
21 | 21 | = text_field_tag 'asdf', "#{@problem.long_name}", class: 'form-control', disabled: true |
|
22 | 22 | .form-group |
|
23 | 23 | = label_tag "Description:" |
|
24 | 24 | = link_to_description_if_any "[download] <span class='glyphicon glyphicon-file'></span>".html_safe, @problem |
|
25 | 25 | |
|
26 | 26 | .form-group |
|
27 | 27 | = label_tag 'Language:' |
|
28 | 28 | = select_tag 'language_id', options_from_collection_for_select(Language.all, 'id', 'pretty_name', @lang_id || Language.find_by_pretty_name("Python").id || Language.first.id), class: 'form-control select', style: "width: 100px" |
|
29 | 29 | .form-group |
|
30 | 30 | .input-group |
|
31 | 31 | %span.input-group-btn |
|
32 | 32 | %span.btn.btn-default.btn-file |
|
33 | 33 | Browse |
|
34 | 34 | = file_field_tag 'load_file' |
|
35 | 35 | = text_field_tag '' , nil, {readonly: true, class: 'form-control'} |
|
36 | 36 | .form-group |
|
37 | 37 | = submit_tag 'Submit', class: 'btn btn-success', id: 'live_submit', |
|
38 | 38 | data: {confirm: "Submitting this source code for task #{@problem.long_name}?"} |
|
39 | 39 | - # latest submission status |
|
40 | 40 | .panel{class: (@submission && @submission.graded_at) ? "panel-info" : "panel-warning"} |
|
41 | 41 | .panel-heading |
|
42 | 42 | Latest Submission Status |
|
43 | 43 | = link_to "Refresh",get_latest_submission_status_submissions_path(@submission.user,@problem), class: "btn btn-default btn-sm", remote: true if @submission |
|
44 | 44 | .panel-body |
|
45 | 45 | %div#latest_status |
|
46 | 46 | - if @submission |
|
47 | 47 | = render :partial => 'submission_short', |
|
48 | 48 | :locals => {submission: @submission, problem_name: @problem.name, problem_id: @problem.id } |
|
49 | 49 | .row |
|
50 | 50 | .col-md-12 |
|
51 | 51 | %h2 Console |
|
52 | 52 | %textarea#console{style: 'height: 100%; width: 100%;background-color:#000;color:#fff;font-family: consolas, monaco, "Droid Sans Mono";',rows: 20} |
|
53 | 53 | |
|
54 | 54 | .modal.fade#compiler{tabindex: -1,role: 'dialog'} |
|
55 | 55 | .modal-dialog.modal-lg{role:'document'} |
|
56 | 56 | .modal-content |
|
57 | 57 | .modal-header |
|
58 | 58 | %button.close{type: 'button', data: {dismissed: :modal}, aria: {label: 'close'}} |
|
59 | 59 | %span{aria: {hidden: 'true'}, data: {dismiss: 'modal'}} × |
|
60 | 60 | %h4 Compiler message |
|
61 | 61 | .modal-body |
|
62 | - %pre#compiler_msg= @submission.compiler_message | |
|
62 | + %pre#compiler_msg | |
|
63 | + - if @submission | |
|
64 | + = @submission.compiler_message | |
|
63 | 65 | .modal-footer |
|
64 | 66 | %button.btn.btn-default{type: 'button', data: {dismiss: 'modal'}} Close |
|
65 | 67 | |
|
66 | 68 | :javascript |
|
67 | 69 | $(document).ready(function() { |
|
68 | 70 | e = ace.edit("editor") |
|
69 | 71 | e.setValue($("#text_sourcecode").val()); |
|
70 | 72 | e.gotoLine(1); |
|
71 | 73 | $("#language_id").trigger('change'); |
|
72 | 74 | |
|
73 | 75 | $("#load_file").on('change',function(evt) { |
|
74 | 76 | var file = evt.target.files[0]; |
|
75 | 77 | var reader = new FileReader(); |
|
76 | 78 | reader.onload = function(theFile) { |
|
77 | 79 | var e = ace.edit("editor") |
|
78 | 80 | e.setValue(theFile.target.result); |
|
79 | 81 | e.gotoLine(1); |
|
80 | 82 | }; |
|
81 | 83 | reader.readAsText(file) |
|
82 | 84 | }); |
|
83 | 85 | |
|
84 | 86 | //brython(); |
|
85 | 87 | }); |
|
86 | 88 | |
|
87 | 89 | |
|
88 | 90 | |
|
89 | 91 | |
|
90 | 92 | |
|
91 | 93 | %script#__main__{type:'text/python3'} |
|
92 | 94 | :plain |
|
93 | 95 | import sys |
|
94 | 96 | import traceback |
|
95 | 97 | |
|
96 | 98 | from browser import document as doc |
|
97 | 99 | from browser import window, alert, console |
|
98 | 100 | |
|
99 | 101 | _credits = """ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands |
|
100 | 102 | for supporting Python development. See www.python.org for more information.""" |
|
101 | 103 | |
|
102 | 104 | _copyright = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com |
|
103 | 105 | All Rights Reserved. |
|
104 | 106 | |
|
105 | 107 | Copyright (c) 2001-2013 Python Software Foundation. |
|
106 | 108 | All Rights Reserved. |
|
107 | 109 | |
|
108 | 110 | Copyright (c) 2000 BeOpen.com. |
|
109 | 111 | All Rights Reserved. |
|
110 | 112 | |
|
111 | 113 | Copyright (c) 1995-2001 Corporation for National Research Initiatives. |
|
112 | 114 | All Rights Reserved. |
|
113 | 115 | |
|
114 | 116 | Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. |
|
115 | 117 | All Rights Reserved.""" |
|
116 | 118 | |
|
117 | 119 | _license = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com |
|
118 | 120 | All rights reserved. |
|
119 | 121 | |
|
120 | 122 | Redistribution and use in source and binary forms, with or without |
|
121 | 123 | modification, are permitted provided that the following conditions are met: |
|
122 | 124 | |
|
123 | 125 | Redistributions of source code must retain the above copyright notice, this |
|
124 | 126 | list of conditions and the following disclaimer. Redistributions in binary |
|
125 | 127 | form must reproduce the above copyright notice, this list of conditions and |
|
126 | 128 | the following disclaimer in the documentation and/or other materials provided |
|
127 | 129 | with the distribution. |
|
128 | 130 | Neither the name of the <ORGANIZATION> nor the names of its contributors may |
|
129 | 131 | be used to endorse or promote products derived from this software without |
|
130 | 132 | specific prior written permission. |
|
131 | 133 | |
|
132 | 134 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
133 | 135 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
134 | 136 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
135 | 137 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
136 | 138 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
137 | 139 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
138 | 140 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
139 | 141 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
140 | 142 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
141 | 143 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
142 | 144 | POSSIBILITY OF SUCH DAMAGE. |
|
143 | 145 | """ |
|
144 | 146 | |
|
145 | 147 | def credits(): |
|
146 | 148 | print(_credits) |
|
147 | 149 | credits.__repr__ = lambda:_credits |
|
148 | 150 | |
|
149 | 151 | def copyright(): |
|
150 | 152 | print(_copyright) |
|
151 | 153 | copyright.__repr__ = lambda:_copyright |
|
152 | 154 | |
|
153 | 155 | def license(): |
|
154 | 156 | print(_license) |
|
155 | 157 | license.__repr__ = lambda:_license |
|
156 | 158 | |
|
157 | 159 | def write(data): |
|
158 | 160 | doc['console'].value += str(data) |
|
159 | 161 | |
|
160 | 162 | |
|
161 | 163 | sys.stdout.write = sys.stderr.write = write |
|
162 | 164 | history = [] |
|
163 | 165 | current = 0 |
|
164 | 166 | _status = "main" # or "block" if typing inside a block |
|
165 | 167 | |
|
166 | 168 | # execution namespace |
|
167 | 169 | editor_ns = {'credits':credits, |
|
168 | 170 | 'copyright':copyright, |
|
169 | 171 | 'license':license, |
|
170 | 172 | '__name__':'__main__'} |
|
171 | 173 | |
|
172 | 174 | def cursorToEnd(*args): |
|
173 | 175 | pos = len(doc['console'].value) |
|
174 | 176 | doc['console'].setSelectionRange(pos, pos) |
|
175 | 177 | doc['console'].scrollTop = doc['console'].scrollHeight |
|
176 | 178 | |
|
177 | 179 | def get_col(area): |
|
178 | 180 | # returns the column num of cursor |
|
179 | 181 | sel = doc['console'].selectionStart |
|
180 | 182 | lines = doc['console'].value.split('\n') |
|
181 | 183 | for line in lines[:-1]: |
|
182 | 184 | sel -= len(line) + 1 |
|
183 | 185 | return sel |
|
184 | 186 | |
|
185 | 187 | |
|
186 | 188 | def myKeyPress(event): |
|
187 | 189 | global _status, current |
|
188 | 190 | if event.keyCode == 9: # tab key |
|
189 | 191 | event.preventDefault() |
|
190 | 192 | doc['console'].value += " " |
|
191 | 193 | elif event.keyCode == 13: # return |
|
192 | 194 | src = doc['console'].value |
|
193 | 195 | if _status == "main": |
|
194 | 196 | currentLine = src[src.rfind('>>>') + 4:] |
|
195 | 197 | elif _status == "3string": |
|
196 | 198 | currentLine = src[src.rfind('>>>') + 4:] |
|
197 | 199 | currentLine = currentLine.replace('\n... ', '\n') |
|
198 | 200 | else: |
|
199 | 201 | currentLine = src[src.rfind('...') + 4:] |
|
200 | 202 | if _status == 'main' and not currentLine.strip(): |
|
201 | 203 | doc['console'].value += '\n>>> ' |
|
202 | 204 | event.preventDefault() |
|
203 | 205 | return |
|
204 | 206 | doc['console'].value += '\n' |
|
205 | 207 | history.append(currentLine) |
|
206 | 208 | current = len(history) |
|
207 | 209 | if _status == "main" or _status == "3string": |
|
208 | 210 | try: |
|
209 | 211 | _ = editor_ns['_'] = eval(currentLine, editor_ns) |
|
210 | 212 | if _ is not None: |
|
211 | 213 | write(repr(_)+'\n') |
|
212 | 214 | doc['console'].value += '>>> ' |
|
213 | 215 | _status = "main" |
|
214 | 216 | except IndentationError: |
|
215 | 217 | doc['console'].value += '... ' |
|
216 | 218 | _status = "block" |
|
217 | 219 | except SyntaxError as msg: |
|
218 | 220 | if str(msg) == 'invalid syntax : triple string end not found' or \ |
|
219 | 221 | str(msg).startswith('Unbalanced bracket'): |
|
220 | 222 | doc['console'].value += '... ' |
|
221 | 223 | _status = "3string" |
|
222 | 224 | elif str(msg) == 'eval() argument must be an expression': |
|
223 | 225 | try: |
|
224 | 226 | exec(currentLine, editor_ns) |
|
225 | 227 | except: |
|
226 | 228 | traceback.print_exc() |
|
227 | 229 | doc['console'].value += '>>> ' |
|
228 | 230 | _status = "main" |
|
229 | 231 | elif str(msg) == 'decorator expects function': |
|
230 | 232 | doc['console'].value += '... ' |
|
231 | 233 | _status = "block" |
|
232 | 234 | else: |
|
233 | 235 | traceback.print_exc() |
|
234 | 236 | doc['console'].value += '>>> ' |
|
235 | 237 | _status = "main" |
|
236 | 238 | except: |
|
237 | 239 | traceback.print_exc() |
|
238 | 240 | doc['console'].value += '>>> ' |
|
239 | 241 | _status = "main" |
|
240 | 242 | elif currentLine == "": # end of block |
|
241 | 243 | block = src[src.rfind('>>>') + 4:].splitlines() |
|
242 | 244 | block = [block[0]] + [b[4:] for b in block[1:]] |
|
243 | 245 | block_src = '\n'.join(block) |
|
244 | 246 | # status must be set before executing code in globals() |
|
245 | 247 | _status = "main" |
|
246 | 248 | try: |
|
247 | 249 | _ = exec(block_src, editor_ns) |
|
248 | 250 | if _ is not None: |
|
249 | 251 | print(repr(_)) |
|
250 | 252 | except: |
|
251 | 253 | traceback.print_exc() |
|
252 | 254 | doc['console'].value += '>>> ' |
|
253 | 255 | else: |
|
254 | 256 | doc['console'].value += '... ' |
|
255 | 257 | |
|
256 | 258 | cursorToEnd() |
|
257 | 259 | event.preventDefault() |
|
258 | 260 | |
|
259 | 261 | def myKeyDown(event): |
|
260 | 262 | global _status, current |
|
261 | 263 | if event.keyCode == 37: # left arrow |
|
262 | 264 | sel = get_col(doc['console']) |
|
263 | 265 | if sel < 5: |
|
264 | 266 | event.preventDefault() |
|
265 | 267 | event.stopPropagation() |
|
266 | 268 | elif event.keyCode == 36: # line start |
|
267 | 269 | pos = doc['console'].selectionStart |
|
268 | 270 | col = get_col(doc['console']) |
|
269 | 271 | doc['console'].setSelectionRange(pos - col + 4, pos - col + 4) |
|
270 | 272 | event.preventDefault() |
|
271 | 273 | elif event.keyCode == 38: # up |
|
272 | 274 | if current > 0: |
|
273 | 275 | pos = doc['console'].selectionStart |
|
274 | 276 | col = get_col(doc['console']) |
|
275 | 277 | # remove current line |
|
276 | 278 | doc['console'].value = doc['console'].value[:pos - col + 4] |
|
277 | 279 | current -= 1 |
|
278 | 280 | doc['console'].value += history[current] |
|
279 | 281 | event.preventDefault() |
|
280 | 282 | elif event.keyCode == 40: # down |
|
281 | 283 | if current < len(history) - 1: |
|
282 | 284 | pos = doc['console'].selectionStart |
|
283 | 285 | col = get_col(doc['console']) |
|
284 | 286 | # remove current line |
|
285 | 287 | doc['console'].value = doc['console'].value[:pos - col + 4] |
|
286 | 288 | current += 1 |
|
287 | 289 | doc['console'].value += history[current] |
|
288 | 290 | event.preventDefault() |
|
289 | 291 | elif event.keyCode == 8: # backspace |
|
290 | 292 | src = doc['console'].value |
|
291 | 293 | lstart = src.rfind('\n') |
|
292 | 294 | if (lstart == -1 and len(src) < 5) or (len(src) - lstart < 6): |
|
293 | 295 | event.preventDefault() |
|
294 | 296 | event.stopPropagation() |
|
295 | 297 | |
|
296 | 298 | |
|
297 | 299 | doc['console'].bind('keypress', myKeyPress) |
|
298 | 300 | doc['console'].bind('keydown', myKeyDown) |
|
299 | 301 | doc['console'].bind('click', cursorToEnd) |
|
300 | 302 | v = sys.implementation.version |
|
301 | 303 | doc['console'].value = "Brython %s.%s.%s on %s %s\n>>> " % ( |
|
302 | 304 | v[0], v[1], v[2], window.navigator.appName, window.navigator.appVersion) |
|
303 | 305 | #doc['console'].value += 'Type "copyright", "credits" or "license" for more information.' |
|
304 | 306 | doc['console'].focus() |
|
305 | 307 | cursorToEnd() |
|
306 | 308 | |
|
307 | 309 | |
|
308 | 310 | |
|
309 | 311 |
You need to be logged in to leave comments.
Login now