示例#1
0
    def __init__(self, **kwargs):
        request_cache_dict = DEFAULT_REQUEST_CACHE.data
        store = modulestore()

        services = kwargs.setdefault('services', {})
        user = kwargs.get('user')
        if user and user.is_authenticated:
            services['completion'] = CompletionService(
                user=user, context_key=kwargs.get('course_id'))
        services['fs'] = xblock.reference.plugins.FSService()
        services['i18n'] = ModuleI18nService
        services['library_tools'] = LibraryToolsService(
            store, user_id=user.id if user else None)
        services['partitions'] = PartitionService(
            course_id=kwargs.get('course_id'), cache=request_cache_dict)
        services['settings'] = SettingsService()
        services['user_tags'] = UserTagsService(self)
        if badges_enabled():
            services['badging'] = BadgingService(
                course_id=kwargs.get('course_id'), modulestore=store)
        self.request_token = kwargs.pop('request_token', None)
        services['teams'] = TeamsService()
        services['teams_configuration'] = TeamsConfigurationService()
        services['call_to_action'] = CallToActionService()
        super(LmsModuleSystem, self).__init__(**kwargs)
示例#2
0
def _preview_module_system(request, descriptor, field_data):
    """
    Returns a ModuleSystem for the specified descriptor that is specialized for
    rendering module previews.

    request: The active django request
    descriptor: An XModuleDescriptor
    """

    course_id = descriptor.location.course_key
    display_name_only = (descriptor.category == 'static_tab')

    replace_url_service = ReplaceURLService(course_id=course_id)

    wrappers = [
        # This wrapper wraps the module in the template specified above
        partial(wrap_xblock,
                'PreviewRuntime',
                display_name_only=display_name_only,
                usage_id_serializer=str,
                request_token=request_token(request)),

        # This wrapper replaces urls in the output that start with /static
        # with the correct course-specific url for the static content
        partial(replace_urls_wrapper,
                replace_url_service=replace_url_service,
                static_replace_only=True),
        _studio_wrap_xblock,
    ]

    wrappers_asides = [
        partial(wrap_xblock_aside,
                'PreviewRuntime',
                usage_id_serializer=str,
                request_token=request_token(request))
    ]

    mako_service = MakoService(namespace_prefix='lms.')
    if settings.FEATURES.get("LICENSING", False):
        # stick the license wrapper in front
        wrappers.insert(0, partial(wrap_with_license,
                                   mako_service=mako_service))

    return PreviewModuleSystem(
        static_url=settings.STATIC_URL,
        # TODO (cpennington): Do we want to track how instructors are using the preview problems?
        track_function=lambda event_type, event: None,
        get_module=partial(_load_preview_module, request),
        debug=True,
        mixins=settings.XBLOCK_MIXINS,
        course_id=course_id,

        # Set up functions to modify the fragment produced by student_view
        wrappers=wrappers,
        wrappers_asides=wrappers_asides,
        error_descriptor_class=ErrorBlock,
        # Get the raw DescriptorSystem, not the CombinedSystem
        descriptor_runtime=descriptor._runtime,  # pylint: disable=protected-access
        services={
            "field-data":
            field_data,
            "i18n":
            ModuleI18nService,
            'mako':
            mako_service,
            "settings":
            SettingsService(),
            "user":
            DjangoXBlockUserService(
                request.user,
                anonymous_user_id='student',
                user_role=get_user_role(request.user, course_id),
            ),
            "partitions":
            StudioPartitionService(course_id=course_id),
            "teams_configuration":
            TeamsConfigurationService(),
            "sandbox":
            SandboxService(contentstore=contentstore, course_id=course_id),
            "cache":
            CacheService(cache),
            'replace_urls':
            replace_url_service
        },
    )