def handle(self, *args, **options):
        if not options['course']:
            raise CommandError(Command.course_option.help)

        course = get_course_by_id(options['course'])

        print 'Warning: this command directly edits the list of course tabs in mongo.'
        print 'Tabs before any changes:'
        print_course(course)

        try:
            if options['delete']:
                if len(args) != 1:
                    raise CommandError(Command.delete_option.help)
                num = int(args[0])
                if query_yes_no('Deleting tab {0} Confirm?'.format(num), default='no'):
                    tabs.primitive_delete(course, num - 1)  # -1 for 0-based indexing
            elif options['insert']:
                if len(args) != 3:
                    raise CommandError(Command.insert_option.help)
                num = int(args[0])
                tab_type = args[1]
                name = args[2]
                if query_yes_no('Inserting tab {0} "{1}" "{2}" Confirm?'.format(num, tab_type, name), default='no'):
                    tabs.primitive_insert(course, num - 1, tab_type, name)  # -1 as above
        except ValueError as e:
            # Cute: translate to CommandError so the CLI error prints nicely.
            raise CommandError(e)
Exemple #2
0
    def handle(self, *args, **options):
        course = get_course_by_id(CourseKey.from_string(options['course']))

        print(
            'Warning: this command directly edits the list of course tabs in mongo.'
        )
        print('Tabs before any changes:')
        print_course(course)

        try:
            if options['delete']:
                num = int(options['delete'][0])
                if num < 3:
                    raise CommandError("Tabs 1 and 2 cannot be changed.")

                if query_yes_no(u'Deleting tab {0} Confirm?'.format(num),
                                default='no'):
                    tabs.primitive_delete(course,
                                          num - 1)  # -1 for 0-based indexing
            elif options['insert']:
                num, tab_type, name = options['insert']
                num = int(num)
                if num < 3:
                    raise CommandError("Tabs 1 and 2 cannot be changed.")

                if query_yes_no(
                        u'Inserting tab {0} "{1}" "{2}" Confirm?'.format(
                            num, tab_type, name),
                        default='no'):
                    tabs.primitive_insert(course, num - 1, tab_type,
                                          name)  # -1 as above
        except ValueError as e:
            # Cute: translate to CommandError so the CLI error prints nicely.
            raise CommandError(e)
    def handle(self, *args, **options):
        if not options["course"]:
            raise CommandError(Command.course_option.help)

        try:
            course_key = CourseKey.from_string(options["course"])
        except InvalidKeyError:
            course_key = SlashSeparatedCourseKey.from_deprecated_string(options["course"])

        course = get_course_by_id(course_key)

        print "Warning: this command directly edits the list of course tabs in mongo."
        print "Tabs before any changes:"
        print_course(course)

        try:
            if options["delete"]:
                if len(args) != 1:
                    raise CommandError(Command.delete_option.help)
                num = int(args[0])
                if query_yes_no("Deleting tab {0} Confirm?".format(num), default="no"):
                    tabs.primitive_delete(course, num - 1)  # -1 for 0-based indexing
            elif options["insert"]:
                if len(args) != 3:
                    raise CommandError(Command.insert_option.help)
                num = int(args[0])
                tab_type = args[1]
                name = args[2]
                if query_yes_no('Inserting tab {0} "{1}" "{2}" Confirm?'.format(num, tab_type, name), default="no"):
                    tabs.primitive_insert(course, num - 1, tab_type, name)  # -1 as above
        except ValueError as e:
            # Cute: translate to CommandError so the CLI error prints nicely.
            raise CommandError(e)
Exemple #4
0
    def handle(self, *args, **options):
        if not options['course']:
            raise CommandError(Command.course_option.help)

        course = get_course_by_id(options['course'])

        print 'Warning: this command directly edits the list of course tabs in mongo.'
        print 'Tabs before any changes:'
        print_course(course)

        try:
            if options['delete']:
                if len(args) != 1:
                    raise CommandError(Command.delete_option.help)
                num = int(args[0])
                if query_yes_no('Deleting tab {0} Confirm?'.format(num), default='no'):
                    tabs.primitive_delete(course, num - 1)  # -1 for 0-based indexing
            elif options['insert']:
                if len(args) != 3:
                    raise CommandError(Command.insert_option.help)
                num = int(args[0])
                tab_type = args[1]
                name = args[2]
                if query_yes_no('Inserting tab {0} "{1}" "{2}" Confirm?'.format(num, tab_type, name), default='no'):
                    tabs.primitive_insert(course, num - 1, tab_type, name)  # -1 as above
        except ValueError as e:
            # Cute: translate to CommandError so the CLI error prints nicely.
            raise CommandError(e)
    def handle(self, *args, **options):
        course = get_course_by_id(CourseKey.from_string(options['course']))

        print('Warning: this command directly edits the list of course tabs in mongo.')
        print('Tabs before any changes:')
        print_course(course)

        try:
            if options['delete']:
                num = int(options['delete'][0])
                if num < 3:
                    raise CommandError("Tabs 1 and 2 cannot be changed.")

                if query_yes_no(u'Deleting tab {0} Confirm?'.format(num), default='no'):
                    tabs.primitive_delete(course, num - 1)  # -1 for 0-based indexing
            elif options['insert']:
                num, tab_type, name = options['insert']
                num = int(num)
                if num < 3:
                    raise CommandError("Tabs 1 and 2 cannot be changed.")

                if query_yes_no(u'Inserting tab {0} "{1}" "{2}" Confirm?'.format(num, tab_type, name), default='no'):
                    tabs.primitive_insert(course, num - 1, tab_type, name)  # -1 as above
        except ValueError as e:
            # Cute: translate to CommandError so the CLI error prints nicely.
            raise CommandError(e)
Exemple #6
0
 def test_save(self):
     """Test course saving."""
     course = CourseFactory.create()
     tabs.primitive_insert(course, 3, 'pdf_textbooks', 'aname')
     course2 = modulestore().get_course(course.id)
     self.assertEqual(course2.tabs[3], {
         'type': 'pdf_textbooks',
         'name': 'aname'
     })
 def test_insert(self):
     """Test primitive tab insertion."""
     course = CourseFactory.create()
     tabs.primitive_insert(course, 2, 'notes', 'aname')
     self.assertEquals(course.tabs[2], {'type': 'notes', 'name': 'aname'})
     with self.assertRaises(ValueError):
         tabs.primitive_insert(course, 0, 'notes', 'aname')
     with self.assertRaises(ValueError):
         tabs.primitive_insert(course, 3, 'static_tab', 'aname')
 def test_insert(self):
     """Test primitive tab insertion."""
     course = CourseFactory.create()
     tabs.primitive_insert(course, 2, 'notes', 'aname')
     self.assertEquals(course.tabs[2], {'type': 'notes', 'name': 'aname'})
     with self.assertRaises(ValueError):
         tabs.primitive_insert(course, 0, 'notes', 'aname')
     with self.assertRaises(ValueError):
         tabs.primitive_insert(course, 3, 'static_tab', 'aname')
Exemple #9
0
 def test_insert(self):
     """Test primitive tab insertion."""
     course = CourseFactory.create(org="edX", course="999")
     tabs.primitive_insert(course, 2, "notes", "aname")
     self.assertEquals(course.tabs[2], {"type": "notes", "name": "aname"})
     with self.assertRaises(ValueError):
         tabs.primitive_insert(course, 0, "notes", "aname")
     with self.assertRaises(ValueError):
         tabs.primitive_insert(course, 3, "static_tab", "aname")
 def test_save(self):
     """Test course saving."""
     course = CourseFactory.create()
     tabs.primitive_insert(course, 3, 'notes', 'aname')
     course2 = modulestore().get_course(course.id)
     self.assertEquals(course2.tabs[3], {'type': 'notes', 'name': 'aname'})
Exemple #11
0
 def test_save(self):
     """Test course saving."""
     course = CourseFactory.create(org='edX', course='999')
     tabs.primitive_insert(course, 3, 'notes', 'aname')
     course2 = get_course_by_id(course.id)
     self.assertEquals(course2.tabs[3], {'type': 'notes', 'name': 'aname'})
Exemple #12
0
 def test_save(self):
     """Test course saving."""
     course = CourseFactory.create(org='edX', course='999')
     tabs.primitive_insert(course, 3, 'notes', 'aname')
     course2 = modulestore().get_course(course.id)
     self.assertEquals(course2.tabs[3], {'type': 'notes', 'name': 'aname'})
Exemple #13
0
 def test_save(self):
     """Test course saving."""
     course = CourseFactory.create(org="edX", course="999")
     tabs.primitive_insert(course, 3, "notes", "aname")
     course2 = get_course_by_id(course.id)
     self.assertEquals(course2.tabs[3], {"type": "notes", "name": "aname"})