示例#1
0
    def dump_one(self, *args, **options):
        if not args:
            raise CommandError("Course id not specified")
        if len(args) > 2:
            raise CommandError("Only one course id may be specified")
        raw_course_key = args[0]

        if len(args) == 1:
            output_file_location = self.get_default_file_location(
                raw_course_key)
        else:
            output_file_location = args[1]

        try:
            course_key = CourseKey.from_string(raw_course_key)
        except InvalidKeyError:
            course_key = SlashSeparatedCourseKey.from_deprecated_string(
                raw_course_key)

        course = get_course(course_key)
        if not course:
            raise CommandError("Invalid course id: {}".format(course_key))

        target_discussion_ids = None
        if options.get(self.COHORTED_ONLY_PARAMETER, False):
            cohorted_discussions = get_legacy_discussion_settings(
                course_key).cohorted_discussions
            if not cohorted_discussions:
                raise MissingCohortedConfigCommandError(
                    "Only cohorted discussions are marked for export, "
                    "but no cohorted discussions found for the course")
            else:
                target_discussion_ids = cohorted_discussions

        raw_end_date = options.get(self.END_DATE_PARAMETER, None)
        end_date = dateutil.parser.parse(
            raw_end_date) if raw_end_date else None
        data = Extractor().extract(
            course_key,
            end_date=end_date,
            thread_type=(options.get(self.THREAD_TYPE_PARAMETER, None)),
            thread_ids=target_discussion_ids,
        )

        filter_str = self._get_filter_string_representation(options)

        self.stdout.write("Writing social stats ({}) to {}\n".format(
            filter_str, output_file_location))
        with open(output_file_location, 'wb') as output_stream:
            Exporter(output_stream).export(data)
示例#2
0
def get_course_discussion_settings(course_key):
    try:
        course_discussion_settings = CourseDiscussionSettings.objects.get(course_id=course_key)
    except CourseDiscussionSettings.DoesNotExist:
        legacy_discussion_settings = get_legacy_discussion_settings(course_key)
        course_discussion_settings, _ = CourseDiscussionSettings.objects.get_or_create(
            course_id=course_key,
            defaults={
                'always_divide_inline_discussions': legacy_discussion_settings['always_cohort_inline_discussions'],
                'divided_discussions': legacy_discussion_settings['cohorted_discussions'],
                'division_scheme': CourseDiscussionSettings.COHORT if legacy_discussion_settings['is_cohorted']
                else CourseDiscussionSettings.NONE
            }
        )

    return course_discussion_settings
    def dump_one(self, *args, **options):
        if not args:
            raise CommandError("Course id not specified")
        if len(args) > 2:
            raise CommandError("Only one course id may be specified")
        raw_course_key = args[0]

        if len(args) == 1:
            output_file_location = self.get_default_file_location(raw_course_key)
        else:
            output_file_location = args[1]

        try:
            course_key = CourseKey.from_string(raw_course_key)
        except InvalidKeyError:
            course_key = SlashSeparatedCourseKey.from_deprecated_string(raw_course_key)

        course = get_course(course_key)
        if not course:
            raise CommandError("Invalid course id: {}".format(course_key))

        target_discussion_ids = None
        if options.get(self.COHORTED_ONLY_PARAMETER, False):
            cohorted_discussions = get_legacy_discussion_settings(course_key).cohorted_discussions
            if not cohorted_discussions:
                raise MissingCohortedConfigCommandError(
                    "Only cohorted discussions are marked for export, "
                    "but no cohorted discussions found for the course")
            else:
                target_discussion_ids = cohorted_discussions

        raw_end_date = options.get(self.END_DATE_PARAMETER, None)
        end_date = dateutil.parser.parse(raw_end_date) if raw_end_date else None
        data = Extractor().extract(
            course_key,
            end_date=end_date,
            thread_type=(options.get(self.THREAD_TYPE_PARAMETER, None)),
            thread_ids=target_discussion_ids,
        )

        filter_str = self._get_filter_string_representation(options)

        self.stdout.write("Writing social stats ({}) to {}\n".format(filter_str, output_file_location))
        with open(output_file_location, 'wb') as output_stream:
            Exporter(output_stream).export(data)
示例#4
0
 def get(cls, course_key):
     """
     Get and/or create settings
     """
     try:
         course_discussion_settings = cls.objects.get(course_id=course_key)
     except cls.DoesNotExist:
         from openedx.core.djangoapps.course_groups.cohorts import get_legacy_discussion_settings
         legacy_discussion_settings = get_legacy_discussion_settings(course_key)
         course_discussion_settings, _ = cls.objects.get_or_create(
             course_id=course_key,
             defaults={
                 'always_divide_inline_discussions': legacy_discussion_settings['always_cohort_inline_discussions'],
                 'divided_discussions': legacy_discussion_settings['cohorted_discussions'],
                 'division_scheme': cls.COHORT if legacy_discussion_settings['is_cohorted'] else cls.NONE
             },
         )
     return course_discussion_settings