當前位置: 首頁>>代碼示例>>Python>>正文


Python DjangoXBlockUserStateClient.iter_all_for_block方法代碼示例

本文整理匯總了Python中courseware.user_state_client.DjangoXBlockUserStateClient.iter_all_for_block方法的典型用法代碼示例。如果您正苦於以下問題:Python DjangoXBlockUserStateClient.iter_all_for_block方法的具體用法?Python DjangoXBlockUserStateClient.iter_all_for_block怎麽用?Python DjangoXBlockUserStateClient.iter_all_for_block使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在courseware.user_state_client.DjangoXBlockUserStateClient的用法示例。


在下文中一共展示了DjangoXBlockUserStateClient.iter_all_for_block方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _build_student_data

# 需要導入模塊: from courseware.user_state_client import DjangoXBlockUserStateClient [as 別名]
# 或者: from courseware.user_state_client.DjangoXBlockUserStateClient import iter_all_for_block [as 別名]
    def _build_student_data(cls, user_id, course_key, usage_key_str):
        """
        Generate a list of problem responses for all problem under the
        ``problem_location`` root.

        Arguments:
            user_id (int): The user id for the user generating the report
            course_key (CourseKey): The ``CourseKey`` for the course whose report
                is being generated
            usage_key_str (str): The generated report will include this
                block and it child blocks.

        Returns:
              Tuple[List[Dict], List[str]]: Returns a list of dictionaries
                containing the student data which will be included in the
                final csv, and the features/keys to include in that CSV.
        """
        usage_key = UsageKey.from_string(usage_key_str).map_into_course(course_key)
        user = get_user_model().objects.get(pk=user_id)
        course_blocks = get_course_blocks(user, usage_key)

        student_data = []
        max_count = settings.FEATURES.get('MAX_PROBLEM_RESPONSES_COUNT')

        store = modulestore()
        user_state_client = DjangoXBlockUserStateClient()

        student_data_keys = set()

        with store.bulk_operations(course_key):
            for title, path, block_key in cls._build_problem_list(course_blocks, usage_key):
                # Chapter and sequential blocks are filtered out since they include state
                # which isn't useful for this report.
                if block_key.block_type in ('sequential', 'chapter'):
                    continue

                block = store.get_item(block_key)
                generated_report_data = {}

                # Blocks can implement the generate_report_data method to provide their own
                # human-readable formatting for user state.
                if hasattr(block, 'generate_report_data'):
                    try:
                        user_state_iterator = user_state_client.iter_all_for_block(block_key)
                        generated_report_data = {
                            username: state
                            for username, state in
                            block.generate_report_data(user_state_iterator, max_count)
                        }
                    except NotImplementedError:
                        pass

                responses = list_problem_responses(course_key, block_key, max_count)

                student_data += responses
                for response in responses:
                    response['title'] = title
                    # A human-readable location for the current block
                    response['location'] = ' > '.join(path)
                    # A machine-friendly location for the current block
                    response['block_key'] = str(block_key)
                    user_data = generated_report_data.get(response['username'], {})
                    response.update(user_data)
                    student_data_keys = student_data_keys.union(user_data.keys())
                if max_count is not None:
                    max_count -= len(responses)
                    if max_count <= 0:
                        break

        # Keep the keys in a useful order, starting with username, title and location,
        # then the columns returned by the xblock report generator in sorted order and
        # finally end with the more machine friendly block_key and state.
        student_data_keys_list = (
            ['username', 'title', 'location'] +
            sorted(student_data_keys) +
            ['block_key', 'state']
        )

        return student_data, student_data_keys_list
開發者ID:cmscom,項目名稱:edx-platform,代碼行數:81,代碼來源:grades.py


注:本文中的courseware.user_state_client.DjangoXBlockUserStateClient.iter_all_for_block方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。