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
2d2a16dd
Commit
2d2a16dd
authored
Jun 14, 2012
by
Calen Pennington
Committed by
Matthew Mongeau
Jun 21, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Successfully read course children out of mongodb
parent
8dc28549
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
26 deletions
+109
-26
cms/djangoapps/contentstore/management/commands/import.py
+14
-15
cms/djangoapps/contentstore/views.py
+1
-4
cms/lib/keystore/__init__.py
+34
-0
cms/lib/keystore/exceptions.py
+4
-0
cms/lib/keystore/mongo.py
+56
-7
No files found.
cms/djangoapps/contentstore/management/commands/import.py
View file @
2d2a16dd
...
...
@@ -6,11 +6,13 @@
#import mitxmako.middleware
#from courseware import content_parser
#from django.contrib.auth.models import User
import
os.path
from
StringIO
import
StringIO
from
mako.template
import
Template
from
mako.lookup
import
TemplateLookup
from
django.core.management.base
import
BaseCommand
from
contentstore.models
import
create_item
,
update_item
,
update_children
from
keystore.django
import
keystore
from
lxml
import
etree
...
...
@@ -20,16 +22,15 @@ class Command(BaseCommand):
def
handle
(
self
,
*
args
,
**
options
):
print
args
data_dir
=
args
[
0
]
course_file
=
'course.xml'
parser
=
etree
.
XMLParser
(
remove_comments
=
True
)
lookup
=
TemplateLookup
(
directories
=
[
data_dir
])
template
=
lookup
.
get_template
(
"course.xml"
)
course_string
=
template
.
render
(
groups
=
[])
course
=
etree
.
XML
(
course_string
,
parser
=
parser
)
course
=
etree
.
parse
(
StringIO
(
course_string
)
,
parser
=
parser
)
elements
=
course
.
xpath
(
"//*"
)
elements
=
list
(
course
.
iter
()
)
tag_to_category
=
{
# Inside HTML ==> Skip these
# Custom tags
...
...
@@ -39,11 +40,11 @@ class Command(BaseCommand):
'image'
:
'Custom'
,
'discuss'
:
'Custom'
,
# Simple lists
'chapter'
:
'
Sequence
'
,
'course'
:
'
Sequenc
e'
,
'sequential'
:
'Sequence'
,
'vertical'
:
'
Sequence
'
,
'section'
:
'Se
quence
'
,
'chapter'
:
'
Chapter
'
,
'course'
:
'
Cours
e'
,
'sequential'
:
'
Lecture
Sequence'
,
'vertical'
:
'
ProblemSet
'
,
'section'
:
'Se
ction
'
,
# True types
'video'
:
'VideoSegment'
,
'html'
:
'HTML'
,
...
...
@@ -114,7 +115,7 @@ class Command(BaseCommand):
results
[
e
.
attrib
[
'url'
]]
=
{
'data'
:{
'text'
:
text
}}
def
handle_problem
(
e
):
data
=
open
(
data_dir
+
'problems/'
+
e
.
attrib
[
'filename'
]
+
'.xml'
)
.
read
()
data
=
open
(
os
.
path
.
join
(
data_dir
,
'problems'
,
e
.
attrib
[
'filename'
]
+
'.xml'
)
)
.
read
()
results
[
e
.
attrib
[
'url'
]]
=
{
'data'
:{
'statement'
:
data
}}
element_actions
=
{
# Inside HTML ==> Skip these
...
...
@@ -149,10 +150,8 @@ class Command(BaseCommand):
for
k
in
results
:
print
k
create_item
(
k
,
'Piotr Mitros'
)
keystore
.
create_item
(
k
,
'Piotr Mitros'
)
if
'data'
in
results
[
k
]:
update_item
(
k
,
results
[
k
][
'data'
])
keystore
.
update_item
(
k
,
results
[
k
][
'data'
])
if
'children'
in
results
[
k
]:
update_children
(
k
,
results
[
k
][
'children'
])
keystore
.
update_children
(
k
,
results
[
k
][
'children'
])
cms/djangoapps/contentstore/views.py
View file @
2d2a16dd
from
mitxmako.shortcuts
import
render_to_response
from
keystore
import
Location
from
keystore.django
import
keystore
from
django.contrib.auth.decorators
import
login_required
@login_required
def
calendar
(
request
,
org
,
course
):
weeks
=
keystore
.
get_children_for_item
(
Location
([
'i4x'
,
org
,
course
,
'Course'
,
'course'
])
)
weeks
=
keystore
.
get_children_for_item
([
'i4x'
,
org
,
course
,
'Course'
,
None
])
return
render_to_response
(
'calendar.html'
,
{
'weeks'
:
weeks
})
...
...
cms/lib/keystore/__init__.py
View file @
2d2a16dd
...
...
@@ -60,6 +60,40 @@ class KeyStore(object):
with the specified location.
If no object is found at that location, raises keystore.exceptions.ItemNotFoundError
Searches for all matches of a partially specifed location, but raises an
keystore.exceptions.InsufficientSpecificationError if more
than a single object matches the query.
location: Something that can be passed to Location
"""
raise
NotImplementedError
def
create_item
(
self
,
location
,
editor
):
"""
Create an empty item at the specified location with the supplied editor
location: Something that can be passed to Location
"""
raise
NotImplementedError
def
update_item
(
self
,
location
,
data
):
"""
Set the data in the item specified by the location to
data
location: Something that can be passed to Location
data: A nested dictionary of problem data
"""
raise
NotImplementedError
def
update_children
(
self
,
location
,
children
):
"""
Set the children for the item specified by the location to
data
location: Something that can be passed to Location
children: A list of child item identifiers
"""
raise
NotImplementedError
...
...
cms/lib/keystore/exceptions.py
View file @
2d2a16dd
...
...
@@ -5,3 +5,7 @@ Exceptions thrown by KeyStore objects
class
ItemNotFoundError
(
Exception
):
pass
class
InsufficientSpecificationError
(
Exception
):
pass
cms/lib/keystore/mongo.py
View file @
2d2a16dd
import
pymongo
from
.
import
KeyStore
from
.exceptions
import
ItemNotFoundError
from
.
import
KeyStore
,
Location
from
.exceptions
import
ItemNotFoundError
,
InsufficientSpecificationError
class
MongoKeyStore
(
KeyStore
):
...
...
@@ -12,15 +12,64 @@ class MongoKeyStore(KeyStore):
host
=
host
,
port
=
port
)[
db
][
collection
]
# Force mongo to report errors, at the expense of performance
self
.
collection
.
safe
=
True
def
get_children_for_item
(
self
,
location
):
item
=
self
.
collection
.
find_one
(
{
'location'
:
location
.
dict
()},
query
=
dict
(
(
'location.{key}'
.
format
(
key
=
key
),
val
)
for
(
key
,
val
)
in
Location
(
location
)
.
dict
()
.
items
()
if
val
is
not
None
)
items
=
self
.
collection
.
find
(
query
,
fields
=
{
'children'
:
True
},
sort
=
[(
'revision'
,
pymongo
.
ASCENDING
)],
limit
=
1
,
)
if
items
.
count
()
>
1
:
raise
InsufficientSpecificationError
(
location
)
if
items
.
count
()
==
0
:
raise
ItemNotFoundError
(
location
)
return
items
[
0
][
'children'
]
def
create_item
(
self
,
location
,
editor
):
"""
Create an empty item at the specified location with the supplied editor
location: Something that can be passed to Location
"""
self
.
collection
.
insert
({
'location'
:
Location
(
location
)
.
dict
(),
'editor'
:
editor
})
if
item
is
None
:
raise
ItemNotFoundError
()
def
update_item
(
self
,
location
,
data
):
"""
Set the data in the item specified by the location to
data
return
item
[
'children'
]
location: Something that can be passed to Location
data: A nested dictionary of problem data
"""
self
.
collection
.
update
(
{
'location'
:
Location
(
location
)
.
dict
()},
{
'$set'
:
{
'data'
:
data
}}
)
def
update_children
(
self
,
location
,
children
):
"""
Set the children for the item specified by the location to
data
location: Something that can be passed to Location
children: A list of child item identifiers
"""
self
.
collection
.
update
(
{
'location'
:
Location
(
location
)
.
dict
()},
{
'$set'
:
{
'children'
:
children
}}
)
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