def test__clean_class_objects(self): """Runs the models._clean_class_objects function.""" # This function returns the number of ojects saved/cleaned obj = JanitorTestModel(content="<p><x>Foo</x></p>") obj.save() self.assertEqual(_clean_class_objects([JanitorTestModel]), 1)
def handle_label(self, label, **options): try: app_label, model = label.lower().split('.') except ValueError: raise CommandError( "Invalid app_label.model_name: {0}".format(label) ) self.stdout.write("\nCleaning {0}.{1}\n".format(app_label, model)) qs = FieldSanitizer.objects.filter( content_type__app_label=app_label, content_type__model=model ) try: assert qs.count() > 0 except AssertionError: raise CommandError("It looks like there are no FieldSanitizers " "defined for {0}.{1}".format(app_label, model) ) klass_list = [fs.content_type.model_class() for fs in qs] object_count = _clean_class_objects(klass_list) self.stdout.write("Cleaned {0} Objects\n".format(object_count))
def handle_noargs(self, **options): sanitizers = FieldSanitizer.objects.all() klass_list = [fs.content_type.model_class() for fs in sanitizers] object_count = _clean_class_objects(klass_list) self.stdout.write("\nCleaned {0} Objects\n".format(object_count))
def handle(self, *args, **options): sanitizers = FieldSanitizer.objects.all() klass_list = [fs.content_type.model_class() for fs in sanitizers] updated = _clean_class_objects(klass_list) self.stdout.write("\nCleaned {0} Objects\n".format(updated))