コード例 #1
0
def get_course_info_section(request, course, section_key):
    """
    This returns the snippet of html to be rendered on the course info page,
    given the key for the section.

    Valid keys:
    - handouts
    - guest_handouts
    - updates
    - guest_updates
    """

    loc = Location(course.location.tag, course.location.org,
                   course.location.course, 'course_info', section_key)

    # Use an empty cache
    model_data_cache = ModelDataCache([], course.id, request.user)
    info_module = get_module(request.user,
                             request,
                             loc,
                             model_data_cache,
                             course.id,
                             wrap_xmodule_display=False,
                             static_asset_path=course.lms.static_asset_path)

    html = ''

    if info_module is not None:
        html = info_module.runtime.render(info_module, None,
                                          'student_view').content

    return html
コード例 #2
0
 def setUp(self):
     self.desc_md = {}
     self.user = UserFactory.create(username='******')
     self.mdc = ModelDataCache(
         [mock_descriptor([mock_field(Scope.user_state, 'a_field')])],
         course_id, self.user)
     self.kvs = LmsKeyValueStore(self.desc_md, self.mdc)
コード例 #3
0
 def setUp(self):
     self.desc_md = {}
     student_module = StudentModuleFactory(
         state=json.dumps({'a_field': 'a_value'}))
     self.user = student_module.student
     self.mdc = ModelDataCache(
         [mock_descriptor([mock_field(Scope.user_state, 'a_field')])],
         course_id, self.user)
     self.kvs = LmsKeyValueStore(self.desc_md, self.mdc)
コード例 #4
0
ファイル: test_model_data.py プロジェクト: samH99/LexisNexis
 def setUp(self):
     field_storage = self.factory.create()
     if hasattr(field_storage, 'student'):
         self.user = field_storage.student
     else:
         self.user = UserFactory.create()
     self.desc_md = {}
     self.mdc = ModelDataCache([mock_descriptor([mock_field(self.scope, 'existing_field')])], course_id, self.user)
     self.kvs = LmsKeyValueStore(self.desc_md, self.mdc)
コード例 #5
0
def get_course_about_section(course, section_key):
    """
    This returns the snippet of html to be rendered on the course about page,
    given the key for the section.

    Valid keys:
    - overview
    - 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
    - ocw_links
    """

    # Many of these are stored as html files instead of some semantic
    # markup. This can change without effecting this interface when we find a
    # good format for defining so many snippets of text/html.

    # TODO: Remove number, instructors from this list
    if section_key in [
            'short_description', 'description', 'key_dates', 'video',
            'course_staff_short', 'course_staff_extended', 'requirements',
            'syllabus', 'textbook', 'faq', 'more_info', 'number',
            'instructors', 'overview', 'effort', 'end_date', 'prerequisites',
            'ocw_links'
    ]:

        try:

            request = get_request_for_thread()

            loc = course.location._replace(category='about', name=section_key)

            # Use an empty cache
            model_data_cache = ModelDataCache([], course.id, request.user)
            about_module = get_module(
                request.user,
                request,
                loc,
                model_data_cache,
                course.id,
                not_found_ok=True,
                wrap_xmodule_display=False,
                static_asset_path=course.lms.static_asset_path)

            html = ''

            if about_module is not None:
                html = about_module.runtime.render(about_module, None,
                                                   'student_view').content

            return html

        except ItemNotFoundError:
            log.warning("Missing about section {key} in course {url}".format(
                key=section_key, url=course.location.url()))
            return None
    elif section_key == "title":
        return course.display_name_with_default
    elif section_key == "university":
        return course.display_org_with_default
    elif section_key == "number":
        return course.display_number_with_default

    raise KeyError("Invalid about key " + str(section_key))