예제 #1
0
파일: component.py 프로젝트: saadow123/1
def container_handler(request, usage_key_string):
    """
    The restful handler for container xblock requests.

    GET
        html: returns the HTML page for editing a container
        json: not currently supported
    """
    if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):

        try:
            usage_key = UsageKey.from_string(usage_key_string)
        except InvalidKeyError:  # Raise Http404 on invalid 'usage_key_string'
            raise Http404
        with modulestore().bulk_operations(usage_key.course_key):
            try:
                course, xblock, lms_link, preview_lms_link = _get_item_in_course(
                    request, usage_key)
            except ItemNotFoundError:
                return HttpResponseBadRequest()

            component_templates = get_component_templates(course)
            ancestor_xblocks = []
            parent = get_parent_xblock(xblock)
            action = request.GET.get('action', 'view')

            is_unit_page = is_unit(xblock)
            unit = xblock if is_unit_page else None

            is_first = True
            while parent:
                if unit is None and is_unit(parent):
                    unit = parent
                elif parent.category != 'sequential':
                    current_block = {
                        'block': parent,
                        'children': parent.get_children(),
                        'is_last': is_first
                    }
                    is_first = False
                    ancestor_xblocks.append(current_block)
                parent = get_parent_xblock(parent)

            ancestor_xblocks.reverse()

            assert unit is not None, "Could not determine unit page"
            subsection = get_parent_xblock(unit)
            assert subsection is not None, "Could not determine parent subsection from unit " + six.text_type(
                unit.location)
            section = get_parent_xblock(subsection)
            assert section is not None, "Could not determine ancestor section from unit " + six.text_type(
                unit.location)

            # for the sequence navigator
            prev_url, next_url = get_sibling_urls(subsection)
            # these are quoted here because they'll end up in a query string on the page,
            # and quoting with mako will trigger the xss linter...
            prev_url = quote_plus(prev_url) if prev_url else None
            next_url = quote_plus(next_url) if next_url else None

            # Fetch the XBlock info for use by the container page. Note that it includes information
            # about the block's ancestors and siblings for use by the Unit Outline.
            xblock_info = create_xblock_info(
                xblock, include_ancestor_info=is_unit_page)

            if is_unit_page:
                add_container_page_publishing_info(xblock, xblock_info)

            # need to figure out where this item is in the list of children as the
            # preview will need this
            index = 1
            for child in subsection.get_children():
                if child.location == unit.location:
                    break
                index += 1

            return render_to_response(
                'container.html',
                {
                    'language_code':
                    request.LANGUAGE_CODE,
                    'context_course':
                    course,  # Needed only for display of menus at top of page.
                    'action':
                    action,
                    'xblock':
                    xblock,
                    'xblock_locator':
                    xblock.location,
                    'unit':
                    unit,
                    'is_unit_page':
                    is_unit_page,
                    'subsection':
                    subsection,
                    'section':
                    section,
                    'position':
                    index,
                    'prev_url':
                    prev_url,
                    'next_url':
                    next_url,
                    'new_unit_category':
                    'vertical',
                    'outline_url':
                    '{url}?format=concise'.format(
                        url=reverse_course_url('course_handler', course.id)),
                    'ancestor_xblocks':
                    ancestor_xblocks,
                    'component_templates':
                    component_templates,
                    'xblock_info':
                    xblock_info,
                    'draft_preview_link':
                    preview_lms_link,
                    'published_preview_link':
                    lms_link,
                    'templates':
                    CONTAINER_TEMPLATES
                })
    else:
        return HttpResponseBadRequest("Only supports HTML requests")
예제 #2
0
def container_handler(request, usage_key_string):
    """
    The restful handler for container xblock requests.

    GET
        html: returns the HTML page for editing a container
        json: not currently supported
    """
    if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):

        try:
            usage_key = UsageKey.from_string(usage_key_string)
        except InvalidKeyError:  # Raise Http404 on invalid 'usage_key_string'
            raise Http404
        with modulestore().bulk_operations(usage_key.course_key):
            try:
                course, xblock, lms_link, preview_lms_link = _get_item_in_course(
                    request, usage_key)
            except ItemNotFoundError:
                return HttpResponseBadRequest()

            component_templates = get_component_templates(course)
            ancestor_xblocks = []
            parent = get_parent_xblock(xblock)
            action = request.GET.get('action', 'view')

            is_unit_page = is_unit(xblock)
            unit = xblock if is_unit_page else None

            while parent and parent.category != 'course':
                if unit is None and is_unit(parent):
                    unit = parent
                ancestor_xblocks.append(parent)
                parent = get_parent_xblock(parent)
            ancestor_xblocks.reverse()

            assert unit is not None, "Could not determine unit page"
            subsection = get_parent_xblock(unit)
            assert subsection is not None, "Could not determine parent subsection from unit " + unicode(
                unit.location)
            section = get_parent_xblock(subsection)
            assert section is not None, "Could not determine ancestor section from unit " + unicode(
                unit.location)

            # Fetch the XBlock info for use by the container page. Note that it includes information
            # about the block's ancestors and siblings for use by the Unit Outline.
            xblock_info = create_xblock_info(
                xblock, include_ancestor_info=is_unit_page)

            if is_unit_page:
                add_container_page_publishing_info(xblock, xblock_info)

            # need to figure out where this item is in the list of children as the
            # preview will need this
            index = 1
            for child in subsection.get_children():
                if child.location == unit.location:
                    break
                index += 1

            return render_to_response(
                'container.html',
                {
                    'context_course':
                    course,  # Needed only for display of menus at top of page.
                    'action': action,
                    'xblock': xblock,
                    'xblock_locator': xblock.location,
                    'unit': unit,
                    'is_unit_page': is_unit_page,
                    'subsection': subsection,
                    'section': section,
                    'new_unit_category': 'vertical',
                    'ancestor_xblocks': ancestor_xblocks,
                    'component_templates': component_templates,
                    'xblock_info': xblock_info,
                    'draft_preview_link': preview_lms_link,
                    'published_preview_link': lms_link,
                    'templates': CONTAINER_TEMPLATES
                })
    else:
        return HttpResponseBadRequest("Only supports HTML requests")
예제 #3
0
def container_handler(request, usage_key_string):
    """
    The restful handler for container xblock requests.

    GET
        html: returns the HTML page for editing a container
        json: not currently supported
    """
    if 'text/html' in request.META.get('HTTP_ACCEPT', 'text/html'):

        try:
            usage_key = UsageKey.from_string(usage_key_string)
        except InvalidKeyError:  # Raise Http404 on invalid 'usage_key_string'
            raise Http404
        with modulestore().bulk_operations(usage_key.course_key):
            try:
                course, xblock, lms_link, preview_lms_link = _get_item_in_course(request, usage_key)
            except ItemNotFoundError:
                return HttpResponseBadRequest()

            component_templates = get_component_templates(course)
            ancestor_xblocks = []
            parent = get_parent_xblock(xblock)
            action = request.REQUEST.get('action', 'view')

            is_unit_page = is_unit(xblock)
            unit = xblock if is_unit_page else None

            while parent and parent.category != 'course':
                if unit is None and is_unit(parent):
                    unit = parent
                ancestor_xblocks.append(parent)
                parent = get_parent_xblock(parent)
            ancestor_xblocks.reverse()

            assert unit is not None, "Could not determine unit page"
            subsection = get_parent_xblock(unit)
            assert subsection is not None, "Could not determine parent subsection from unit " + unicode(unit.location)
            section = get_parent_xblock(subsection)
            assert section is not None, "Could not determine ancestor section from unit " + unicode(unit.location)

            # Fetch the XBlock info for use by the container page. Note that it includes information
            # about the block's ancestors and siblings for use by the Unit Outline.
            xblock_info = create_xblock_info(xblock, include_ancestor_info=is_unit_page)

            if is_unit_page:
                add_container_page_publishing_info(xblock, xblock_info)

            # need to figure out where this item is in the list of children as the
            # preview will need this
            index = 1
            for child in subsection.get_children():
                if child.location == unit.location:
                    break
                index += 1

            return render_to_response('container.html', {
                'context_course': course,  # Needed only for display of menus at top of page.
                'action': action,
                'xblock': xblock,
                'xblock_locator': xblock.location,
                'unit': unit,
                'is_unit_page': is_unit_page,
                'subsection': subsection,
                'section': section,
                'new_unit_category': 'vertical',
                'ancestor_xblocks': ancestor_xblocks,
                'component_templates': json.dumps(component_templates),
                'xblock_info': xblock_info,
                'draft_preview_link': preview_lms_link,
                'published_preview_link': lms_link,
                'keywords_supported': get_keywords_supported(),
                'templates': CONTAINER_TEMPATES
            })
    else:
        return HttpResponseBadRequest("Only supports HTML requests")