Commit dfc2a354 by Bridger Maxwell

First pass at putting dyanamic content from data on course about page.

parent 38425e9b
......@@ -138,12 +138,16 @@ def user_groups(user):
# return [u.name for u in UserTestGroup.objects.raw("select * from auth_user, student_usertestgroup, student_usertestgroup_users where auth_user.id = student_usertestgroup_users.user_id and student_usertestgroup_users.usertestgroup_id = student_usertestgroup.id and auth_user.id = %s", [user.id])]
def replace_custom_tags(course, tree):
tags = os.listdir(course.path+'/custom_tags')
for tag in tags:
for element in tree.iter(tag):
element.tag = 'customtag'
impl = etree.SubElement(element, 'impl')
impl.text = tag
try:
tags = os.listdir(course.path+'/custom_tags')
for tag in tags:
for element in tree.iter(tag):
element.tag = 'customtag'
impl = etree.SubElement(element, 'impl')
impl.text = tag
except os.error:
# The directory must not exist. This is okay, as it is optional. If it is empty, git has trouble tracking it
pass
def course_xml_process(course, tree):
''' Do basic pre-processing of an XML tree. Assign IDs to all
......
......@@ -44,6 +44,44 @@ class Course(namedtuple('Course', _FIELDS)):
log.exception(ex)
raise CourseInfoLoadError("Could not read course info: {0}:{1}"
.format(type(ex).__name__, ex))
def get_about_section(self, section_key):
"""
This returns the snippet of html to be rendered on the course about page, given the key for the section.
Valid keys:
- title
- university
- number
- short_description
- description
- key_dates (includes start, end, exams, etc)
- video
- course_staff_short
- course_staff_extended
- requirements
- syllabus
- textbook
- faq
- more_info
"""
if section_key in ['short_description', 'description', 'key_dates', 'video', 'course_staff_short', 'course_staff_extended',
'requirements', 'syllabus', 'textbook', 'faq', 'more_info']:
try:
with open(self.path / "about" / section_key + ".html") as htmlFile:
return htmlFile.read()
except IOError:
return "! About section missing !"
elif section_key == "title":
return self.title
elif section_key == "university":
return self.institution
elif section_key == "number":
return self.number
raise KeyError("Invalid about key " + str(section_key))
def load_courses(courses_path):
"""Given a directory of courses, returns a list of Course objects. For the
......
......@@ -366,3 +366,23 @@ def jump_to(request, probname=None):
return index(request,
course=coursename, chapter=chapter,
section=section, position=position)
@ensure_csrf_cookie
def course_info(request):
csrf_token = csrf(request)['csrf_token']
# TODO: Couse should be a model
return render_to_response('portal/course_info.html', {'csrf': csrf_token })
@ensure_csrf_cookie
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']
try:
course = settings.COURSES_BY_ID[course_id]
except KeyError:
raise Http404("Course not found")
return render_to_response('portal/course_about.html', {'csrf': csrf_token, 'course' : course})
......@@ -8,7 +8,7 @@
<ul>
% for section in chapter['sections']:
<li${' class="active"' if 'active' in section and section['active'] else ''}>
<a href="${ MITX_ROOT_URL}${reverse('courseware_section', args=[course_id] + format_url_params([chapter['name'], section['name']]))}">
<a href="${reverse('courseware_section', args=[course_id] + format_url_params([chapter['name'], section['name']]))}">
<p>${section['name']}
<span class="subtitle">
${section['format']} ${"due " + section['due'] if 'due' in section and section['due'] != '' else ''}
......
<%namespace name='static' file='static_content.html'/>
<%!
from django.core.urlresolvers import reverse
%>
%for course in courses:
<article class="course">
<div class="inner-wrapper">
<header class="course-preview">
<a href="courses/${course.id}/info">
<a href="${reverse('about_course', args=[course.id])}">
<hgroup>
<h2>${course.title}</h2>
<p>${course.institution}</p>
......@@ -21,7 +24,7 @@
<img src="${static.url('images/history.png')}">
</div>
<div class="desc">
<p>An advanced intorduction to analog circuits.</p>
<p>An advanced introduction to analog circuits.</p>
</div>
</section>
</div>
......
<%namespace name='static' file='static_content.html'/>
<%namespace name='static' file='../static_content.html'/>
<%block name="js_extra">
<script src="${static.url('js/course_info.js')}"></script>
</%block>
<%inherit file="main.html" />
<%inherit file="../main.html" />
<section class="container">
<section class="course-info">
<header>
<img src="${static.url('images/harvard_cropped.png')}" />
<h2>18th Century History <span class="course-number">(HIS-223)</span></h3>
<h3>Harvard University</h3>
<h2>${course.get_about_section("title")} <span class="course-number">(${course.get_about_section("number")})</span></h3>
<h3>${course.get_about_section("university")}</h3>
<div class="course-abstract">
<p>This course will examine the ways in which the world has grown more integrated yet more divided over the past 300 years.</p>
<p>${course.get_about_section("short_description")}</p>
</div>
<a class="button sign-up" href="#">Sign up</a>
</header>
......@@ -120,7 +120,7 @@
<p>The course will consist of 24 lectures, each lasting 50 minutes. There will be regular assignments consisting of map tests and short essays.</p>
</li>
<li>Are there any prerequisites?
<p>No - anyone and everyone is welcome to take this class.</p>
<p>No - anyone and everyone is welcome to take this course.</p>
</li>
<li>What textbook should I buy?
<p>Although the lectures are designed to be self-contained, we recommend (but do not require) that students refer to the book Worlds Together, Worlds Apart: A History of the World: From 1000 CE to the Present (W W Norton, 3rd edition) -- Volume II, which was written specifically for this course.</p>
......
......@@ -15,7 +15,6 @@ urlpatterns = ('',
url(r'^about$', 'student.views.about', name="about"),
url(r'^jobs$', 'student.views.jobs', name="jobs"),
url(r'^dashboard$', 'student.views.dashboard'),
url(r'^course_info$', 'student.views.course_info'),
url(r'^change_email$', 'student.views.change_email_request'),
url(r'^email_confirm/(?P<key>[^/]*)$', 'student.views.confirm_email_change'),
url(r'^change_name$', 'student.views.change_name_request'),
......@@ -80,7 +79,8 @@ if settings.COURSEWARE_ENABLED:
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"),
)
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