コード例 #1
0
    def _create(cls, target_class, **kwargs):
        """
        Create and return a new toy course instance. See SampleCourseFactory for customization kwargs.
        """
        store = kwargs.get('modulestore')
        user_id = kwargs.get('user_id', ModuleStoreEnum.UserID.test)

        fields = {
            'block_info_tree': TOY_BLOCK_INFO_TREE,
            'textbooks': [Textbook("Textbook", "path/to/a/text_book")],
            'wiki_slug': "toy",
            'graded': True,
            'discussion_topics': {"General": {"id": "i4x-edX-toy-course-2012_Fall"}},
            'graceperiod': datetime.timedelta(days=2, seconds=21599),
            'start': datetime.datetime(2015, 07, 17, 12, tzinfo=pytz.utc),
            'xml_attributes': {"filename": ["course/2012_Fall.xml", "course/2012_Fall.xml"]},
            'pdf_textbooks': [
                {
                    "tab_title": "Sample Multi Chapter Textbook",
                    "id": "MyTextbook",
                    "chapters": [
                        {"url": "/static/Chapter1.pdf", "title": "Chapter 1"},
                        {"url": "/static/Chapter2.pdf", "title": "Chapter 2"}
                    ]
                }
            ],
            'course_image': "just_a_test.jpg",
        }
コード例 #2
0
ファイル: factories.py プロジェクト: uetuluk/edx-platform
    def _create(cls, target_class, **kwargs):
        """
        Create and return a new toy course instance. See SampleCourseFactory for customization kwargs.
        """
        store = kwargs.get('modulestore')
        user_id = kwargs.get('user_id', ModuleStoreEnum.UserID.test)

        fields = {
            'block_info_tree':
            TOY_BLOCK_INFO_TREE,
            'textbooks': [Textbook("Textbook", "path/to/a/text_book")],
            'wiki_slug':
            "toy",
            'graded':
            True,
            'discussion_topics': {
                "General": {
                    "id": "i4x-edX-toy-course-2012_Fall"
                }
            },
            'graceperiod':
            datetime.timedelta(days=2, seconds=21599),
            'start':
            datetime.datetime(2015, 7, 17, 12, tzinfo=pytz.utc),
            'xml_attributes': {
                "filename": ["course/2012_Fall.xml", "course/2012_Fall.xml"]
            },
            'pdf_textbooks': [{
                "tab_title":
                "Sample Multi Chapter Textbook",
                "id":
                "MyTextbook",
                "chapters": [{
                    "url": "/static/Chapter1.pdf",
                    "title": "Chapter 1"
                }, {
                    "url": "/static/Chapter2.pdf",
                    "title": "Chapter 2"
                }]
            }],
            'course_image':
            "just_a_test.jpg",
        }
        fields.update(kwargs)

        toy_course = super()._create(target_class, **fields)
        with store.bulk_operations(toy_course.id, emit_signals=False):
            with store.branch_setting(ModuleStoreEnum.Branch.draft_preferred,
                                      toy_course.id):
                store.create_item(user_id,
                                  toy_course.id,
                                  "about",
                                  block_id="short_description",
                                  fields={"data": "A course about toys."})
                store.create_item(user_id,
                                  toy_course.id,
                                  "about",
                                  block_id="effort",
                                  fields={"data": "6 hours"})
                store.create_item(user_id,
                                  toy_course.id,
                                  "about",
                                  block_id="end_date",
                                  fields={"data": "TBD"})
                store.create_item(
                    user_id,
                    toy_course.id,
                    "course_info",
                    "handouts",
                    fields={
                        "data":
                        "<a href='/static/handouts/sample_handout.txt'>Sample</a>"
                    })
                store.create_item(
                    user_id,
                    toy_course.id,
                    "static_tab",
                    "resources",
                    fields={"display_name": "Resources"},
                )
                store.create_item(
                    user_id,
                    toy_course.id,
                    "static_tab",
                    "syllabus",
                    fields={"display_name": "Syllabus"},
                )
        return toy_course