예제 #1
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(f'Deleting tab {num} Confirm?', 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(
                        f'Inserting tab {num} "{tab_type}" "{name}" Confirm?',
                        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)  # lint-amnesty, pylint: disable=raise-missing-from
예제 #2
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'
     })
예제 #3
0
 def test_insert(self):
     """Test primitive tab insertion."""
     course = CourseFactory.create()
     tabs.primitive_insert(course, 2, 'pdf_textbooks', 'aname')
     self.assertEqual(course.tabs[2], {'type': 'pdf_textbooks', 'name': 'aname'})
     with self.assertRaises(ValueError):
         tabs.primitive_insert(course, 0, 'pdf_textbooks', 'aname')
     with self.assertRaises(ValueError):
         tabs.primitive_insert(course, 3, 'static_tab', 'aname')