当前位置: 首页>>代码示例>>Python>>正文


Python course_details.CourseDetails类代码示例

本文整理汇总了Python中openedx.core.djangoapps.models.course_details.CourseDetails的典型用法代码示例。如果您正苦于以下问题:Python CourseDetails类的具体用法?Python CourseDetails怎么用?Python CourseDetails使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CourseDetails类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_fetch_video

 def test_fetch_video(self):
     video_value = 'test_video_id'
     with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
         CourseDetails.update_about_video(self.course, video_value, self.user.id)
     self.assertEqual(CourseDetails.fetch_youtube_video_id(self.course.id), video_value)
     video_url = CourseDetails.fetch_video_url(self.course.id)
     self.assertRegexpMatches(video_url, r'http://.*{}'.format(video_value))
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:7,代码来源:test_course_details.py

示例2: test_basic

 def test_basic(self):
     expected_data = {
         'course_id': u'edX/toy/2012_Fall',
         'name': u'Toy Course',
         'number': u'toy',
         'org': u'edX',
         'short_description': u'A course about toys.',
         'media': {
             'course_image': {
                 'uri': u'/c4x/edX/toy/asset/just_a_test.jpg',
             },
             'course_video': {
                 'uri': u'http://www.youtube.com/watch?v=test_youtube_id',
             }
         },
         'start': u'2015-07-17T12:00:00Z',
         'start_type': u'timestamp',
         'start_display': u'July 17, 2015',
         'end': u'2015-09-19T18:00:00Z',
         'enrollment_start': u'2015-06-15T00:00:00Z',
         'enrollment_end': u'2015-07-15T00:00:00Z',
         'blocks_url': u'http://testserver/api/courses/v1/blocks/?course_id=edX%2Ftoy%2F2012_Fall',
         'effort': u'6 hours',
     }
     course = self.create_course()
     CourseDetails.update_about_video(course, 'test_youtube_id', self.staff_user.id)  # pylint: disable=no-member
     result = self._get_result(course)
     self.assertDictEqual(result, expected_data)
开发者ID:andela-ijubril,项目名称:edx-platform,代码行数:28,代码来源:test_serializers.py

示例3: test_toggle_pacing_during_course_run

    def test_toggle_pacing_during_course_run(self):
        SelfPacedConfiguration(enabled=True).save()
        self.course.start = datetime.datetime.now()
        self.store.update_item(self.course, self.user.id)

        details = CourseDetails.fetch(self.course.id)
        with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
            updated_details = CourseDetails.update_from_json(
                self.course.id, dict(details.__dict__, self_paced=True), self.user
            )
        self.assertFalse(updated_details.self_paced)
开发者ID:zhenzhai,项目名称:edx-platform,代码行数:11,代码来源:test_course_details.py

示例4: get_overview

 def get_overview(self, course_overview):
     """
     Get the representation for SerializerMethodField `overview`
     """
     # Note: This makes a call to the modulestore, unlike the other
     # fields from CourseSerializer, which get their data
     # from the CourseOverview object in SQL.
     return CourseDetails.fetch_about_attribute(course_overview.id, 'overview')
开发者ID:Colin-Fredericks,项目名称:edx-platform,代码行数:8,代码来源:serializers.py

示例5: test_updates_values_in_mongo_should_be_updated_in_sql

    def test_updates_values_in_mongo_should_be_updated_in_sql(self):
        """ Test that a already existing course is correctly updated
            by update_course management command.
        """
        mongo_course = CourseFactory.create(short_description='test')
        # short_description field is required by FUN Course model
        CourseDetails.update_about_item(
            mongo_course, 'short_description', u"Short description", None)

        self.assertFalse(FUNCourse.objects.all().exists())
        call_command('update_courses', course_id=unicode(mongo_course.id))

        self.assertTrue(u"Short description",
            FUNCourse.objects.get(key=mongo_course.id).short_description)

        CourseDetails.update_about_item(
            mongo_course, 'short_description', u"Short description changed",
            None)
        call_command('update_courses', course_id=unicode(mongo_course.id))

        self.assertEqual(
            u"Short description changed",
            FUNCourse.objects.get(key=mongo_course.id).short_description)
开发者ID:openfun,项目名称:fun-apps,代码行数:23,代码来源:test_SQL_denormalization.py

示例6: get_course_description

 def get_course_description(
     self, bot, chat_id, course_name=None, course_key=None, enroll=None, enroll_keyboard=False
 ):
     """
     Get description of particular courses by Title or by course_id
     """
     bot.sendChatAction(chat_id=chat_id, action=ChatAction.TYPING)
     if enroll:
         result = CourseEnrollment.objects.get(id=enroll)
         results = [modulestore().get_course(result.course_id)]
         course_name = results[0].display_name_with_default
     elif course_key:
         results = [modulestore().get_course(course_key)]
         course_name = modulestore().get_course(course_key).display_name_with_default
     else:
         results = modulestore().get_courses()
         results = [course for course in results if course.scope_ids.block_type == "course"]
     for each in results:
         if each.display_name_with_default == course_name:
             message = truncate_course_info(CourseDetails.fetch_about_attribute(each.id, "overview"))
             if message == "null":
                 bot.sendMessage(chat_id=chat_id, text="I'm sorry, but this course has no description")
             else:
                 bot.sendMessage(
                     chat_id=chat_id, text="*Short course description*", parse_mode=telegram.ParseMode.MARKDOWN
                 )
                 course_key = each.id
                 current_site = Site.objects.get_current()
                 course_title = modulestore().get_course(course_key).display_name_with_default
                 course_url = "[%s](%scourses/%s/)" % (course_title, current_site, each.id)
                 bot.sendMessage(chat_id=chat_id, text=course_url, parse_mode=telegram.ParseMode.MARKDOWN)
                 if enroll_keyboard:
                     reply_markup = InlineKeyboardMarkup(
                         [
                             [
                                 InlineKeyboardButton(
                                     text="I like it and I want to enroll",
                                     callback_data=json.dumps({"key": str(course_key)}),
                                 )
                             ]
                         ]
                     )
                     bot.sendMessage(chat_id=chat_id, text=message, reply_markup=reply_markup)
                 else:
                     bot.sendMessage(chat_id=chat_id, text=message)
             break
     bot.sendMessage(chat_id=chat_id, reply_markup=ReplyKeyboardHide())
开发者ID:vz10,项目名称:edx_telegram_bot,代码行数:47,代码来源:edx_telegram_bot.py

示例7: get_coursed_and_create_matrix

def get_coursed_and_create_matrix():
    results = [course for course in modulestore().get_courses() if course.scope_ids.block_type == "course"]
    new_matrix = TfidMatrixAllCourses.objects.all().first() or TfidMatrixAllCourses()
    print new_matrix.matrix.shape[0] != len(results)
    if new_matrix.matrix.shape[0] != len(results):
        all_courses = [re.sub("<[^>]*>", "", CourseDetails.fetch_about_attribute(x.id, "overview")) for x in results]

        MatrixEdxCoursesId.objects.all().delete()
        map(lambda x: MatrixEdxCoursesId.objects.create(course_key=x.id, course_index=results.index(x)), results)

        stemmer = snowballstemmer.stemmer("english")
        courses_stem = [" ".join(stemmer.stemWords(x.split())) for x in all_courses]

        vect = TfidfVectorizer(stop_words=get_stop_words(), lowercase=True, dtype=np.float32)
        matrix = vect.fit_transform(courses_stem)
        new_matrix.matrix = matrix
        new_matrix.save()
开发者ID:vz10,项目名称:edx_telegram_bot,代码行数:17,代码来源:prediction.py

示例8: test_virgin_fetch

 def test_virgin_fetch(self):
     details = CourseDetails.fetch(self.course.id)
     self.assertEqual(details.org, self.course.location.org, "Org not copied into")
     self.assertEqual(details.course_id, self.course.location.course, "Course_id not copied into")
     self.assertEqual(details.run, self.course.location.name, "Course name not copied into")
     self.assertEqual(details.course_image_name, self.course.course_image)
     self.assertIsNotNone(details.start_date.tzinfo)
     self.assertIsNone(details.end_date, "end date somehow initialized " + str(details.end_date))
     self.assertIsNone(
         details.enrollment_start, "enrollment_start date somehow initialized " + str(details.enrollment_start)
     )
     self.assertIsNone(
         details.enrollment_end, "enrollment_end date somehow initialized " + str(details.enrollment_end)
     )
     self.assertIsNone(details.syllabus, "syllabus somehow initialized" + str(details.syllabus))
     self.assertIsNone(details.intro_video, "intro_video somehow initialized" + str(details.intro_video))
     self.assertIsNone(details.effort, "effort somehow initialized" + str(details.effort))
     self.assertIsNone(details.language, "language somehow initialized" + str(details.language))
     self.assertFalse(details.self_paced)
开发者ID:28554010,项目名称:edx-platform,代码行数:19,代码来源:test_course_details.py

示例9: update_course

    def update_course(self, mongo_course, assign_universities=False):
        '''
        For the given course, we create or update the corresponding
        course in SQL Course table.
        '''

        course_handler = CourseHandler(mongo_course)
        key = course_handler.key
        self.stdout.write('Updating data for course {}\n'.format(key))
        course, was_created = Course.objects.get_or_create(key=key)
        if was_created or assign_universities:
            university = course_handler.assign_university(course)
            if university:
                self.stdout.write('\t University assigned to "{}"\n'.format(key))
            else:
                self.stdout.write('\t No university assigned to "{}"\n'.format(key))
        course.is_active = True
        course.university_display_name = course_handler.university_name
        course.title = course_handler.title
        course.image_url = course_handler.image_url
        thumbnails_info = {}
        for thumbnail_alias, thumbnails_options in \
                courses_settings.FUN_THUMBNAIL_OPTIONS.items():
            thumbnail = course_handler.make_thumbnail(thumbnails_options)
            if thumbnail:
                thumbnails_info[thumbnail_alias] = thumbnail.url
        course.thumbnails_info = thumbnails_info
        course.start_date = mongo_course.start
        course.enrollment_start_date = mongo_course.enrollment_start
        course.enrollment_end_date = mongo_course.enrollment_end
        course.end_date = mongo_course.end

        course_key = CourseKey.from_string(key)
        course.short_description = CourseDetails.fetch_about_attribute(
            course_key,
            'short_description',
        )

        course.save()
        del course
        self.stdout.write('Updated course {}\n'.format(key))
        return None
开发者ID:openfun,项目名称:fun-apps,代码行数:42,代码来源:update_courses.py

示例10: test_update_and_fetch

 def test_update_and_fetch(self):
     SelfPacedConfiguration(enabled=True).save()
     jsondetails = CourseDetails.fetch(self.course.id)
     jsondetails.syllabus = "<a href='foo'>bar</a>"
     # encode - decode to convert date fields and other data which changes form
     with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).syllabus,
             jsondetails.syllabus, "After set syllabus"
         )
         jsondetails.short_description = "Short Description"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).short_description,
             jsondetails.short_description, "After set short_description"
         )
         jsondetails.overview = "Overview"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).overview,
             jsondetails.overview, "After set overview"
         )
         jsondetails.intro_video = "intro_video"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).intro_video,
             jsondetails.intro_video, "After set intro_video"
         )
         jsondetails.effort = "effort"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).effort,
             jsondetails.effort, "After set effort"
         )
         jsondetails.self_paced = True
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).self_paced,
             jsondetails.self_paced
         )
         jsondetails.start_date = datetime.datetime(2010, 10, 1, 0, tzinfo=UTC())
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).start_date,
             jsondetails.start_date
         )
         jsondetails.end_date = datetime.datetime(2011, 10, 1, 0, tzinfo=UTC())
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).end_date,
             jsondetails.end_date
         )
         jsondetails.certificate_available_date = datetime.datetime(2010, 10, 1, 0, tzinfo=UTC())
         self.assertEqual(
             CourseDetails.update_from_json(
                 self.course.id, jsondetails.__dict__, self.user
             ).certificate_available_date,
             jsondetails.certificate_available_date
         )
         jsondetails.course_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).course_image_name,
             jsondetails.course_image_name
         )
         jsondetails.banner_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).banner_image_name,
             jsondetails.banner_image_name
         )
         jsondetails.video_thumbnail_image_name = "an_image.jpg"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).video_thumbnail_image_name,
             jsondetails.video_thumbnail_image_name
         )
         jsondetails.language = "hr"
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).language,
             jsondetails.language
         )
         jsondetails.learning_info = ["test", "test"]
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).learning_info,
             jsondetails.learning_info
         )
         jsondetails.instructor_info = {
             "instructors": [
                 {
                     "name": "test",
                     "title": "test",
                     "organization": "test",
                     "image": "test",
                     "bio": "test"
                 }
             ]
         }
         self.assertEqual(
             CourseDetails.update_from_json(self.course.id, jsondetails.__dict__, self.user).instructor_info,
             jsondetails.instructor_info
         )
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:92,代码来源:test_course_details.py

示例11: recommend

    def recommend(self, bot, chat_id, telegram_user):
        telegram_id = telegram_user.telegram_id
        if not LearningPredictionForUser.objects.filter(telegram_user=telegram_user):
            bot.sendMessage(
                chat_id=chat_id,
                text="It seems like I see you for the first time,"
                " please answer a few questions, so I'll be know more about you",
            )
            prediction.get_test_courses(telegram_id)
        test_courses = LearningPredictionForUser.objects.get(telegram_user=telegram_user).get_list()
        if len(test_courses) > 0:
            course_id = MatrixEdxCoursesId.objects.filter(course_index=test_courses[0]).first().course_key
            course_key = CourseKey.from_string(course_id)
            reply_markup = InlineKeyboardMarkup(
                [
                    [
                        InlineKeyboardButton(
                            text="I like it!", callback_data=json.dumps({"method": "learning", "kwargs": {}})
                        )
                    ],
                    [
                        InlineKeyboardButton(
                            text="Hmmm. I don't like at all!",
                            callback_data=json.dumps({"method": "learning", "kwargs": {"is_positive": False}}),
                        )
                    ],
                ]
            )
        else:
            predicted_course_id = prediction.prediction(telegram_id)

            if predicted_course_id == -1:
                bot.sendMessage(chat_id=chat_id, text="It seems like you have enrolled to all courses we have for now")
                return

            predicted_course_key = (
                MatrixEdxCoursesId.objects.filter(course_index=predicted_course_id).first().course_key
            )
            bot.sendMessage(chat_id=chat_id, text="Now I'm going to recommend you some great courses")
            course_key = CourseKey.from_string(predicted_course_key)

            course_for_user = PredictionForUser.objects.get_or_create(telegram_user=telegram_user)[0]
            course_for_user.prediction_course = predicted_course_key
            course_for_user.save()
            reply_markup = InlineKeyboardMarkup(
                [
                    [
                        InlineKeyboardButton(
                            text="I like it and I want to enroll",
                            callback_data=json.dumps({"method": "enroll", "kwargs": {}}),
                        )
                    ],
                    [
                        InlineKeyboardButton(
                            text="I like it but will eroll another time",
                            callback_data=json.dumps({"method": "not_enroll", "kwargs": {}}),
                        )
                    ],
                    [
                        InlineKeyboardButton(
                            text="What the shit is this (I don't like it)",
                            callback_data=json.dumps({"method": "wrong_predict", "kwargs": {}}),
                        )
                    ],
                ]
            )

        course_description = CourseDetails.fetch_about_attribute(course_key, "overview")
        course_title = modulestore().get_course(course_key).display_name_with_default
        bot.sendMessage(chat_id=chat_id, text="*%s*" % course_title, parse_mode=telegram.ParseMode.MARKDOWN)
        bot.sendMessage(chat_id=chat_id, text=truncate_course_info(course_description), reply_markup=reply_markup)
开发者ID:vz10,项目名称:edx_telegram_bot,代码行数:71,代码来源:edx_telegram_bot.py

示例12: test_fetch_about_attribute_error

 def test_fetch_about_attribute_error(self):
     attribute_name = 'not_an_about_attribute'
     with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
         CourseDetails.update_about_item(self.course, attribute_name, 'test_value', self.user.id)
     with self.assertRaises(ValueError):
         CourseDetails.fetch_about_attribute(self.course.id, attribute_name)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:6,代码来源:test_course_details.py

示例13: test_fetch_about_attribute

 def test_fetch_about_attribute(self, attribute_name):
     attribute_value = 'test_value'
     with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, self.course.id):
         CourseDetails.update_about_item(self.course, attribute_name, attribute_value, self.user.id)
     self.assertEqual(CourseDetails.fetch_about_attribute(self.course.id, attribute_name), attribute_value)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:5,代码来源:test_course_details.py

示例14: _create_from_course

    def _create_from_course(cls, course):
        """
        Creates a CourseOverview object from a CourseDescriptor.

        Does not touch the database, simply constructs and returns an overview
        from the given course.

        Arguments:
            course (CourseDescriptor): any course descriptor object

        Returns:
            CourseOverview: overview extracted from the given course
        """
        from lms.djangoapps.certificates.api import get_active_web_certificate
        from openedx.core.lib.courses import course_image_url

        log.info('Creating course overview for %s.', unicode(course.id))

        # Workaround for a problem discovered in https://openedx.atlassian.net/browse/TNL-2806.
        # If the course has a malformed grading policy such that
        # course._grading_policy['GRADE_CUTOFFS'] = {}, then
        # course.lowest_passing_grade will raise a ValueError.
        # Work around this for now by defaulting to None.
        try:
            lowest_passing_grade = course.lowest_passing_grade
        except ValueError:
            lowest_passing_grade = None

        display_name = course.display_name
        start = course.start
        end = course.end
        max_student_enrollments_allowed = course.max_student_enrollments_allowed
        if isinstance(course.id, CCXLocator):
            from lms.djangoapps.ccx.utils import get_ccx_from_ccx_locator
            ccx = get_ccx_from_ccx_locator(course.id)
            display_name = ccx.display_name
            start = ccx.start
            end = ccx.due
            max_student_enrollments_allowed = ccx.max_student_enrollments_allowed

        return cls(
            version=cls.VERSION,
            id=course.id,
            _location=course.location,
            org=course.location.org,
            display_name=display_name,
            display_number_with_default=course.display_number_with_default,
            display_org_with_default=course.display_org_with_default,

            start=start,
            end=end,
            advertised_start=course.advertised_start,
            announcement=course.announcement,

            course_image_url=course_image_url(course),
            social_sharing_url=course.social_sharing_url,

            certificates_display_behavior=course.certificates_display_behavior,
            certificates_show_before_end=course.certificates_show_before_end,
            cert_html_view_enabled=course.cert_html_view_enabled,
            has_any_active_web_certificate=(get_active_web_certificate(course) is not None),
            cert_name_short=course.cert_name_short,
            cert_name_long=course.cert_name_long,
            lowest_passing_grade=lowest_passing_grade,
            end_of_course_survey_url=course.end_of_course_survey_url,

            days_early_for_beta=course.days_early_for_beta,
            mobile_available=course.mobile_available,
            visible_to_staff_only=course.visible_to_staff_only,
            _pre_requisite_courses_json=json.dumps(course.pre_requisite_courses),

            enrollment_start=course.enrollment_start,
            enrollment_end=course.enrollment_end,
            enrollment_domain=course.enrollment_domain,
            invitation_only=course.invitation_only,
            max_student_enrollments_allowed=max_student_enrollments_allowed,

            catalog_visibility=course.catalog_visibility,
            short_description=CourseDetails.fetch_about_attribute(course.id, 'short_description'),
            effort=CourseDetails.fetch_about_attribute(course.id, 'effort'),
            course_video_url=CourseDetails.fetch_video_url(course.id),
            self_paced=course.self_paced,
        )
开发者ID:CraftAcademy,项目名称:edx-platform,代码行数:83,代码来源:models.py

示例15: test_basic

 def test_basic(self):
     course = self.create_course()
     CourseDetails.update_about_video(course, 'test_youtube_id', self.staff_user.id)
     with check_mongo_calls(self.expected_mongo_calls):
         result = self._get_result(course)
     self.assertDictEqual(result, self.expected_data)
开发者ID:edx,项目名称:edx-platform,代码行数:6,代码来源:test_serializers.py


注:本文中的openedx.core.djangoapps.models.course_details.CourseDetails类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。