def parse_args(self, *args):
        """
        Return a 5-tuple of passed in values for (course_key, user, org, course, run).
        """
        if len(args) < 2:
            raise CommandError(
                "migrate_to_split requires at least two arguments: "
                "a course_key and a user identifier (email or ID)"
            )

        try:
            course_key = CourseKey.from_string(args[0])
        except InvalidKeyError:
            raise CommandError("Invalid location string")

        try:
            user = user_from_str(args[1])
        except User.DoesNotExist:
            raise CommandError("No user found identified by {}".format(args[1]))

        org = course = run = None
        try:
            org = args[2]
            course = args[3]
            run = args[4]
        except IndexError:
            pass

        return course_key, user.id, org, course, run
Exemple #2
0
    def parse_args(self, *args):
        """
        Return a tuple of passed in values for (modulestore, user, org, course, run).
        """
        if len(args) != 5:
            raise CommandError(
                "create_course requires 5 arguments: "
                "a modulestore, user, org, course, run. Modulestore is one of {}"
                .format(
                    [ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split]))

        if args[0] not in [
                ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split
        ]:
            raise CommandError(
                "Modulestore (first arg) must be one of {}".format(
                    [ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split]))
        storetype = args[0]

        try:
            user = user_from_str(args[1])
        except User.DoesNotExist:
            raise CommandError(
                "No user {user} found: expected args are {args}".format(
                    user=args[1],
                    args=self.args,
                ), )

        org = args[2]
        course = args[3]
        run = args[4]

        return storetype, user, org, course, run
Exemple #3
0
    def parse_args(self, *args):
        """
        Return a 5-tuple of passed in values for (course_key, user, org, course, run).
        """
        if len(args) < 2:
            raise CommandError(
                "migrate_to_split requires at least two arguments: "
                "a course_key and a user identifier (email or ID)")

        try:
            course_key = CourseKey.from_string(args[0])
        except InvalidKeyError:
            raise CommandError("Invalid location string")

        try:
            user = user_from_str(args[1])
        except User.DoesNotExist:
            raise CommandError("No user found identified by {}".format(
                args[1]))

        org = course = run = None
        try:
            org = args[2]
            course = args[3]
            run = args[4]
        except IndexError:
            pass

        return course_key, user.id, org, course, run
    def parse_args(self, *args):
        """
        Return a tuple of passed in values for (modulestore, user, org, course, run).
        """
        if len(args) != 5:
            raise CommandError(
                "create_course requires 5 arguments: "
                "a modulestore, user, org, course, run. Modulestore is one of {}".format(
                    [ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split]
                )
            )

        if args[0] not in [ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split]:
            raise CommandError(
                "Modulestore (first arg) must be one of {}".format(
                    [ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split]
                )
            )
        storetype = args[0]

        try:
            user = user_from_str(args[1])
        except User.DoesNotExist:
            raise CommandError(
                "No user {user} found: expected args are {args}".format(
                    user=args[1],
                    args=self.args,
                ),
            )

        org = args[2]
        course = args[3]
        run = args[4]

        return storetype, user, org, course, run
 def get_user(self, user):
     """
     Return a User object.
     """
     try:
         user_object = user_from_str(user)
     except User.DoesNotExist:
         raise CommandError("No user {user} found.".format(user=user))
     return user_object
 def get_user(self, user):
     """
     Return a User object.
     """
     try:
         user_object = user_from_str(user)
     except User.DoesNotExist:
         raise CommandError(u"No user {user} found.".format(user=user))
     return user_object
Exemple #7
0
    def parse_args(self, **options):
        """
        Return a tuple of passed in values for (modulestore, user, org, course, run).
        """
        try:
            user = user_from_str(options['user'])
        except User.DoesNotExist:
            raise CommandError("No user {user} found.".format(user=options['user']))

        return options['modulestore'], user, options['org'], options['course'], options['run']
Exemple #8
0
    def parse_args(self, **options):
        """
        Return a tuple of passed in values for (modulestore, user, org, course, run).
        """
        try:
            user = user_from_str(options['user'])
        except User.DoesNotExist:
            raise CommandError("No user {user} found.".format(user=options['user']))

        return options['modulestore'], user, options['org'], options['number'], options['run'], options['name']
Exemple #9
0
    def parse_args(self, **options):
        """
        Return a 5-tuple of passed in values for (course_key, user, org, course, run).
        """
        try:
            course_key = CourseKey.from_string(options['course_key'])
        except InvalidKeyError:
            raise CommandError("Invalid location string")

        try:
            user = user_from_str(options['email'])
        except User.DoesNotExist:
            raise CommandError(u"No user found identified by {}".format(options['email']))

        return course_key, user.id, options['org'], options['course'], options['run']
    def parse_args(self, **options):
        """
        Return a 5-tuple of passed in values for (course_key, user, org, course, run).
        """
        try:
            course_key = CourseKey.from_string(options['course_key'])
        except InvalidKeyError:
            raise CommandError("Invalid location string")

        try:
            user = user_from_str(options['email'])
        except User.DoesNotExist:
            raise CommandError(u"No user found identified by {}".format(options['email']))

        return course_key, user.id, options['org'], options['course'], options['run']
Exemple #11
0
    def handle(self, *args, **options):
        try:
            courses = json.loads(options["courses_json"])["courses"]
        except ValueError:
            raise CommandError("Invalid JSON object")
        except KeyError:
            raise CommandError("JSON object is missing courses list")

        for course_settings in courses:
            # Validate course
            if not self._course_is_valid(course_settings):
                logger.warning(
                    "Can't create course, proceeding to next course")
                continue

            # Retrieve settings
            org = course_settings["organization"]
            num = course_settings["number"]
            run = course_settings["run"]
            user_email = course_settings["user"]
            try:
                user = user_from_str(user_email)
            except User.DoesNotExist:
                logger.warning(user_email + " user does not exist")
                logger.warning(
                    "Can't create course, proceeding to next course")
                continue
            fields = self._process_course_fields(course_settings["fields"])

            # Create the course
            try:
                new_course = create_new_course_in_store(
                    "split", user, org, num, run, fields)
                logger.info("Created {}".format(unicode(new_course.id)))
            except DuplicateCourseError:
                logger.warning("Course already exists for %s, %s, %s", org,
                               num, run)

            # Configure credit provider
            if ("enrollment"
                    in course_settings) and ("credit_provider"
                                             in course_settings["enrollment"]):
                credit_provider = course_settings["enrollment"][
                    "credit_provider"]
                if credit_provider is not None:
                    CreditProvider.objects.get_or_create(
                        provider_id=credit_provider,
                        display_name=credit_provider)
    def handle(self, *args, **options):
        try:
            courses = json.loads(options["courses_json"])["courses"]
        except ValueError:
            raise CommandError("Invalid JSON object")
        except KeyError:
            raise CommandError("JSON object is missing courses list")

        for course_settings in courses:
            # Validate course
            if not self._course_is_valid(course_settings):
                logger.warning("Can't create course, proceeding to next course")
                continue

            # Retrieve settings
            org = course_settings["organization"]
            num = course_settings["number"]
            run = course_settings["run"]
            user_email = course_settings["user"]
            try:
                user = user_from_str(user_email)
            except User.DoesNotExist:
                logger.warning(user_email + " user does not exist")
                logger.warning("Can't create course, proceeding to next course")
                continue
            fields = self._process_course_fields(course_settings["fields"])

            # Create the course
            try:
                new_course = create_new_course_in_store("split", user, org, num, run, fields)
                logger.info("Created {}".format(unicode(new_course.id)))
            except DuplicateCourseError:
                logger.warning("Course already exists for %s, %s, %s", org, num, run)

            # Configure credit provider
            if ("enrollment" in course_settings) and ("credit_provider" in course_settings["enrollment"]):
                credit_provider = course_settings["enrollment"]["credit_provider"]
                if credit_provider is not None:
                    CreditProvider.objects.get_or_create(
                        provider_id=credit_provider,
                        display_name=credit_provider
                    )
    def handle(self, *args, **options):

        if options["json"] is None:
            raise CommandError("Must pass in JSON object")

        try:
            settings = json.loads(options["json"])
        except ValueError:
            raise CommandError("Invalid JSON")

        if not (all(key in settings
                    for key in ("store", "user", "organization", "number",
                                "run", "fields"))):
            raise CommandError("JSON object is missing required fields")

        if settings["store"] in [
                ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split
        ]:
            store = settings["store"]
        else:
            raise CommandError("Modulestore invalid_store is not valid")

        try:
            user = user_from_str(settings["user"])
        except User.DoesNotExist:
            raise CommandError(
                "User {user} not found".format(user=settings["user"]))

        org = settings["organization"]
        num = settings["number"]
        run = settings["run"]
        fields = settings["fields"]

        # Create the course
        new_course = create_new_course_in_store(store, user, org, num, run,
                                                fields)
        self.stdout.write(u"Created {}".format(unicode(new_course.id)))