Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #12339 -- Made content type deletion an interactive process to …

…prevent accidentally cascade deleting content from a production database. Thanks to kcarnold for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12782 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 45a56e637ea5e356b2f276a7ddbb4335f3c39b35 1 parent beca4b8
@freakboy3742 freakboy3742 authored
Showing with 27 additions and 9 deletions.
  1. +27 −9 django/contrib/contenttypes/management.py
View
36 django/contrib/contenttypes/management.py
@@ -25,16 +25,34 @@ def update_contenttypes(app, created_models, verbosity=2, **kwargs):
if verbosity >= 2:
print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
# The presence of any remaining content types means the supplied app has an
- # undefined model and can safely be removed, which cascades to also remove
- # related permissions.
- for ct in content_types:
- if verbosity >= 2:
- print "Deleting stale content type '%s | %s'" % (ct.app_label, ct.model)
- ct.delete()
-
-def update_all_contenttypes(verbosity=2):
+ # undefined model. Confirm that the content type is stale before deletion.
+ if content_types:
+ if kwargs.get('interactive', False):
+ content_type_display = '\n'.join([' %s | %s' % (ct.app_label, ct.model) for ct in content_types])
+ ok_to_delete = raw_input("""The following content types are stale and need to be deleted:
+
+%s
+
+Any objects related to these content types by a foreign key will also
+be deleted. Are you sure you want to delete these content types?
+If you're unsure, answer 'no'.
+
+ Type 'yes' to continue, or 'no' to cancel: """ % content_type_display)
+ else:
+ ok_to_delete = False
+
+ if ok_to_delete == 'yes':
+ for ct in content_types:
+ if verbosity >= 2:
+ print "Deleting stale content type '%s | %s'" % (ct.app_label, ct.model)
+ ct.delete()
+ else:
+ if verbosity >= 2:
+ print "Stale content types remain."
+
+def update_all_contenttypes(verbosity=2, **kwargs):
for app in get_apps():
- update_contenttypes(app, None, verbosity)
+ update_contenttypes(app, None, verbosity, **kwargs)
signals.post_syncdb.connect(update_contenttypes)
Please sign in to comment.
Something went wrong with that request. Please try again.