web/lib/django/core/management/commands/reset.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
equal deleted inserted replaced
28:b758351d191f 29:cc9b7e14412b
       
     1 from optparse import make_option
       
     2 
       
     3 from django.conf import settings
     1 from django.core.management.base import AppCommand, CommandError
     4 from django.core.management.base import AppCommand, CommandError
     2 from django.core.management.color import no_style
     5 from django.core.management.color import no_style
     3 from optparse import make_option
     6 from django.core.management.sql import sql_reset
       
     7 from django.db import connections, transaction, DEFAULT_DB_ALIAS
     4 
     8 
     5 class Command(AppCommand):
     9 class Command(AppCommand):
     6     option_list = AppCommand.option_list + (
    10     option_list = AppCommand.option_list + (
     7         make_option('--noinput', action='store_false', dest='interactive', default=True,
    11         make_option('--noinput', action='store_false', dest='interactive', default=True,
     8             help='Tells Django to NOT prompt the user for input of any kind.'),
    12             help='Tells Django to NOT prompt the user for input of any kind.'),
       
    13         make_option('--database', action='store', dest='database',
       
    14             default=DEFAULT_DB_ALIAS, help='Nominates a database to reset. '
       
    15                 'Defaults to the "default" database.'),
     9     )
    16     )
    10     help = "Executes ``sqlreset`` for the given app(s) in the current database."
    17     help = "Executes ``sqlreset`` for the given app(s) in the current database."
    11     args = '[appname ...]'
    18     args = '[appname ...]'
    12 
    19 
    13     output_transaction = True
    20     output_transaction = True
    14 
    21 
    15     def handle_app(self, app, **options):
    22     def handle_app(self, app, **options):
    16         from django.db import connection, transaction
    23         using = options.get('database', DEFAULT_DB_ALIAS)
    17         from django.conf import settings
    24         connection = connections[using]
    18         from django.core.management.sql import sql_reset
       
    19 
    25 
    20         app_name = app.__name__.split('.')[-2]
    26         app_name = app.__name__.split('.')[-2]
    21 
       
    22         self.style = no_style()
    27         self.style = no_style()
    23 
    28 
    24         sql_list = sql_reset(app, self.style)
    29         sql_list = sql_reset(app, self.style, connection)
    25 
    30 
    26         if options.get('interactive'):
    31         if options.get('interactive'):
    27             confirm = raw_input("""
    32             confirm = raw_input("""
    28 You have requested a database reset.
    33 You have requested a database reset.
    29 This will IRREVERSIBLY DESTROY any data for
    34 This will IRREVERSIBLY DESTROY any data for
    30 the "%s" application in the database "%s".
    35 the "%s" application in the database "%s".
    31 Are you sure you want to do this?
    36 Are you sure you want to do this?
    32 
    37 
    33 Type 'yes' to continue, or 'no' to cancel: """ % (app_name, settings.DATABASE_NAME))
    38 Type 'yes' to continue, or 'no' to cancel: """ % (app_name, connection.settings_dict['NAME']))
    34         else:
    39         else:
    35             confirm = 'yes'
    40             confirm = 'yes'
    36 
    41 
    37         if confirm == 'yes':
    42         if confirm == 'yes':
    38             try:
    43             try: