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
49a000a3
Commit
49a000a3
authored
Dec 07, 2011
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Folding stuff in capa_module from views
parent
9e18b261
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
42 deletions
+26
-42
courseware/capa_module.py
+8
-3
courseware/models.py
+1
-0
courseware/views.py
+14
-37
courseware/x_module.py
+2
-1
urls.py
+1
-1
No files found.
courseware/capa_module.py
View file @
49a000a3
...
...
@@ -33,8 +33,6 @@ class LoncapaModule(XModule):
return
render_to_string
(
'problem.html'
,
{
'problem'
:
content
,
'id'
:
self
.
filename
})
def
__init__
(
self
,
xml
,
item_id
,
ajax_url
=
None
,
track_url
=
None
,
state
=
None
):
XModule
.
__init__
(
self
,
xml
,
item_id
,
ajax_url
,
track_url
,
state
)
dom
=
parseString
(
xml
)
...
...
@@ -48,4 +46,11 @@ class LoncapaModule(XModule):
# Temporary
def
check_problem
(
self
,
get
):
pass
answer
=
dict
()
# input_resistor_1 ==> resistor_1
for
key
in
get
:
answer
[
'_'
.
join
(
key
.
split
(
'_'
)[
1
:])]
=
get
[
key
]
js
=
json
.
dumps
(
self
.
lcp
.
grade_answers
(
answer
))
return
js
courseware/models.py
View file @
49a000a3
...
...
@@ -49,6 +49,7 @@ class StudentModule(models.Model):
module_id
=
models
.
CharField
(
max_length
=
255
)
# Filename for homeworks, etc.
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
modified
=
models
.
DateTimeField
(
auto_now
=
True
)
xml
=
models
.
TextField
(
blank
=
True
)
class
Meta
:
unique_together
=
((
'student'
,
'module_id'
,
'module_type'
),)
...
...
courseware/views.py
View file @
49a000a3
...
...
@@ -128,7 +128,8 @@ def render_x_module(request, xml_module):
problem
=
capa_module
.
LoncapaModule
(
xml_module
.
toxml
(),
module_id
)
smod
=
StudentModule
(
student
=
request
.
user
,
module_id
=
module_id
,
state
=
problem
.
get_state
())
state
=
problem
.
get_state
(),
xml
=
problem
.
xml
)
smod
.
save
()
elif
len
(
s
)
==
1
:
# If so, render it
...
...
@@ -140,56 +141,32 @@ def render_x_module(request, xml_module):
return
{
'content'
:
problem
.
get_html
()}
def
modx_dispatch
(
request
,
dispatch
=
None
,
id
=
None
):
s
=
StudentModule
.
objects
.
filter
(
student
=
request
.
user
,
module_id
=
id
)
def
modx_dispatch
(
request
,
module
=
None
,
dispatch
=
None
,
id
=
None
):
s
=
StudentModule
.
objects
.
filter
(
module_type
=
module
,
student
=
request
.
user
,
module_id
=
id
)
if
len
(
s
)
==
0
:
raise
Http404
s
=
s
[
0
]
dispatch
=
dispatch
.
split
(
'?'
)[
0
]
if
dispatch
==
'problem_check'
:
return
check_problem
(
request
)
problem
=
capa_module
.
LoncapaModule
(
s
.
xml
,
s
.
module_id
,
state
=
s
.
state
)
html
=
problem
.
check_problem
(
request
.
GET
)
s
.
state
=
problem
.
get_state
()
s
.
grade
=
problem
.
get_score
()[
'score'
]
s
.
save
()
return
HttpResponse
(
html
)
#check_problem(s, request.GET)
elif
dispatch
==
'problem_reset'
:
return
reset_problem
(
request
,
id
)
else
:
print
"AAA"
raise
Http404
def
reset_problem
(
request
,
id
):
s
=
StudentModule
.
objects
.
filter
(
student
=
request
.
user
,
module_id
=
id
)
s
[
0
]
.
delete
()
return
HttpResponse
(
json
.
dumps
({}),
mimetype
=
"application/json"
)
def
check_problem
(
request
):
answer
=
dict
()
# input_resistor_1 ==> resistor_1
for
key
in
request
.
GET
:
answer
[
'_'
.
join
(
key
.
split
(
'_'
)[
1
:])]
=
request
.
GET
[
key
]
## THE NEXT TWO LINES ARE SUBTLE, AND CAN EASILY INTRODUCE SECURITY ISSUES
#
# The filename is grabbed from the user. The user could inject arbitrary
# filenames and potentially compromise our system. The second line prevents
# this, since we confirm filename is a valid module_id in the database.
# Small changes to the code or to the database could break this.
#
# We should probably add an explicit check to make sure the filename is in
# the XML file to make this less fragile.
filename
=
answer
.
keys
()[
0
]
.
split
(
'_'
)[
0
]
s
=
StudentModule
.
objects
.
filter
(
student
=
request
.
user
,
module_id
=
filename
)
if
len
(
s
)
==
1
:
s
=
s
[
0
]
problem
=
capa_problem
.
LoncapaProblem
(
settings
.
DATA_DIR
+
filename
+
'.xml'
,
id
=
filename
,
state
=
s
.
state
)
js
=
json
.
dumps
(
problem
.
grade_answers
(
answer
))
s
.
state
=
problem
.
get_state
()
s
.
grade
=
problem
.
get_score
()[
'score'
]
s
.
save
()
else
:
raise
Exception
(
"Database is inconsistent (3)."
)
return
HttpResponse
(
js
,
mimetype
=
"application/json"
)
module_types
=
{
'video'
:
video_module
,
'html'
:
html_module
,
'tab'
:
tab_module
,
...
...
courseware/x_module.py
View file @
49a000a3
...
...
@@ -26,7 +26,8 @@ class XModule:
def
handle_ajax
(
self
,
json
):
return
def
__init__
(
self
,
xml
,
item_id
,
ajax_url
,
track_url
,
state
=
None
):
def
__init__
(
self
,
xml
,
item_id
,
ajax_url
=
None
,
track_url
=
None
,
state
=
None
):
''' In most cases, you must pass state or xml'''
self
.
xml
=
xml
self
.
item_id
=
item_id
self
.
ajax_url
=
ajax_url
...
...
urls.py
View file @
49a000a3
...
...
@@ -10,7 +10,7 @@ urlpatterns = patterns('',
url
(
r'^courseware/(?P<course>[^/]*)/(?P<chapter>[^/]*)/$'
,
'courseware.views.index'
),
url
(
r'^courseware/(?P<course>[^/]*)/$'
,
'courseware.views.index'
),
# url(r'^courseware/modx/(?P<id>[^/]*)/problem_check$', 'courseware.views.check_problem'),
url
(
r'^
courseware/modx
/(?P<id>[^/]*)/(?P<dispatch>[^/]*)$'
,
'courseware.views.modx_dispatch'
),
#reset_problem'),
url
(
r'^
modx/(?P<module>[^/]*)
/(?P<id>[^/]*)/(?P<dispatch>[^/]*)$'
,
'courseware.views.modx_dispatch'
),
#reset_problem'),
url
(
r'^courseware/$'
,
'courseware.views.index'
),
url
(
r'^profile$'
,
'courseware.views.profile'
),
# url(r'^admin/', include('django.contrib.admin.urls')),
...
...
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