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
1dad5cae
Commit
1dad5cae
authored
Dec 20, 2011
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic support for per-user courseware in place
parent
9ac4ac8a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
59 deletions
+16
-59
auth/models.py
+1
-1
courseware/capa_module.py
+0
-1
courseware/content_parser.py
+10
-5
courseware/module_render.py
+1
-1
courseware/profile.py
+0
-48
courseware/views.py
+4
-3
No files found.
auth/models.py
View file @
1dad5cae
...
...
@@ -11,7 +11,7 @@ class UserProfile(models.Model):
language
=
models
.
TextField
(
blank
=
True
)
location
=
models
.
TextField
(
blank
=
True
)
meta
=
models
.
TextField
(
blank
=
True
)
# JSON dictionary for future expansion
courseware
=
models
.
TextField
(
blank
=
True
,
default
=
'course
ware
.xml'
)
courseware
=
models
.
TextField
(
blank
=
True
,
default
=
'course.xml'
)
class
Registration
(
models
.
Model
):
''' Allows us to wait for e-mail before user is registered. A
...
...
courseware/capa_module.py
View file @
1dad5cae
...
...
@@ -9,7 +9,6 @@ from capa_problem import LoncapaProblem
import
dateutil
import
datetime
from
xml.dom.minidom
import
parse
,
parseString
## TODO: Abstract out from Django
...
...
courseware/content_parser.py
View file @
1dad5cae
from
django.conf
import
settings
from
xml.dom.minidom
import
parse
,
parseString
import
libxml2
from
auth.models
import
UserProfile
''' This file will eventually form an abstraction layer between the
course XML file and the rest of the system.
...
...
@@ -8,10 +9,14 @@ course XML file and the rest of the system.
TODO: Shift everything from xml.dom.minidom to XPath (or XQuery)
'''
def
module_xml
(
module
,
id_tag
,
module_id
):
def
course_file
(
user
):
# TODO: Cache. Also, return the libxml2 object.
return
settings
.
DATA_DIR
+
UserProfile
.
objects
.
get
(
user
=
user
)
.
courseware
def
module_xml
(
coursefile
,
module
,
id_tag
,
module_id
):
''' Get XML for a module based on module and module_id. Assumes
module occurs once in course
.xml
. '''
doc
=
libxml2
.
parseFile
(
settings
.
DATA_DIR
+
'course.xml'
)
module occurs once in course
ware XML file.
. '''
doc
=
libxml2
.
parseFile
(
coursefile
)
# Sanitize input
if
not
module
.
isalnum
():
...
...
@@ -28,8 +33,8 @@ def module_xml(module, id_tag, module_id):
return
None
return
result_set
[
0
]
.
serialize
()
def
toc_from_xml
(
active_chapter
,
active_section
):
dom
=
parse
(
settings
.
DATA_DIR
+
'course.xml'
)
def
toc_from_xml
(
coursefile
,
active_chapter
,
active_section
):
dom
=
parse
(
coursefile
)
course
=
dom
.
getElementsByTagName
(
'course'
)[
0
]
name
=
course
.
getAttribute
(
"name"
)
...
...
courseware/module_render.py
View file @
1dad5cae
...
...
@@ -142,7 +142,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
#print "X",s.xml, "Y",content_parser.module_xml(module, id_tag, id)
print
xml
=
content_parser
.
module_xml
(
module
,
id_tag
,
id
)
xml
=
content_parser
.
module_xml
(
content_parser
.
course_file
(
request
.
user
),
module
,
id_tag
,
id
)
instance
=
modx_modules
[
module
](
xml
,
s
.
module_id
,
...
...
courseware/profile.py
deleted
100644 → 0
View file @
9ac4ac8a
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
(
'/'
)
dom
=
parse
(
settings
.
DATA_DIR
+
'course.xml'
)
hw
=
[]
course
=
dom
.
getElementsByTagName
(
'course'
)[
0
]
chapters
=
course
.
getElementsByTagName
(
'chapter'
)
responses
=
StudentModule
.
objects
.
filter
(
student
=
request
.
user
)
for
c
in
chapters
:
for
s
in
c
.
getElementsByTagName
(
'section'
):
problems
=
s
.
getElementsByTagName
(
'problem'
)
scores
=
[]
if
len
(
problems
)
>
0
:
for
p
in
problems
:
id
=
p
.
getAttribute
(
'filename'
)
correct
=
0
for
response
in
responses
:
if
response
.
module_id
==
id
:
if
response
.
grade
!=
None
:
correct
=
response
.
grade
else
:
correct
=
0
total
=
capa_module
.
LoncapaModule
(
p
.
toxml
(),
"id"
)
.
max_score
()
# TODO: Add state. Not useful now, but maybe someday problems will have randomized max scores?
scores
.
append
((
int
(
correct
),
total
))
score
=
{
'course'
:
course
.
getAttribute
(
'name'
),
'section'
:
s
.
getAttribute
(
"name"
),
'chapter'
:
c
.
getAttribute
(
"name"
),
'scores'
:
scores
,
}
hw
.
append
(
score
)
user_info
=
UserProfile
.
objects
.
get
(
user
=
request
.
user
)
context
=
{
'name'
:
user_info
.
name
,
'username'
:
request
.
user
.
username
,
'location'
:
user_info
.
location
,
'language'
:
user_info
.
language
,
'email'
:
request
.
user
.
email
,
'homeworks'
:
hw
,
'csrf'
:
csrf
(
request
)[
'csrf_token'
]
}
return
render_to_response
(
'profile.html'
,
context
)
courseware/views.py
View file @
1dad5cae
...
...
@@ -39,7 +39,7 @@ def profile(request):
if
not
request
.
user
.
is_authenticated
():
return
redirect
(
'/'
)
dom
=
parse
(
settings
.
DATA_DIR
+
'course.xml'
)
dom
=
parse
(
content_parser
.
course_file
(
request
.
user
)
)
hw
=
[]
course
=
dom
.
getElementsByTagName
(
'course'
)[
0
]
chapters
=
course
.
getElementsByTagName
(
'chapter'
)
...
...
@@ -87,7 +87,7 @@ def render_accordion(request,course,chapter,section):
def
format_string
(
string
):
return
urllib
.
quote
(
string
.
replace
(
' '
,
'_'
))
toc
=
content_parser
.
toc_from_xml
(
chapter
,
section
)
toc
=
content_parser
.
toc_from_xml
(
c
ontent_parser
.
course_file
(
request
.
user
),
c
hapter
,
section
)
active_chapter
=
1
for
i
in
range
(
len
(
toc
)):
if
toc
[
i
][
'active'
]:
...
...
@@ -117,7 +117,8 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
if
course
!=
"6.002 Spring 2012"
:
return
redirect
(
'/'
)
dom
=
parse
(
settings
.
DATA_DIR
+
'course.xml'
)
cf
=
content_parser
.
course_file
(
request
.
user
)
dom
=
parse
(
cf
)
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
)
...
...
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