Commit bd115f3d by Matthew Mongeau

workarounds for get_about_section

parent 2a6a894c
import logging
from django.conf import settings
from fs.osfs import OSFS
from importlib import import_module
from lxml import etree
......@@ -128,7 +129,8 @@ class XMLModuleStore(ModuleStore):
"""
Returns a list of course descriptors
"""
return self.courses
# return self.courses
return settings.COURSES
def create_item(self, location):
raise NotImplementedError("XMLModuleStores are read-only")
......
......@@ -27,6 +27,31 @@ class Course(namedtuple('Course', _FIELDS)):
"""Course objects encapsulate general information about a given run of a
course. This includes things like name, grading policy, etc.
"""
@property
def id(self):
return "{0.institution},{0.number},{0.run_id}".format(self).replace(" ", "_")
def get_about_section(self, section):
if section == "university":
section = "institution"
if section in _FIELDS:
getattr(self, section)
else:
return section
@classmethod
def load_from_path(cls, course_path):
course_path = path(course_path) # convert it from string if necessary
try:
with open(course_path / "course_info.yaml") as course_info_file:
course_info = yaml.load(course_info_file)
summary = course_info['course']
summary.update(path=course_path, grader=None)
return cls(**summary)
except Exception as ex:
log.exception(ex)
raise CourseInfoLoadError("Could not read course info: {0}:{1}"
.format(type(ex).__name__, ex))
def load_courses(courses_path):
"""Given a directory of courses, returns a list of Course objects. For the
......
......@@ -54,7 +54,9 @@ def format_url_params(params):
def courses(request):
csrf_token = csrf(request)['csrf_token']
# TODO: Clean up how 'error' is done.
context = {'courses': modulestore().get_courses(),
# context = {'courses': modulestore().get_courses(),
# 'csrf': csrf_token}
context = {'courses': settings.COURSES,
'csrf': csrf_token}
return render_to_response("courses.html", context)
......@@ -252,8 +254,9 @@ def course_info(request, course_id):
csrf_token = csrf(request)['csrf_token']
try:
course_location = CourseDescriptor.id_to_location(course_id)
course = modulestore().get_item(course_location)
# course_location = CourseDescriptor.id_to_location(course_id)
# course = modulestore().get_item(course_location)
course = settings.COURSES_BY_ID[course_id]
except KeyError:
raise Http404("Course not found")
......
......@@ -491,8 +491,9 @@ def accept_name_change(request):
def course_info(request, course_id):
# This is the advertising page for a student to look at the course before signing up
csrf_token = csrf(request)['csrf_token']
course_loc = CourseDescriptor.id_to_location(course_id)
course = modulestore().get_item(course_loc)
# course_loc = CourseDescriptor.id_to_location(course_id)
# course = modulestore().get_item(course_loc)
course = settings.COURSES_BY_ID[course_id]
# TODO: Couse should be a model
return render_to_response('portal/course_about.html', {'csrf': csrf_token, 'course': course})
......
......@@ -64,6 +64,12 @@ sys.path.append(PROJECT_ROOT / 'lib')
sys.path.append(COMMON_ROOT / 'djangoapps')
sys.path.append(COMMON_ROOT / 'lib')
######### EDX dormsbee/portal changes #################
from courseware.courses import create_lookup_table, load_courses
COURSES = load_courses(ENV_ROOT / "data")
COURSES_BY_ID = create_lookup_table(COURSES)
#######################################################
################################## MITXWEB #####################################
# This is where we stick our compiled template files. Most of the app uses Mako
# templates
......
......@@ -11,7 +11,7 @@ from .common import *
from .logsettings import get_logger_config
DEBUG = True
TEMPLATE_DEBUG = False
TEMPLATE_DEBUG = True
LOGGING = get_logger_config(ENV_ROOT / "log",
logging_env="dev",
......
......@@ -2,8 +2,8 @@
<%!
from django.core.urlresolvers import reverse
%>
<%page args="course"/>
%for course in courses:
<article id="${course.id}"class="course">
<div class="inner-wrapper">
<header class="course-preview">
......@@ -20,158 +20,7 @@
<p class="dates"><span class="start">7/23/12</span> &rarr; <span class="end">12/15/12</span></p>
</div>
<div class="cover-image">
<img src="${static.url('images/courses/history.png')}">
</div>
<div class="desc">
<p>An advanced introduction to analog circuits.</p>
</div>
</section>
</div>
</article>
%endfor
<article id="${course.id}"class="course">
<div class="inner-wrapper">
<header class="course-preview">
<a href="${reverse('about_course', args=[course.id])}">
<hgroup>
<h2>${course.title}</h2>
</hgroup>
<div class="info-link">&#x2794;</div>
</a>
</header>
<section class="info">
<div class="meta-info">
<p class="university">${course.institution}</p>
<p class="dates"><span class="start">7/23/12</span> &rarr; <span class="end">12/15/12</span></p>
</div>
<div class="cover-image">
<img src="${static.url('images/courses/math.png')}">
</div>
<div class="desc">
<p>An advanced introduction to analog circuits.</p>
</div>
</section>
</div>
</article>
<article id="${course.id}"class="course">
<div class="inner-wrapper">
<header class="course-preview">
<a href="${reverse('about_course', args=[course.id])}">
<hgroup>
<h2>${course.title}</h2>
</hgroup>
<div class="info-link">&#x2794;</div>
</a>
</header>
<section class="info">
<div class="meta-info">
<p class="university">${course.institution}</p>
<p class="dates"><span class="start">7/23/12</span> &rarr; <span class="end">12/15/12</span></p>
</div>
<div class="cover-image">
<img src="${static.url('images/courses/python.png')}">
</div>
<div class="desc">
<p>An advanced introduction to analog circuits.</p>
</div>
</section>
</div>
</article>
<article id="${course.id}"class="course">
<div class="inner-wrapper">
<header class="course-preview">
<a href="${reverse('about_course', args=[course.id])}">
<hgroup>
<h2>${course.title}</h2>
</hgroup>
<div class="info-link">&#x2794;</div>
</a>
</header>
<section class="info">
<div class="meta-info">
<p class="university">${course.institution}</p>
<p class="dates"><span class="start">7/23/12</span> &rarr; <span class="end">12/15/12</span></p>
</div>
<div class="cover-image">
<img src="${static.url('images/courses/space1.jpg')}">
</div>
<div class="desc">
<p>An advanced introduction to analog circuits.</p>
</div>
</section>
</div>
</article>
<article id="${course.id}"class="course">
<div class="inner-wrapper">
<header class="course-preview">
<a href="${reverse('about_course', args=[course.id])}">
<hgroup>
<h2>${course.title}</h2>
</hgroup>
<div class="info-link">&#x2794;</div>
</a>
</header>
<section class="info">
<div class="meta-info">
<p class="university">${course.institution}</p>
<p class="dates"><span class="start">7/23/12</span> &rarr; <span class="end">12/15/12</span></p>
</div>
<div class="cover-image">
<img src="${static.url('images/courses/space2.jpg')}">
</div>
<div class="desc">
<p>An advanced introduction to analog circuits.</p>
</div>
</section>
</div>
</article>
<article id="${course.id}"class="course">
<div class="inner-wrapper">
<header class="course-preview">
<a href="${reverse('about_course', args=[course.id])}">
<hgroup>
<h2>${course.title}</h2>
</hgroup>
<div class="info-link">&#x2794;</div>
</a>
</header>
<section class="info">
<div class="meta-info">
<p class="university">${course.institution}</p>
<p class="dates"><span class="start">7/23/12</span> &rarr; <span class="end">12/15/12</span></p>
</div>
<div class="cover-image">
<img src="${static.url('images/courses/space4.jpg')}">
</div>
<div class="desc">
<p>An advanced introduction to analog circuits.</p>
</div>
</section>
</div>
</article>
<article id="${course.id}"class="course">
<div class="inner-wrapper">
<header class="course-preview">
<a href="${reverse('about_course', args=[course.id])}">
<hgroup>
<h2>${course.title}</h2>
</hgroup>
<div class="info-link">&#x2794;</div>
</a>
</header>
<section class="info">
<div class="meta-info">
<p class="university">${course.institution}</p>
<p class="dates"><span class="start">7/23/12</span> &rarr; <span class="end">12/15/12</span></p>
</div>
<div class="cover-image">
<img src="${static.url('images/courses/space3.jpg')}">
<img src="${static.url('images/courses/circuits.jpeg')}">
</div>
<div class="desc">
<p>An advanced introduction to analog circuits.</p>
......
......@@ -69,15 +69,24 @@ if settings.COURSEWARE_ENABLED:
# Multicourse related:
url(r'^courses/?$', 'courseware.views.courses', name="courses"),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/info$', 'courseware.views.course_info', name="info"),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/book$', 'staticbook.views.index', name="book"),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/enroll$', 'student.views.enroll', name="enroll"),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/courseware/?$', 'courseware.views.index', name="courseware"),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/courseware/(?P<chapter>[^/]*)/(?P<section>[^/]*)/$', 'courseware.views.index', name="courseware_section"),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/profile$', 'courseware.views.profile', name="profile"),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/profile/(?P<student_id>[^/]*)/$', 'courseware.views.profile'),
url(r'^courses/(?P<course_id>[^/]*)/info$', 'courseware.views.course_info', name="info"),
url(r'^courses/(?P<course_id>[^/]*)/book$', 'staticbook.views.index', name="book"),
url(r'^courses/(?P<course_id>[^/]*)/enroll$', 'student.views.enroll', name="enroll"),
url(r'^courses/(?P<course_id>[^/]*)/courseware/?$', 'courseware.views.index', name="courseware"),
url(r'^courses/(?P<course_id>[^/]*)/courseware/(?P<chapter>[^/]*)/(?P<section>[^/]*)/$', 'courseware.views.index', name="courseware_section"),
url(r'^courses/(?P<course_id>[^/]*)/profile$', 'courseware.views.profile', name="profile"),
url(r'^courses/(?P<course_id>[^/]*)/profile/(?P<student_id>[^/]*)/$', 'courseware.views.profile'),
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/about$', 'courseware.views.course_info', name="about_course"),
# url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/info$', 'courseware.views.course_info', name="info"),
# url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/book$', 'staticbook.views.index', name="book"),
# url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/enroll$', 'student.views.enroll', name="enroll"),
# url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/courseware/?$', 'courseware.views.index', name="courseware"),
# url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/courseware/(?P<chapter>[^/]*)/(?P<section>[^/]*)/$', 'courseware.views.index', name="courseware_section"),
# url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/profile$', 'courseware.views.profile', name="profile"),
# url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/profile/(?P<student_id>[^/]*)/$', 'courseware.views.profile'),
url(r'^courses/(?P<course_id>[^/]*)/about$', 'student.views.course_info', name="about_course"),
# url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/])/about$', 'courseware.views.course_info', name="about_course"),
)
if settings.ENABLE_MULTICOURSE:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment