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
8b248375
Commit
8b248375
authored
Dec 07, 2011
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor working
parent
24bf20e1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
24 deletions
+37
-24
courseware/capa_module.py
+20
-3
courseware/capa_problem.py
+1
-1
courseware/views.py
+12
-18
courseware/x_module.py
+4
-2
No files found.
courseware/capa_module.py
View file @
8b248375
...
...
@@ -17,7 +17,6 @@ class LoncapaModule(XModule):
id_attribute
=
"filename"
def
get_state
(
self
):
print
"got"
return
self
.
lcp
.
get_state
()
def
get_score
(
self
):
...
...
@@ -40,10 +39,19 @@ class LoncapaModule(XModule):
self
.
filename
=
node
.
getAttribute
(
"filename"
)
filename
=
settings
.
DATA_DIR
+
self
.
filename
+
".xml"
self
.
name
=
node
.
getAttribute
(
"name"
)
print
state
self
.
lcp
=
LoncapaProblem
(
filename
,
item_id
,
state
)
# Temporary
def
handle_ajax
(
self
,
dispatch
,
get
):
if
dispatch
==
'problem_check'
:
html
=
self
.
check_problem
(
get
)
elif
dispatch
==
'problem_reset'
:
html
=
self
.
reset_problem
(
get
)
else
:
return
"Error"
return
html
# Temporary -- move to capa_problem
def
check_problem
(
self
,
get
):
answer
=
dict
()
...
...
@@ -54,3 +62,12 @@ class LoncapaModule(XModule):
js
=
json
.
dumps
(
self
.
lcp
.
grade_answers
(
answer
))
return
js
def
reset_problem
(
self
,
get
):
self
.
lcp
.
answers
=
dict
()
self
.
lcp
.
context
=
dict
()
self
.
lcp
.
questions
=
dict
()
# Detailed info about questions in problem instance. TODO: Should be by id and not lid.
self
.
lcp
.
answers
=
dict
()
# Student answers
self
.
lcp
.
correct_map
=
dict
()
self
.
lcp
.
seed
=
None
return
"{}"
courseware/capa_problem.py
View file @
8b248375
...
...
@@ -42,7 +42,7 @@ class LoncapaProblem():
state
=
{}
self
.
gid
=
id
if
'seed'
in
state
:
if
'seed'
in
state
and
state
[
'seed'
]
!=
None
and
state
[
'seed'
]
!=
""
:
self
.
seed
=
state
[
'seed'
]
else
:
# TODO: Check performance of urandom -- depending on
...
...
courseware/views.py
View file @
8b248375
...
...
@@ -119,8 +119,11 @@ def vertical_module(request, module):
return
{
'js'
:
js
,
'content'
:
render_to_string
(
'vert_module.html'
,{
'items'
:
contents
})}
modx_modules
=
{
'problem'
:
capa_module
.
LoncapaModule
}
def
render_x_module
(
request
,
xml_module
):
# Check if problem has an instance in DB
print
xml_module
module_id
=
xml_module
.
getAttribute
(
capa_module
.
LoncapaModule
.
id_attribute
)
s
=
StudentModule
.
objects
.
filter
(
student
=
request
.
user
,
module_id
=
module_id
)
if
len
(
s
)
==
0
:
...
...
@@ -133,9 +136,12 @@ def render_x_module(request, xml_module):
smod
.
save
()
elif
len
(
s
)
==
1
:
# If so, render it
s
=
s
[
0
]
problem
=
capa_module
.
LoncapaModule
(
xml_module
.
toxml
(),
module_id
,
state
=
s
[
0
]
.
state
)
state
=
s
.
state
)
s
.
state
=
problem
.
get_state
()
s
.
save
()
else
:
raise
Exception
(
"Database is inconsistent (1)."
)
...
...
@@ -149,24 +155,12 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
s
=
s
[
0
]
dispatch
=
dispatch
.
split
(
'?'
)[
0
]
if
dispatch
==
'problem_check'
:
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
:
raise
Http404
def
reset_problem
(
request
,
id
):
s
=
StudentModule
.
objects
.
filter
(
student
=
request
.
user
,
module_id
=
id
)[
0
]
s
.
state
=
"{}"
problem
=
modx_modules
[
module
](
s
.
xml
,
s
.
module_id
,
state
=
s
.
state
)
html
=
problem
.
handle_ajax
(
dispatch
,
request
.
GET
)
s
.
state
=
problem
.
get_state
()
s
.
grade
=
problem
.
get_score
()[
'score'
]
s
.
save
()
return
HttpResponse
(
json
.
dumps
({}),
mimetype
=
"application/json"
)
return
HttpResponse
(
html
)
module_types
=
{
'video'
:
video_module
,
'html'
:
html_module
,
...
...
courseware/x_module.py
View file @
8b248375
...
...
@@ -23,8 +23,10 @@ class XModule:
def
get_html
(
self
):
return
"Unimplemented"
def
handle_ajax
(
self
,
json
):
return
def
handle_ajax
(
self
,
dispatch
,
get
):
''' dispatch is last part of the URL.
get is a dictionary-like object '''
return
""
def
__init__
(
self
,
xml
,
item_id
,
ajax_url
=
None
,
track_url
=
None
,
state
=
None
):
''' In most cases, you must pass state or xml'''
...
...
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