Read week headings from mongodb
This commit is contained in:
committed by
Matthew Mongeau
parent
31871a0548
commit
bb2910fce5
@@ -82,7 +82,7 @@ class Command(BaseCommand):
|
||||
def handle_list(e):
|
||||
if e.attrib.get("class", None) == "tutorials":
|
||||
return
|
||||
children = [{'url':le.attrib['url']} for le in e.getchildren()]
|
||||
children = [le.attrib['url'] for le in e.getchildren()]
|
||||
results[e.attrib['url']] = {'children':children}
|
||||
|
||||
def handle_video(e):
|
||||
|
||||
@@ -3,11 +3,10 @@ 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(['i4x', org, course, 'Course', None])
|
||||
return render_to_response('calendar.html', {'weeks': weeks})
|
||||
|
||||
|
||||
def index(request):
|
||||
return render_to_response('index.html', {})
|
||||
# FIXME (cpennington): These need to be read in from the active user
|
||||
org = 'mit.edu'
|
||||
course = '6002xs12'
|
||||
course = keystore.get_item(['i4x', org, course, 'Course', None])
|
||||
weeks = course.get_children()
|
||||
return render_to_response('index.html', {'weeks': weeks})
|
||||
|
||||
@@ -37,7 +37,7 @@ class Location(object):
|
||||
self.update(location.list())
|
||||
|
||||
def url(self):
|
||||
return "i4x://{org}/{course}/{category}/{name}".format(**self.dict())
|
||||
return "{tag}://{org}/{course}/{category}/{name}".format(**self.dict())
|
||||
|
||||
def list(self):
|
||||
return [self.tag, self.org, self.course, self.category, self.name]
|
||||
@@ -54,10 +54,9 @@ class Location(object):
|
||||
|
||||
|
||||
class KeyStore(object):
|
||||
def get_children_for_item(self, location):
|
||||
def get_item(self, location):
|
||||
"""
|
||||
Returns the children for the most recent revision of the object
|
||||
with the specified location.
|
||||
Returns an XModuleDescriptor instance for the item at location
|
||||
|
||||
If no object is found at that location, raises keystore.exceptions.ItemNotFoundError
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import pymongo
|
||||
from . import KeyStore, Location
|
||||
from .exceptions import ItemNotFoundError, InsufficientSpecificationError
|
||||
from xmodule.x_module import XModuleDescriptor
|
||||
|
||||
|
||||
class MongoKeyStore(KeyStore):
|
||||
@@ -12,11 +13,22 @@ 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):
|
||||
def get_item(self, location):
|
||||
"""
|
||||
Returns an XModuleDescriptor instance for the item at 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
|
||||
"""
|
||||
query = dict(
|
||||
('location.{key}'.format(key=key), val)
|
||||
for (key, val)
|
||||
@@ -25,7 +37,6 @@ class MongoKeyStore(KeyStore):
|
||||
)
|
||||
items = self.collection.find(
|
||||
query,
|
||||
fields={'children': True},
|
||||
sort=[('revision', pymongo.ASCENDING)],
|
||||
limit=1,
|
||||
)
|
||||
@@ -35,7 +46,7 @@ class MongoKeyStore(KeyStore):
|
||||
if items.count() == 0:
|
||||
raise ItemNotFoundError(location)
|
||||
|
||||
return items[0]['children']
|
||||
return XModuleDescriptor.load_from_json(items[0], self.get_item)
|
||||
|
||||
def create_item(self, location, editor):
|
||||
"""
|
||||
|
||||
@@ -35,9 +35,10 @@
|
||||
</header>
|
||||
|
||||
<ol>
|
||||
% for week in weeks:
|
||||
<li>
|
||||
<header>
|
||||
<h1><a href="#">Week 1</a></h1>
|
||||
<h1><a href="#">${week.name}</a></h1>
|
||||
<ul>
|
||||
<li class="goal editable"><strong>Goal title:</strong> This is a goal that will be in the header of the week</li>
|
||||
<li class="goal editable"><strong>Goal title two:</strong> This is another goal for this week so that students have two things to learn</li>
|
||||
@@ -64,125 +65,7 @@
|
||||
<%include file="module-dropdown.html"/>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<header>
|
||||
<h1><a href="#">Week 2</a></h1>
|
||||
<ul>
|
||||
<li class="goal editable"><strong>Another title</strong> This is the goal for the week</li>
|
||||
</ul>
|
||||
</header>
|
||||
|
||||
<ul>
|
||||
<li class="seq">
|
||||
<a href="#" class="sequence-edit">Lecture Sequence</a>
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</li>
|
||||
<li class="seq">
|
||||
<a href="#" class="sequence-edit">Lecture Sequence
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</a></li>
|
||||
<li class="lab">
|
||||
<a href="#" class="lab-edit">Lab</a>
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</li>
|
||||
<li class="hw">
|
||||
<a href="#">Homework</a>
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</li>
|
||||
<%include file="module-dropdown.html"/>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<header>
|
||||
<h1><a href="#">Week 3</a></h1>
|
||||
<ul>
|
||||
<li class="goal editable"><strong>Another title</strong> This is the goal for the week</li>
|
||||
</ul>
|
||||
</header>
|
||||
|
||||
<ul>
|
||||
<li class="lab">
|
||||
<a href="#" class="lab-edit">Lab</a>
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</li>
|
||||
<li class="lab">
|
||||
<a href="#" class="lab-edit">Lab</a>
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</li>
|
||||
<li class="hw">
|
||||
<a href="#">Homework</a>
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</li>
|
||||
|
||||
<%include file="module-dropdown.html"/>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<header>
|
||||
<h1><a href="#">Week 4</a></h1>
|
||||
<ul>
|
||||
<li class="goal editable"><strong>Another title</strong> This is the goal for the week</li>
|
||||
<li class="goal editable"><strong>Goal title two:</strong> This is another fgoal for this week so that students have two things to learn</li>
|
||||
</ul>
|
||||
</header>
|
||||
|
||||
<ul>
|
||||
<li class="seq">
|
||||
<a href="#" class="sequence-edit">Lecture Sequence</a>
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</li>
|
||||
<li class="lab">
|
||||
<a href="#" class="lab-edit">Lab</a>
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</li>
|
||||
<li class="hw">
|
||||
<a href="#">Homework</a>
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</li>
|
||||
<li class="hw">
|
||||
<a href="#">Homework</a>
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</li>
|
||||
<%include file="module-dropdown.html"/>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<header>
|
||||
<h1><a>Week 5</a></h1>
|
||||
<ul>
|
||||
<li class="goal editable">Please create a learning goal for this week</li>
|
||||
</ul>
|
||||
</header>
|
||||
|
||||
<ul>
|
||||
<%include file="module-dropdown.html"/>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<header>
|
||||
<h1><a>Week 6</a></h1>
|
||||
<ul>
|
||||
<li class="goal editable">Please create a learning goal for this week</li>
|
||||
</ul>
|
||||
</header>
|
||||
|
||||
<ul>
|
||||
<%include file="module-dropdown.html"/>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<header>
|
||||
<h1><a>Week 7</a></h1>
|
||||
<ul>
|
||||
<li class="goal editable">Please create a learning goal for this week</li>
|
||||
</ul>
|
||||
</header>
|
||||
|
||||
<ul>
|
||||
<%include file="module-dropdown.html"/>
|
||||
</ul>
|
||||
</li>
|
||||
%endfor
|
||||
<li>
|
||||
<header>
|
||||
<h1>Course Scratch Pad</h1>
|
||||
|
||||
Reference in New Issue
Block a user