~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to django/contrib/contenttypes/management.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
            if verbosity >= 2:
26
26
                print "Adding content type '%s | %s'" % (ct.app_label, ct.model)
27
27
    # The presence of any remaining content types means the supplied app has an
28
 
    # undefined model and can safely be removed, which cascades to also remove
29
 
    # related permissions.
30
 
    for ct in content_types:
31
 
        if verbosity >= 2:
32
 
            print "Deleting stale content type '%s | %s'" % (ct.app_label, ct.model)
33
 
        ct.delete()
34
 
 
35
 
def update_all_contenttypes(verbosity=2):
 
28
    # undefined model. Confirm that the content type is stale before deletion.
 
29
    if content_types:
 
30
        if kwargs.get('interactive', False):
 
31
            content_type_display = '\n'.join(['    %s | %s' % (ct.app_label, ct.model) for ct in content_types])
 
32
            ok_to_delete = raw_input("""The following content types are stale and need to be deleted:
 
33
 
 
34
%s
 
35
 
 
36
Any objects related to these content types by a foreign key will also
 
37
be deleted. Are you sure you want to delete these content types?
 
38
If you're unsure, answer 'no'.
 
39
 
 
40
    Type 'yes' to continue, or 'no' to cancel: """ % content_type_display)
 
41
        else:
 
42
            ok_to_delete = False
 
43
 
 
44
        if ok_to_delete == 'yes':
 
45
            for ct in content_types:
 
46
                if verbosity >= 2:
 
47
                    print "Deleting stale content type '%s | %s'" % (ct.app_label, ct.model)
 
48
                ct.delete()
 
49
        else:
 
50
            if verbosity >= 2:
 
51
                print "Stale content types remain."
 
52
 
 
53
def update_all_contenttypes(verbosity=2, **kwargs):
36
54
    for app in get_apps():
37
 
        update_contenttypes(app, None, verbosity)
 
55
        update_contenttypes(app, None, verbosity, **kwargs)
38
56
 
39
57
signals.post_syncdb.connect(update_contenttypes)
40
58