Beispiel #1
0
 def __init__(self, *args, **kwargs):
     memory_id_manager = MemoryIdManager()
     # Provide an IdReader if one isn't already passed to the runtime.
     if not args:
         kwargs.setdefault('id_reader', memory_id_manager)
     kwargs.setdefault('id_generator', memory_id_manager)
     super(TestRuntime, self).__init__(*args, **kwargs)
Beispiel #2
0
 def __init__(
         self,
         handler_url,  # type: Callable[[UsageKey, str, Union[int, ANONYMOUS_USER]], str]
         student_data_mode,  # type: Union[STUDENT_DATA_EPHEMERAL, STUDENT_DATA_PERSISTED]
         runtime_class,  # type: XBlockRuntime
 ):
     """
     args:
         handler_url: A method to get URLs to call XBlock handlers. It must
             implement this signature:
             handler_url(
                 usage_key: UsageKey,
                 handler_name: str,
                 user_id: Union[int, str],
             )
         student_data_mode: Specifies whether student data should be kept
             in a temporary in-memory store (e.g. Studio) or persisted
             forever in the database.
         runtime_class: What runtime to use, e.g. BlockstoreXBlockRuntime
     """
     self.handler_url = handler_url
     self.id_reader = OpaqueKeyReader()
     self.id_generator = MemoryIdManager(
     )  # We don't really use id_generator until we need to support asides
     self.runtime_class = runtime_class
     self.authored_data_store = BlockstoreFieldData()
     self.children_data_store = BlockstoreChildrenData(
         self.authored_data_store)
     assert student_data_mode in (self.STUDENT_DATA_EPHEMERAL,
                                  self.STUDENT_DATA_PERSISTED)
     self.student_data_mode = student_data_mode
     self._error_trackers = {}
 def __init__(self):
     id_manager = MemoryIdManager()
     field_data = KvsFieldData(DictKeyValueStore())
     super().__init__(
         id_reader=id_manager,
         id_generator=id_manager,
         field_data=field_data,
     )
Beispiel #4
0
    def __init__(
            self,
            handler_url,  # type: (Callable[[XBlock, string, string, string, bool], string]
            authored_data_kvs,  # type: KeyValueStore
            student_data_kvs,  # type: KeyValueStore
            runtime_class,  # type: XBlockRuntime
    ):
        """
        args:
            handler_url: A method that implements the XBlock runtime
                handler_url interface.
            authored_data_kvs: An KeyValueStore used to retrieve
                any fields with UserScope.NONE
            student_data_kvs: An KeyValueStore used to retrieve
                any fields with UserScope.ONE or UserScope.ALL
        """
        self.handler_url = handler_url
        # TODO: new ID manager:
        self.id_reader = OpaqueKeyReader()
        self.id_generator = MemoryIdManager(
        )  # We don't really use id_generator until we need to support asides
        self.runtime_class = runtime_class

        # Field data storage/retrieval:
        authored_data = KvsFieldData(kvs=authored_data_kvs)
        student_data = KvsFieldData(kvs=student_data_kvs)
        #if authored_data_readonly:
        #    authored_data = ReadOnlyFieldData(authored_data)

        self.field_data = SplitFieldData({
            Scope.content: authored_data,
            Scope.settings: authored_data,
            Scope.parent: authored_data,
            Scope.children: authored_data,
            Scope.user_state_summary: student_data,
            Scope.user_state: student_data,
            Scope.user_info: student_data,
            Scope.preferences: student_data,
        })

        self._error_trackers = {}
Beispiel #5
0
    def __init__(
            self,
            handler_url,  # type: (Callable[[UsageKey, str, Union[int, ANONYMOUS_USER]], str]
            authored_data_store,  # type: FieldData
            student_data_store,  # type: FieldData
            runtime_class,  # type: XBlockRuntime
    ):
        """
        args:
            handler_url: A method to get URLs to call XBlock handlers. It must
                implement this signature:
                handler_url(
                    usage_key: UsageKey,
                    handler_name: str,
                    user_id: Union[int, ANONYMOUS_USER],
                )
                If user_id is ANONYMOUS_USER, the handler should execute without
                any user-scoped fields.
            authored_data_store: A FieldData instance used to retrieve/write
                any fields with UserScope.NONE
            student_data_store: A FieldData instance used to retrieve/write
                any fields with UserScope.ONE or UserScope.ALL
        """
        self.handler_url = handler_url
        self.id_reader = OpaqueKeyReader()
        self.id_generator = MemoryIdManager(
        )  # We don't really use id_generator until we need to support asides
        self.runtime_class = runtime_class
        self.authored_data_store = authored_data_store
        self.field_data = SplitFieldData({
            Scope.content: authored_data_store,
            Scope.settings: authored_data_store,
            Scope.parent: authored_data_store,
            Scope.children: authored_data_store,
            Scope.user_state_summary: student_data_store,
            Scope.user_state: student_data_store,
            Scope.user_info: student_data_store,
            Scope.preferences: student_data_store,
        })

        self._error_trackers = {}
Beispiel #6
0
        has_query = False
        if not thirdparty:
            url += "?student={student}".format(student=block.scope_ids.user_id)
            has_query = True
        if query:
            url += "&" if has_query else "?"
            url += query
        return url

    def resource_url(self, resource):
        return "toyruntime/" + resource

    def local_resource_url(self, block, uri):
        return ''

    def publish(self, block, event_type, event_data):
        log.info(
            "XBlock '%s' event for %s (usage_id={%s}): %r",
            event_type,
            block.scope_ids.block_type,
            block.scope_ids.usage_id,
            event_data
        )


# Our global state (the "database").
TOYRUNTIME_KVS = ToyRuntimeKeyValueStore(dict())

# Our global id manager
ID_MANAGER = MemoryIdManager()