Exemplo n.º 1
0
def _render_course_outline_to_html(handler, course):
    """Renders course outline to HTML."""

    units = []
    for unit in course.get_units():
        if course.get_parent_unit(unit.unit_id):
            continue  # Will be rendered as part of containing element.
        if unit.type == verify.UNIT_TYPE_ASSESSMENT:
            units.append(_render_assessment_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_LINK:
            units.append(_render_link_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_UNIT:
            units.append(_render_unit_outline(handler, course, unit))
        elif unit.type == verify.UNIT_TYPE_CUSTOM:
            units.append(_render_custom_unit_outline(handler, course, unit))
        else:
            raise Exception('Unknown unit type: %s.' % unit.type)

    is_course_availability_editable = permissions.can_edit_property(
        handler.app_context, constants.SCOPE_COURSE_SETTINGS,
        'course/course:now_available')
    any_course_setting_viewable = permissions.can_view(
        handler.app_context, constants.SCOPE_COURSE_SETTINGS)
    template_values = {
        'course': {
            'title': course.title,
            'can_add_or_remove': roles.Roles.is_course_admin(
                handler.app_context),
            'can_reorder': roles.Roles.is_user_allowed(
                handler.app_context, custom_module,
                constants.COURSE_OUTLINE_REORDER_PERMISSION),
            'settings_viewable': any_course_setting_viewable,
            'availability': {
                'url': handler.get_action_url('course_availability'),
                'xsrf_token': handler.create_xsrf_token('course_availability'),
                'param': not handler.app_context.now_available,
                'now_available': handler.app_context.now_available,
                'is_editable': is_course_availability_editable,
            }
        },
        'units': units,
        'add_lesson_xsrf_token': handler.create_xsrf_token('add_lesson'),
        'unit_lesson_title_xsrf_token': handler.create_xsrf_token(
            unit_lesson_editor.UnitLessonTitleRESTHandler.XSRF_TOKEN),
        'unit_title_template': resources_display.get_unit_title_template(
            course.app_context),
        'extra_info_title': ', '.join(COURSE_OUTLINE_EXTRA_INFO_TITLES)
    }
    for item_type in unit_lesson_editor.UnitLessonEditor.CAN_EDIT_DRAFT:
        action_name = '%s_%s' % (
            unit_lesson_editor.UnitLessonEditor.ACTION_POST_SET_DRAFT_STATUS,
            item_type)
        token_name = 'status_xsrf_token_%s' % item_type
        template_values[token_name] = handler.create_xsrf_token(action_name)

    return jinja2.Markup(
        handler.get_template(
            'course_outline.html', [os.path.dirname(__file__)]
            ).render(template_values))
Exemplo n.º 2
0
def _render_course_outline_to_html(handler, course):
    """Renders course outline to HTML."""

    units = []
    for unit in course.get_units():
        if course.get_parent_unit(unit.unit_id):
            continue  # Will be rendered as part of containing element.
        if unit.type == verify.UNIT_TYPE_ASSESSMENT:
            units.append(_render_assessment_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_LINK:
            units.append(_render_link_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_UNIT:
            units.append(_render_unit_outline(handler, course, unit))
        elif unit.type == verify.UNIT_TYPE_CUSTOM:
            units.append(_render_custom_unit_outline(handler, course, unit))
        else:
            raise Exception('Unknown unit type: %s.' % unit.type)

    is_course_availability_editable = permissions.can_edit_property(
        handler.app_context, constants.SCOPE_COURSE_SETTINGS,
        'course/course:now_available')
    any_course_setting_viewable = permissions.can_view(
        handler.app_context, constants.SCOPE_COURSE_SETTINGS)
    template_values = {
        'course': {
            'title':
            course.title,
            'can_add_or_remove':
            roles.Roles.is_course_admin(handler.app_context),
            'can_reorder':
            roles.Roles.is_user_allowed(
                handler.app_context, custom_module,
                constants.COURSE_OUTLINE_REORDER_PERMISSION),
            'settings_viewable':
            any_course_setting_viewable,
        },
        'units':
        units,
        'add_lesson_xsrf_token':
        handler.create_xsrf_token('add_lesson'),
        'unit_lesson_title_xsrf_token':
        handler.create_xsrf_token(
            unit_lesson_editor.UnitLessonTitleRESTHandler.XSRF_TOKEN),
        'unit_title_template':
        resources_display.get_unit_title_template(course.app_context),
        'extra_info_title':
        ', '.join(COURSE_OUTLINE_EXTRA_INFO_TITLES)
    }

    return jinja2.Markup(
        handler.get_template(
            'course_outline.html',
            [os.path.dirname(__file__)]).render(template_values))
Exemplo n.º 3
0
def _render_course_outline_to_html(handler, course):
    """Renders course outline to HTML."""

    units = []
    for unit in course.get_units():
        if course.get_parent_unit(unit.unit_id):
            continue  # Will be rendered as part of containing element.
        if unit.type == verify.UNIT_TYPE_ASSESSMENT:
            units.append(_render_assessment_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_LINK:
            units.append(_render_link_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_UNIT:
            units.append(_render_unit_outline(handler, course, unit))
        elif unit.type == verify.UNIT_TYPE_CUSTOM:
            units.append(_render_custom_unit_outline(handler, course, unit))
        else:
            raise Exception('Unknown unit type: %s.' % unit.type)

    template_values = {
        'course': {
            'title': course.title,
            'is_editable': handler.app_context.is_editable_fs(),
            'availability': {
                'url':
                handler.get_action_url('course_availability'),
                'xsrf_token':
                handler.create_xsrf_token('course_availability'),
                'param':
                not handler.app_context.now_available,
                'class': ('row-hover icon md md-lock-open'
                          if handler.app_context.now_available else
                          'row-hover icon md md-lock')
            }
        },
        'units':
        units,
        'add_lesson_xsrf_token':
        handler.create_xsrf_token('add_lesson'),
        'status_xsrf_token':
        handler.create_xsrf_token('set_draft_status'),
        'unit_lesson_title_xsrf_token':
        handler.create_xsrf_token(
            unit_lesson_editor.UnitLessonTitleRESTHandler.XSRF_TOKEN),
        'unit_title_template':
        resources_display.get_unit_title_template(course.app_context),
        'extra_info_title':
        ', '.join(COURSE_OUTLINE_EXTRA_INFO_TITLES)
    }
    return jinja2.Markup(
        handler.get_template(
            'course_outline.html',
            [os.path.dirname(__file__)]).render(template_values))
Exemplo n.º 4
0
def _render_course_outline_to_html(handler, course):
    """Renders course outline to HTML."""

    units = []
    for unit in course.get_units():
        if course.get_parent_unit(unit.unit_id):
            continue  # Will be rendered as part of containing element.
        if unit.type == verify.UNIT_TYPE_ASSESSMENT:
            units.append(_render_assessment_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_LINK:
            units.append(_render_link_outline(handler, unit))
        elif unit.type == verify.UNIT_TYPE_UNIT:
            units.append(_render_unit_outline(handler, course, unit))
        elif unit.type == verify.UNIT_TYPE_CUSTOM:
            units.append(_render_custom_unit_outline(handler, course, unit))
        else:
            raise Exception('Unknown unit type: %s.' % unit.type)

    template_values = {
        'course': {
            'title': course.title,
            'is_editable': handler.app_context.is_editable_fs(),
            'availability': {
                'url': handler.get_action_url('course_availability'),
                'xsrf_token': handler.create_xsrf_token('course_availability'),
                'param': not handler.app_context.now_available,
                'class': (
                    'row-hover icon md md-lock-open'
                    if handler.app_context.now_available else
                    'row-hover icon md md-lock')
            }
        },
        'units': units,
        'add_lesson_xsrf_token': handler.create_xsrf_token('add_lesson'),
        'status_xsrf_token': handler.create_xsrf_token('set_draft_status'),
        'unit_lesson_title_xsrf_token': handler.create_xsrf_token(
            unit_lesson_editor.UnitLessonTitleRESTHandler.XSRF_TOKEN),
        'unit_title_template': resources_display.get_unit_title_template(
            course.app_context),
        'extra_info_title': ', '.join(COURSE_OUTLINE_EXTRA_INFO_TITLES)
    }
    return jinja2.Markup(
        handler.get_template(
            'course_outline.html', [os.path.dirname(__file__)]
            ).render(template_values))