Description:
- bootstrapize problem/edit - bootstrapize announcement/edit
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r650:72b80e42fb9b - - 4 files changed: 2 inserted, 113 deleted

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