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
95060f39
Commit
95060f39
authored
Dec 24, 2012
by
Alexander Kryklia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated python part to sync with new interface
parent
61c68b74
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
31 deletions
+43
-31
common/lib/capa/capa/inputtypes.py
+38
-22
common/lib/capa/capa/templates/drag_and_drop_input.html
+5
-9
No files found.
common/lib/capa/capa/inputtypes.py
View file @
95060f39
...
...
@@ -45,6 +45,7 @@ import re
import
shlex
# for splitting quoted strings
import
sys
import
os
import
unidecode
from
registry
import
TagRegistry
...
...
@@ -798,29 +799,44 @@ class DragAndDropInput(InputTypeBase):
template
=
'drag_and_drop_input.html'
tags
=
[
'drag_and_drop_input'
]
@classmethod
def
get_attributes
(
cls
):
"""
Note: height, width, images_directory_path are required.
"""
# import ipdb; ipdb.set_trace()
return
[
Attribute
(
'height'
),
Attribute
(
'width'
),
Attribute
(
'images_directory_path'
),
]
def
setup
(
self
):
# import ipdb; ipdb.set_trace()
imagepath
=
self
.
loaded_attributes
[
'images_directory_path'
]
# import ipdb; ipdb.set_trace()
try
:
images_list
=
self
.
system
.
filestore
.
listdir
(
os
.
path
.
join
(
'static'
,
'images'
,
imagepath
))
images_list
=
[
'/static/images/'
+
img
for
img
in
images_list
]
except
:
images_list
=
[]
self
.
loaded_attributes
[
'images_list'
]
=
images_list
self
.
to_render
.
add
(
'images_list'
)
def
slugify
(
s
):
"""Makes slug from string"""
s
=
unidecode
.
unidecode
(
s
)
.
lower
()
return
re
.
sub
(
r'\W+'
,
'-'
,
s
)
def
parse
(
x
):
"""Parses <draggable/> xml element to dictionary.
Args:
xml etree element <draggable...> with optional
name or label or icon attributes. At least one
attribute must be presented.
Returns:
dict{'name': smth, 'label': smth, 'icon': smth}.
"""
dic
=
dict
()
for
attr_name
in
(
'name'
,
'label'
,
'icon'
):
try
:
dic
[
attr_name
]
=
Attribute
(
attr_name
)
.
parse_from_xml
(
x
)
except
ValueError
:
dic
[
attr_name
]
=
None
dic
[
'name'
]
=
dic
[
'name'
]
or
slugify
(
dic
[
'label'
])
dic
[
'label'
]
=
dic
[
'label'
]
or
dic
[
'name'
]
return
dic
to_js
=
dict
()
to_js
[
'target'
]
=
Attribute
(
'img'
)
.
parse_from_xml
(
self
.
xml
)
to_js
[
'draggable'
]
=
[
parse
(
draggable
)
for
draggable
in
self
.
xml
.
getchildren
()]
self
.
loaded_attributes
[
'drag_and_drop_json'
]
=
json
.
dumps
(
to_js
)
self
.
to_render
.
add
(
'drag_and_drop_json'
)
self
.
loaded_attributes
[
'course_folder'
]
=
self
.
system
.
course_id
.
split
(
'/'
)[
1
]
self
.
to_render
.
add
(
'course_folder'
)
registry
.
register
(
DragAndDropInput
)
...
...
common/lib/capa/capa/templates/drag_and_drop_input.html
View file @
95060f39
<section
id=
"inputtype_${id}"
class=
"capa_inputtype"
>
<div
class=
"drag_and_drop_problem"
id=
"drag_and_drop_div_${id}"
style=
"width:${width};height:${height}"
>
% if images_list:
<ul>
% for item in images_list:
<li><image
width=
"100"
height=
"100"
src=
"${item}"
></image></li>
% endfor
</ul>
% endif
data-plain-id=
"${id}"
data-course-folder=
"${course_folder}"
>
</div>
<div
class=
"script_placeholder"
data-src=
"/static/js/raphael.js"
></div>
<div
class=
"drag_and_drop_problem"
id=
"drag_and_drop_json_${id}"
style=
"display:none;"
>
${drag_and_drop_json}
</div>
<div
class=
"script_placeholder"
data-src=
"/static/js/capa/drag_and_drop.js"
></div>
% if status == 'unsubmitted':
<div
class=
"unanswered"
id=
"status_${id}"
>
...
...
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