From dfc2a35442aebc316f06a6ea8e80d5b99a5775f6 Mon Sep 17 00:00:00 2001 From: Bridger Maxwell Date: Wed, 27 Jun 2012 18:31:39 -0400 Subject: [PATCH] First pass at putting dyanamic content from data on course about page. --- lms/djangoapps/courseware/content_parser.py | 16 +++++--- lms/djangoapps/courseware/courses.py | 38 +++++++++++++++++++ lms/djangoapps/courseware/views.py | 20 ++++++++++ lms/templates/accordion.html | 2 +- lms/templates/course.html | 7 +++- .../course_about.html} | 12 +++--- lms/urls.py | 4 +- 7 files changed, 82 insertions(+), 17 deletions(-) rename lms/templates/{course_info.html => portal/course_about.html} (96%) diff --git a/lms/djangoapps/courseware/content_parser.py b/lms/djangoapps/courseware/content_parser.py index eac163a5ce..1cd3a4be30 100644 --- a/lms/djangoapps/courseware/content_parser.py +++ b/lms/djangoapps/courseware/content_parser.py @@ -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 diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index 7299dff068..2475ce72e8 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -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 diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index b35c4ea5cb..e3b2c48797 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -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}) + diff --git a/lms/templates/accordion.html b/lms/templates/accordion.html index 7f67f784ad..dbeb077567 100644 --- a/lms/templates/accordion.html +++ b/lms/templates/accordion.html @@ -8,7 +8,7 @@