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
94657602
Commit
94657602
authored
Dec 08, 2011
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor cleanup
parent
8b248375
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
17 deletions
+44
-17
courseware/capa_module.py
+5
-1
courseware/capa_problem.py
+7
-2
courseware/content_parser.py
+12
-0
courseware/views.py
+20
-14
No files found.
courseware/capa_module.py
View file @
94657602
...
...
@@ -29,8 +29,10 @@ class LoncapaModule(XModule):
inner_html
=
self
.
lcp
.
get_html
()
content
=
{
'name'
:
self
.
name
,
'html'
:
inner_html
}
print
"XXXXXXXXXXXXXXXXXXXXXXXXXXX"
print
self
.
lcp
.
done
return
render_to_string
(
'problem.html'
,
{
'problem'
:
content
,
'id'
:
self
.
filename
})
{
'problem'
:
content
,
'id'
:
self
.
filename
,
'done'
:
self
.
lcp
.
done
})
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
)
...
...
@@ -54,6 +56,7 @@ class LoncapaModule(XModule):
# Temporary -- move to capa_problem
def
check_problem
(
self
,
get
):
self
.
lcp
.
done
=
True
answer
=
dict
()
# input_resistor_1 ==> resistor_1
for
key
in
get
:
...
...
@@ -64,6 +67,7 @@ class LoncapaModule(XModule):
return
js
def
reset_problem
(
self
,
get
):
self
.
lcp
.
done
=
False
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.
...
...
courseware/capa_problem.py
View file @
94657602
...
...
@@ -12,7 +12,8 @@ class LoncapaProblem():
2) Populate any student answers. '''
return
json
.
dumps
({
'seed'
:
self
.
seed
,
'answers'
:
self
.
answers
,
'correct_map'
:
self
.
correct_map
})
'correct_map'
:
self
.
correct_map
,
'done'
:
self
.
done
})
def
get_score
(
self
):
correct
=
0
...
...
@@ -41,7 +42,10 @@ class LoncapaProblem():
else
:
state
=
{}
self
.
gid
=
id
if
'done'
in
state
:
self
.
done
=
state
[
'done'
]
if
'seed'
in
state
and
state
[
'seed'
]
!=
None
and
state
[
'seed'
]
!=
""
:
self
.
seed
=
state
[
'seed'
]
else
:
...
...
@@ -81,6 +85,7 @@ class LoncapaProblem():
self
.
text
=
self
.
contextualize_text
(
self
.
text
)
self
.
filename
=
filename
done
=
False
text
=
""
context
=
{}
# Execution context from loncapa/python
questions
=
{}
# Detailed info about questions in problem instance. TODO: Should be by id and not lid.
...
...
courseware/content_parser.py
View file @
94657602
from
django.conf
import
settings
from
xml.dom.minidom
import
parse
,
parseString
''' This file will eventually form an abstraction layer between the
course XML file and the rest of the system.
'''
def
toc_from_xml
(
active_chapter
,
active_section
):
dom
=
parse
(
settings
.
DATA_DIR
+
'course.xml'
)
...
...
@@ -23,3 +26,12 @@ def toc_from_xml(active_chapter,active_section):
'active'
:(
c
.
getAttribute
(
"name"
)
==
active_chapter
)})
return
ch
def
dom_select
(
dom
,
element_type
,
element_name
):
if
dom
==
None
:
return
None
elements
=
dom
.
getElementsByTagName
(
element_type
)
for
e
in
elements
:
if
e
.
getAttribute
(
"name"
)
==
element_name
:
return
e
return
None
courseware/views.py
View file @
94657602
...
...
@@ -16,7 +16,7 @@ from django.http import Http404
import
urllib
import
capa_module
,
capa_problem
import
capa_module
from
models
import
StudentModule
...
...
@@ -29,6 +29,8 @@ from content_parser import *
template_imports
=
{
'urllib'
:
urllib
}
def
profile
(
request
):
''' User profile. Show username, location, etc, as well as grades .
We need to allow the user to change some of these settings .'''
if
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/'
)
...
...
@@ -74,7 +76,7 @@ def profile(request):
return
render_to_response
(
'profile.html'
,
context
)
def
render_accordion
(
request
,
course
,
chapter
,
section
):
''' Draws
accordion
. Takes current position in accordion as
''' Draws
navigation bar
. Takes current position in accordion as
parameter. Returns (initialization_javascript, content)'''
def
format_string
(
string
):
return
urllib
.
quote
(
string
.
replace
(
' '
,
'_'
))
...
...
@@ -93,15 +95,21 @@ def render_accordion(request,course,chapter,section):
'content'
:
render_to_string
(
'accordion.html'
,
context
)}
def
video_module
(
request
,
module
):
''' Shows a video, with subtitles.
'''
id
=
module
.
getAttribute
(
'youtube'
)
return
{
'js'
:
render_to_string
(
'video_init.js'
,{
'id'
:
id
}),
'content'
:
render_to_string
(
'video.html'
,{})}
def
html_module
(
request
,
module
):
''' Show basic text
'''
template_source
=
module
.
getAttribute
(
'filename'
)
return
{
'content'
:
render_to_string
(
template_source
,
{})}
def
tab_module
(
request
,
module
):
''' Layout module which lays out content in tabs.
'''
contents
=
[(
e
.
getAttribute
(
"name"
),
render_module
(
request
,
e
))
\
for
e
in
module
.
childNodes
\
if
e
.
nodeType
==
1
]
...
...
@@ -111,6 +119,8 @@ def tab_module(request, module):
'content'
:
render_to_string
(
'tab_module.html'
,{
'tabs'
:
contents
})}
def
vertical_module
(
request
,
module
):
''' Layout module which lays out content vertically.
'''
contents
=
[(
e
.
getAttribute
(
"name"
),
render_module
(
request
,
e
))
\
for
e
in
module
.
childNodes
\
if
e
.
nodeType
==
1
]
...
...
@@ -122,6 +132,7 @@ def vertical_module(request, module):
modx_modules
=
{
'problem'
:
capa_module
.
LoncapaModule
}
def
render_x_module
(
request
,
xml_module
):
''' Generic module for extensions. This renders to HTML. '''
# Check if problem has an instance in DB
print
xml_module
module_id
=
xml_module
.
getAttribute
(
capa_module
.
LoncapaModule
.
id_attribute
)
...
...
@@ -148,6 +159,7 @@ def render_x_module(request, xml_module):
return
{
'content'
:
problem
.
get_html
()}
def
modx_dispatch
(
request
,
module
=
None
,
dispatch
=
None
,
id
=
None
):
''' Generic module for extensions. This handles AJAX. '''
s
=
StudentModule
.
objects
.
filter
(
module_type
=
module
,
student
=
request
.
user
,
module_id
=
id
)
if
len
(
s
)
==
0
:
raise
Http404
...
...
@@ -170,22 +182,16 @@ module_types={'video':video_module,
#'lab':lab_module,
def
render_module
(
request
,
module
):
''' Generic dispatch for internal modules. '''
if
module
==
None
:
return
{
"content"
:
""
}
if
str
(
module
.
localName
)
in
module_types
:
return
module_types
[
module
.
localName
](
request
,
module
)
return
{
"content"
:
""
}
def
dom_select
(
dom
,
element_type
,
element_name
):
if
dom
==
None
:
return
None
elements
=
dom
.
getElementsByTagName
(
element_type
)
for
e
in
elements
:
if
e
.
getAttribute
(
"name"
)
==
element_name
:
return
e
return
None
def
index
(
request
,
course
=
"6.002 Spring 2012"
,
chapter
=
"Using the System"
,
section
=
"Hints"
):
''' Displays courseware accordion, and any associated content.
'''
if
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/'
)
...
...
@@ -200,9 +206,9 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
return
redirect
(
'/'
)
dom
=
parse
(
settings
.
DATA_DIR
+
'course.xml'
)
dom_course
=
dom_select
(
dom
,
'course'
,
course
)
dom_chapter
=
dom_select
(
dom_course
,
'chapter'
,
chapter
)
dom_section
=
dom_select
(
dom_chapter
,
'section'
,
section
)
dom_course
=
content_parser
.
dom_select
(
dom
,
'course'
,
course
)
dom_chapter
=
content_parser
.
dom_select
(
dom_course
,
'chapter'
,
chapter
)
dom_section
=
content_parser
.
dom_select
(
dom_chapter
,
'section'
,
section
)
if
dom_section
!=
None
:
module
=
[
e
for
e
in
dom_section
.
childNodes
if
e
.
nodeType
==
1
][
0
]
else
:
...
...
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