def handle(self, *args, **options): confirm = raw_input( 'This is a DESTRUCTIVE action. Are you sure? [y/N]: ') if confirm == 'y': # start with Organization, as this will cascade heavily print "=====================" print "Deleting Organizations" self.delete_objects_of_class(Organization, retain=100) print print "=====================" print "Deleting Content Types" print for k, ctKlass in CONTENT_TYPES.items(): self.delete_objects_of_class(ctKlass) print print "=====================" print "Deleting Linked Objects and Metadata" class_list = [ Image, File, Website, Author, AcademicDiscipline, InstitutionalOffice, ProgramType, ConferenceName, PresentationType, CourseMaterialType, OutreachMaterialType, PublicationMaterialType ] for klass in class_list: self.delete_objects_of_class(klass) print print "=====================" print "Removing thumbnails" self.delete_objects_of_class(KVStore, retain=0) print print "=====================" print "Removing all Sessions" self.delete_objects_of_class(Session, retain=0) print print "=====================" print "Removing all users who aren't staff/aashe" to_delete = User.objects.filter(is_staff=False) print "Deleting %d of %d Users" % (to_delete.count(), User.objects.count()) for obj in to_delete: obj.delete() print print "=====================" print "Deleting Admin Log Entries" self.delete_objects_of_class(LogEntry, retain=100) print else: print "Action Cancelled."
def handle(self, *args, **options): confirm = raw_input( 'This is a DESTRUCTIVE action. Are you sure? [y/N]: ') if confirm == 'y': # start with Organization, as this will cascade heavily print "=====================" print "Deleting Organizations" self.delete_objects_of_class(Organization, retain=100) print print "=====================" print "Deleting Content Types" print for k, ctKlass in CONTENT_TYPES.items(): self.delete_objects_of_class(ctKlass) print print "=====================" print "Deleting Linked Objects and Metadata" class_list = [ Image, File, Website, Author, AcademicDiscipline, InstitutionalOffice, ProgramType, ConferenceName, PresentationType, CourseMaterialType, OutreachMaterialType, PublicationMaterialType] for klass in class_list: self.delete_objects_of_class(klass) print print "=====================" print "Removing thumbnails" self.delete_objects_of_class(KVStore, retain=0) print print "=====================" print "Removing all Sessions" self.delete_objects_of_class(Session, retain=0) print print "=====================" print "Removing all users who aren't staff/aashe" to_delete = User.objects.filter(is_staff=False) print "Deleting %d of %d Users" % ( to_delete.count(), User.objects.count()) for obj in to_delete: obj.delete() print print "=====================" print "Deleting Admin Log Entries" self.delete_objects_of_class(LogEntry, retain=100) print else: print "Action Cancelled."
def test_admin_urls(self): """ Create each content type and then get the admin_url """ for key, klass in CONTENT_TYPES.items(): prop_dict = self.generic_properties.copy() prop_dict.update({ 'content_type': key, }) if key in self.ct_specific_fields.keys(): prop_dict.update(self.ct_specific_fields[key]) ct = klass.objects.create(**prop_dict) # just make sure no exceptions are raised url = ct.get_admin_url()
""" fix_newlines.py When importing from the old IRC, I didn't parse all the newlines to double them up so that they would appear as new paragraphs with markdown. Doing that here. """ from hub.apps.content.models import CONTENT_TYPES from hub.apps.content.types.casestudies import CaseStudy import pdb for k, ct_class in CONTENT_TYPES.items(): # Get the TextFields text_fields = [] for f in ct_class._meta.fields: if f.__class__.__name__ == "TextField": text_fields.append(f.name) for ct in ct_class.objects.all(): for field_name in text_fields: text = getattr(ct, field_name) if text: new_text = text.replace("\n", "\n\n") setattr(ct, field_name, new_text) ct.save()