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
ff536248
Commit
ff536248
authored
Aug 04, 2012
by
Mike Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style changes and comments
parent
8919fbd9
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
66 additions
and
58 deletions
+66
-58
cms/static/coffee/src/models/capadescriptor.coffee
+18
-18
cms/static/coffee/src/views/capawiki.coffee
+3
-3
cms/static/coffee/src/views/module_edit.coffee
+2
-2
cms/static/peg/capawiki.jspeg
+33
-28
common/lib/xmodule/setup.py
+1
-1
common/lib/xmodule/xmodule/capawiki_module.py
+5
-5
common/lib/xmodule/xmodule/modulestore/xml_importer.py
+4
-1
No files found.
cms/static/coffee/src/models/capadescriptor.coffee
View file @
ff536248
class
@
Capa
w
ikiDescriptor
class
@
Capa
W
ikiDescriptor
constructor
:
(
@
element
)
->
@
loadParser
(
"/static/peg/capawiki.jspeg"
)
@
capa
_b
ox
=
$
(
".capa-box"
,
@
element
)
@
wiki
_b
ox
=
$
(
".wiki-box"
,
@
element
)
@
capa
B
ox
=
$
(
".capa-box"
,
@
element
)
@
wiki
B
ox
=
$
(
".wiki-box"
,
@
element
)
save
:
->
{
'capa'
:
@
capa
_box
.
val
(),
'wiki'
:
@
wiki_b
ox
.
val
()}
{
'capa'
:
@
capa
Box
.
val
(),
'wiki'
:
@
wikiB
ox
.
val
()}
debug
:
(
msg
)
->
# console.log msg
...
...
@@ -23,16 +23,18 @@ class @CapawikiDescriptor
"Line "
+
e
.
line
+
", column "
+
e
.
column
+
": "
+
e
.
message
else
e
.
message
dom2capa
:
(
node
)
->
serializeDomToCapaXML
:
(
node
)
->
# serializes a Capa XML document and make changes if needed
# e.g. replace <text> into <startouttext />
serializer
=
new
XMLSerializer
()
capa
=
serializer
.
serializeToString
(
node
)
buildXML
:
(
parsed
)
->
dom
_p
arser
=
new
DOMParser
()
doc
=
dom
_p
arser
.
parseFromString
(
"<problem />"
,
"text/xml"
);
dom
P
arser
=
new
DOMParser
()
doc
=
dom
P
arser
.
parseFromString
(
"<problem />"
,
"text/xml"
);
problem
=
$
(
doc
).
find
(
'problem'
)
create
_text_e
lement
=
(
content
)
->
create
TextE
lement
=
(
content
)
->
el
=
$
(
doc
.
createElement
(
'text'
))
for
line
in
content
.
split
(
'
\n
'
)
el
.
append
doc
.
createTextNode
(
line
)
...
...
@@ -40,13 +42,13 @@ class @CapawikiDescriptor
el
.
children
().
last
().
remove
()
return
el
variable_name_w
rapper
=
(
expression
)
->
replaceVariableNameW
rapper
=
(
expression
)
->
match
=
/^\{(.+)\}$/
.
exec
(
expression
)
return
if
match
then
"$"
+
match
[
1
]
else
expression
for
section
in
parsed
if
section
.
type
==
'text'
newel
=
create
_text_e
lement
(
section
.
text
)
newel
=
create
TextE
lement
(
section
.
text
)
problem
.
append
(
newel
)
else
if
section
.
type
==
'image'
...
...
@@ -55,7 +57,7 @@ class @CapawikiDescriptor
img
.
attr
'src'
,
section
.
url
center
.
append
img
if
section
.
title
title
=
create
_text_e
lement
(
section
.
title
)
title
=
create
TextE
lement
(
section
.
title
)
center
.
append
doc
.
createElement
(
'br'
)
center
.
append
title
problem
.
append
center
...
...
@@ -78,14 +80,14 @@ class @CapawikiDescriptor
for
choice_def
in
section
.
choices
choice
=
$
(
doc
.
createElement
(
'choice'
))
choice
.
attr
'correct'
,
choice_def
.
correct
choice
.
append
create
_text_e
lement
(
choice_def
.
text
)
choice
.
append
create
TextE
lement
(
choice_def
.
text
)
group
.
append
(
choice
)
problem
.
append
(
newel
)
else
if
section
.
type
==
'numerical'
newel
=
$
(
doc
.
createElement
(
'numericalresponse'
))
newel
.
attr
'answer'
,
variable_name_w
rapper
(
section
.
answer
)
newel
.
attr
'answer'
,
replaceVariableNameW
rapper
(
section
.
answer
)
tolerance
=
$
(
doc
.
createElement
(
'responseparam'
))
tolerance
.
attr
'type'
,
'tolerance'
...
...
@@ -100,7 +102,7 @@ class @CapawikiDescriptor
else
if
section
.
type
==
'string'
newel
=
$
(
doc
.
createElement
(
'stringresponse'
))
newel
.
attr
'answer'
,
variable_name_w
rapper
(
section
.
answer
)
newel
.
attr
'answer'
,
replaceVariableNameW
rapper
(
section
.
answer
)
newel
.
append
doc
.
createElement
(
'textline'
)
problem
.
append
(
newel
)
...
...
@@ -108,7 +110,7 @@ class @CapawikiDescriptor
else
if
section
.
type
==
'formula'
formularesponse
=
$
(
doc
.
createElement
(
"formularesponse"
))
formularesponse
.
attr
'samples'
,
section
.
samples
formularesponse
.
attr
'answer'
,
variable_name_w
rapper
(
section
.
answer
)
formularesponse
.
attr
'answer'
,
replaceVariableNameW
rapper
(
section
.
answer
)
formularesponse
.
attr
'type'
,
'cs'
tolerance
=
$
(
doc
.
createElement
(
'responseparam'
))
...
...
@@ -126,7 +128,7 @@ class @CapawikiDescriptor
else
throw
new
SyntaxError
(
"unexpected section type "
+
section
.
type
)
capa
=
@
dom2capa
(
doc
)
capa
=
@
serializeDomToCapaXML
(
doc
)
return
capa
parse
:
(
source
)
->
...
...
@@ -144,5 +146,4 @@ class @CapawikiDescriptor
catch
e
message
=
@
buildParserErrorMessage
e
return
{
'message'
:
message
,
'status'
:
'error'
}
return
done
(
xml
)
\ No newline at end of file
cms/static/coffee/src/views/capawiki.coffee
View file @
ff536248
class
CMS
.
Views
.
Capa
w
ikiEdit
extends
Backbone
.
View
class
CMS
.
Views
.
Capa
W
ikiEdit
extends
Backbone
.
View
tagName
:
'section'
className
:
'edit-pane'
...
...
@@ -87,8 +87,8 @@ class CMS.Views.CapawikiEdit extends Backbone.View
event
.
preventDefault
()
previewType
=
$
(
event
.
target
).
data
(
'preview-type'
)
moduleType
=
$
(
event
.
target
).
data
(
'type'
)
if
moduleType
==
"Capa
w
ikiDescriptor"
CMS
.
pushView
new
CMS
.
Views
.
Capa
w
ikiEdit
if
moduleType
==
"Capa
W
ikiDescriptor"
CMS
.
pushView
new
CMS
.
Views
.
Capa
W
ikiEdit
model
:
new
CMS
.
Models
.
Module
id
:
$
(
event
.
target
).
data
(
'id'
)
type
:
if
moduleType
==
'None'
then
null
else
moduleType
...
...
cms/static/coffee/src/views/module_edit.coffee
View file @
ff536248
...
...
@@ -37,8 +37,8 @@ class CMS.Views.ModuleEdit extends Backbone.View
event
.
preventDefault
()
previewType
=
$
(
event
.
target
).
data
(
'preview-type'
)
moduleType
=
$
(
event
.
target
).
data
(
'type'
)
if
moduleType
==
"Capa
w
ikiDescriptor"
CMS
.
pushView
new
CMS
.
Views
.
Capa
w
ikiEdit
if
moduleType
==
"Capa
W
ikiDescriptor"
CMS
.
pushView
new
CMS
.
Views
.
Capa
W
ikiEdit
model
:
new
CMS
.
Models
.
Module
id
:
$
(
event
.
target
).
data
(
'id'
)
type
:
if
moduleType
==
'None'
then
null
else
moduleType
...
...
cms/static/peg/capawiki.jspeg
View file @
ff536248
...
...
@@ -8,7 +8,7 @@ start
GeneralResponse /
NumericalOrStringResponse /
NumericalResponse /
MultipleChoice /
MultipleChoice
Response
/
Paragraph
)+
...
...
@@ -116,7 +116,7 @@ NumericalOrStringResponse
}
/ StringResponse
/* MultipleChoice */
/* MultipleChoice
Response
*/
ChoiceTextLine
= !ChoiceIdentifier line:Line
...
...
@@ -130,7 +130,7 @@ Choice
return {'type': 'choice', 'correct' : correct, 'text': lines.join("").replace(/[\n\r]$/,"")};
}
MultipleChoice
MultipleChoice
Response
= choices:Choice+
{
return {'type': 'multiple_choice', 'choices': choices};
...
...
@@ -196,9 +196,35 @@ AlphanumericalText
return chars.join("");
}
/* JSON */
/* NumericalResponse */
NumericalToleranceValueType
= decimal / percentage / integer
NumericalTolerance
= '+-' ' '* value:NumericalToleranceValueType ' '*
{
return value;
}
NumericalResponse
= CorrectAnswerIdentifier ' '* '(' ' '* value:NumericalValue ' '* tolerance:NumericalTolerance? ')' ' '* Linebreak
{
if (tolerance == "")
tolerance = "5%"
return {'type': 'numerical', 'answer': value, 'tolerance': tolerance};
}
NumericalValue
= additive
/ VariableName
/* JSON parser based on the grammar described at http://json.org/. */
/* https://github.com/Contra/pegjs/blob/c9af3e4fb50a5e93bfb542a4298bb64735e9978e/examples/json.pegjs */
/* TODO: add prefixes to JSON and arithmetrics rules */
JSONDictionary
= _ o:object { return o; }
...
...
@@ -306,31 +332,10 @@ whitespace
= [ \t\n\r]
/* NumericalResponse */
NumericalToleranceValueType
= decimal / percentage / integer
NumericalTolerance
= '+-' ' '* value:NumericalToleranceValueType ' '*
{
return value;
}
NumericalResponse
= CorrectAnswerIdentifier ' '* '(' ' '* value:NumericalValue ' '* tolerance:NumericalTolerance? ')' ' '* Linebreak
{
if (tolerance == "")
tolerance = "5%"
return {'type': 'numerical', 'answer': value, 'tolerance': tolerance};
}
NumericalValue
= additive
/ VariableName
/* Mathematical rules */
/* Based on JSPEG's arithmetrics example at
https://raw.github.com/dmajda/pegjs/master/examples/arithmetics.pegjs
*/
additive
= left:multiplicative "+" right:additive { return left + right; }
/ left:multiplicative "-" right:additive { return left - right; }
...
...
common/lib/xmodule/setup.py
View file @
ff536248
...
...
@@ -27,7 +27,7 @@ setup(
"image = xmodule.backcompat_module:TranslateCustomTagDescriptor"
,
"error = xmodule.error_module:ErrorDescriptor"
,
"problem = xmodule.capa_module:CapaDescriptor"
,
"capawiki = xmodule.capawiki_module:Capa
w
ikiDescriptor"
,
"capawiki = xmodule.capawiki_module:Capa
W
ikiDescriptor"
,
"problemset = xmodule.vertical_module:VerticalDescriptor"
,
"section = xmodule.backcompat_module:SemanticSectionDescriptor"
,
"sequential = xmodule.seq_module:SequenceDescriptor"
,
...
...
common/lib/xmodule/xmodule/capawiki_module.py
View file @
ff536248
...
...
@@ -11,7 +11,7 @@ from xmodule.capa_module import CapaModule, CapaDescriptor
log
=
logging
.
getLogger
(
__name__
)
class
Capa
w
ikiModule
(
CapaModule
):
class
Capa
W
ikiModule
(
CapaModule
):
js
=
{
'coffee'
:
[
resource_string
(
__name__
,
'js/src/capa/display.coffee'
)],
'js'
:
[
resource_string
(
__name__
,
'js/src/capa/imageinput.js'
),
resource_string
(
__name__
,
'js/src/capa/schematic.js'
),
...
...
@@ -22,11 +22,11 @@ class CapawikiModule(CapaModule):
self
.
_definition
=
definition
assert
isinstance
(
definition
[
'data'
],
dict
)
and
'capa'
in
definition
[
'data'
]
self
.
capa_definition
=
{
'data'
:
definition
[
'data'
][
'capa'
]}
super
(
Capa
w
ikiModule
,
self
)
.
__init__
(
system
,
location
,
self
.
capa_definition
,
instance_state
,
super
(
Capa
W
ikiModule
,
self
)
.
__init__
(
system
,
location
,
self
.
capa_definition
,
instance_state
,
shared_state
,
**
kwargs
)
class
Capa
w
ikiDescriptor
(
CapaDescriptor
):
js_module_name
=
"Capa
w
ikiDescriptor"
module_class
=
Capa
w
ikiModule
class
Capa
W
ikiDescriptor
(
CapaDescriptor
):
js_module_name
=
"Capa
W
ikiDescriptor"
module_class
=
Capa
W
ikiModule
mako_template
=
"widgets/capawiki-edit.html"
common/lib/xmodule/xmodule/modulestore/xml_importer.py
View file @
ff536248
...
...
@@ -7,10 +7,13 @@ from .exceptions import DuplicateItemError
log
=
logging
.
getLogger
(
__name__
)
# TODO: added a command to invoke import_from_xml_capawiki
def
import_from_xml_capawiki
(
store
,
data_dir
,
course_dirs
=
None
,
eager
=
True
,
default_class
=
'xmodule.raw_module.RawDescriptor'
):
"""
import_from_xml_CapaWiki imports xml files from data_dir, converts
each problem into a CapaWiki problem.
Import the specified xml data_dir into the "store" modulestore,
using org and course as the location org and course.
...
...
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