Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
e3bc9f83
Commit
e3bc9f83
authored
Oct 25, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor textbox.
- tests - rename it codeinput, with textbox still supported too
parent
4bffcdb8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
53 deletions
+97
-53
common/lib/capa/capa/inputtypes.py
+47
-52
common/lib/capa/capa/templates/codeinput.html
+0
-0
common/lib/capa/capa/tests/test_inputtypes.py
+50
-1
No files found.
common/lib/capa/capa/inputtypes.py
View file @
e3bc9f83
...
@@ -489,66 +489,61 @@ register_input_class(FileSubmission)
...
@@ -489,66 +489,61 @@ register_input_class(FileSubmission)
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
## TODO: Make a wrapper for <codeinput>
def
textbox
(
element
,
value
,
status
,
render_template
,
msg
=
''
):
'''
The textbox is used for code input. The message is the return HTML string from
evaluating the code, eg error messages, and output from the code tests.
'''
class
CodeInput
(
InputTypeBase
):
eid
=
element
.
get
(
'id'
)
"""
count
=
int
(
eid
.
split
(
'_'
)[
-
2
])
-
1
# HACK
A text area input for code--uses codemirror, does syntax highlighting, special tab handling,
size
=
element
.
get
(
'size'
)
etc.
rows
=
element
.
get
(
'rows'
)
or
'30'
"""
cols
=
element
.
get
(
'cols'
)
or
'80'
# if specified, then textline is hidden and id is stored in div of name given by hidden
template
=
"codeinput.html"
hidden
=
element
.
get
(
'hidden'
,
''
)
tags
=
[
'codeinput'
,
'textbox'
,
# Old name for this. Still supported, but deprecated.
]
# if no student input yet, then use the default input given by the problem
def
__init__
(
self
,
system
,
xml
,
state
):
if
not
value
:
super
(
CodeInput
,
self
)
.
__init__
(
system
,
xml
,
state
)
value
=
element
.
text
# Check if problem has been queued
self
.
rows
=
xml
.
get
(
'rows'
)
or
'30'
queue_len
=
0
self
.
cols
=
xml
.
get
(
'cols'
)
or
'80'
# Flag indicating that the problem has been queued, 'msg' is length of queue
# if specified, then textline is hidden and id is stored in div of name given by hidden
if
status
==
'incomplete'
:
self
.
hidden
=
xml
.
get
(
'hidden'
,
''
)
status
=
'queued'
queue_len
=
msg
msg
=
'Submitted to grader.'
# For CodeMirror
# if no student input yet, then use the default input given by the problem
mode
=
element
.
get
(
'mode'
,
'python'
)
if
not
self
.
value
:
linenumbers
=
element
.
get
(
'linenumbers'
,
'true'
)
self
.
value
=
xml
.
text
tabsize
=
element
.
get
(
'tabsize'
,
'4'
)
tabsize
=
int
(
tabsize
)
context
=
{
'id'
:
eid
,
# Check if problem has been queued
'value'
:
value
,
self
.
queue_len
=
0
'state'
:
status
,
# Flag indicating that the problem has been queued, 'msg' is length of queue
'count'
:
count
,
if
self
.
status
==
'incomplete'
:
'size'
:
size
,
self
.
status
=
'queued'
'msg'
:
msg
,
self
.
queue_len
=
self
.
msg
'mode'
:
mode
,
self
.
msg
=
'Submitted to grader.'
'linenumbers'
:
linenumbers
,
'rows'
:
rows
,
# For CodeMirror
'cols'
:
cols
,
self
.
mode
=
xml
.
get
(
'mode'
,
'python'
)
'hidden'
:
hidden
,
self
.
linenumbers
=
xml
.
get
(
'linenumbers'
,
'true'
)
'tabsize'
:
tabsize
,
self
.
tabsize
=
int
(
xml
.
get
(
'tabsize'
,
'4'
))
'queue_len'
:
queue_len
,
def
_get_render_context
(
self
):
context
=
{
'id'
:
self
.
id
,
'value'
:
self
.
value
,
'state'
:
self
.
status
,
'msg'
:
self
.
msg
,
'mode'
:
self
.
mode
,
'linenumbers'
:
self
.
linenumbers
,
'rows'
:
self
.
rows
,
'cols'
:
self
.
cols
,
'hidden'
:
self
.
hidden
,
'tabsize'
:
self
.
tabsize
,
'queue_len'
:
self
.
queue_len
,
}
}
html
=
render_template
(
"textbox.html"
,
context
)
return
context
try
:
xhtml
=
etree
.
XML
(
html
)
except
Exception
as
err
:
newmsg
=
'error
%
s in rendering message'
%
(
str
(
err
)
.
replace
(
'<'
,
'<'
))
newmsg
+=
'<br/>Original message:
%
s'
%
msg
.
replace
(
'<'
,
'<'
)
context
[
'msg'
]
=
newmsg
html
=
render_template
(
"textbox.html"
,
context
)
xhtml
=
etree
.
XML
(
html
)
return
xhtml
register_input_class
(
CodeInput
)
_reg
(
textbox
)
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
def
schematic
(
element
,
value
,
status
,
render_template
,
msg
=
''
):
def
schematic
(
element
,
value
,
status
,
render_template
,
msg
=
''
):
...
...
common/lib/capa/capa/templates/
textbox
.html
→
common/lib/capa/capa/templates/
codeinput
.html
View file @
e3bc9f83
File moved
common/lib/capa/capa/tests/test_inputtypes.py
View file @
e3bc9f83
...
@@ -251,7 +251,7 @@ class FileSubmissionTest(unittest.TestCase):
...
@@ -251,7 +251,7 @@ class FileSubmissionTest(unittest.TestCase):
escapedict
=
{
'"'
:
'"'
}
escapedict
=
{
'"'
:
'"'
}
esc
=
lambda
s
:
saxutils
.
escape
(
s
,
escapedict
)
esc
=
lambda
s
:
saxutils
.
escape
(
s
,
escapedict
)
state
=
{
'value'
:
'BumbleBee.py'
,
state
=
{
'value'
:
'BumbleBee.py'
,
'status'
:
'incomplete'
,
'status'
:
'incomplete'
,
'feedback'
:
{
'message'
:
'3'
},
}
'feedback'
:
{
'message'
:
'3'
},
}
...
@@ -269,3 +269,52 @@ class FileSubmissionTest(unittest.TestCase):
...
@@ -269,3 +269,52 @@ class FileSubmissionTest(unittest.TestCase):
self
.
assertEqual
(
context
,
expected
)
self
.
assertEqual
(
context
,
expected
)
class
CodeInputTest
(
unittest
.
TestCase
):
'''
Check that codeinput inputs work
'''
def
test_rendering
(
self
):
mode
=
"parrot"
linenumbers
=
'false'
rows
=
'37'
cols
=
'11'
tabsize
=
'7'
xml_str
=
"""<codeinput id="prob_1_2"
mode="{m}"
cols="{c}"
rows="{r}"
linenumbers="{ln}"
tabsize="{ts}"
/>"""
.
format
(
m
=
mode
,
c
=
cols
,
r
=
rows
,
ln
=
linenumbers
,
ts
=
tabsize
)
element
=
etree
.
fromstring
(
xml_str
)
escapedict
=
{
'"'
:
'"'
}
esc
=
lambda
s
:
saxutils
.
escape
(
s
,
escapedict
)
state
=
{
'value'
:
'print "good evening"'
,
'status'
:
'incomplete'
,
'feedback'
:
{
'message'
:
'3'
},
}
the_input
=
inputtypes
.
get_class_for_tag
(
'codeinput'
)(
system
,
element
,
state
)
context
=
the_input
.
_get_render_context
()
expected
=
{
'id'
:
'prob_1_2'
,
'value'
:
'print "good evening"'
,
'state'
:
'queued'
,
'msg'
:
'Submitted to grader.'
,
'mode'
:
mode
,
'linenumbers'
:
linenumbers
,
'rows'
:
rows
,
'cols'
:
cols
,
'hidden'
:
''
,
'tabsize'
:
int
(
tabsize
),
'queue_len'
:
'3'
,
}
self
.
assertEqual
(
context
,
expected
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment