Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added ability to use --noinput flag for application reset.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3888 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b5a712240823f84e76172b729393123e9ac2f38d 1 parent bf6257f
Russell Keith-Magee authored October 03, 2006

Showing 1 changed file with 12 additions and 6 deletions. Show diff stats Hide diff stats

  1. 18  django/core/management.py
18  django/core/management.py
@@ -103,7 +103,6 @@ def get_sql_create(app):
103 103
     known_models = set([model for model in _get_installed_models(_get_table_list()) if model not in app_models])
104 104
     pending_references = {}
105 105
 
106  
-
107 106
     for model in app_models:
108 107
         output, references = _get_sql_model_create(model, known_models)
109 108
         final_output.extend(output)
@@ -596,7 +595,7 @@ def install(app):
596 595
 install.help_doc = "Executes ``sqlall`` for the given app(s) in the current database."
597 596
 install.args = APP_ARGS
598 597
 
599  
-def reset(app):
  598
+def reset(app, interactive=True):
600 599
     "Executes the equivalent of 'get_sql_reset' in the current database."
601 600
     from django.db import connection, transaction
602 601
     app_name = app.__name__.split('.')[-2]
@@ -607,21 +606,25 @@ def reset(app):
607 606
     _check_for_validation_errors(app)
608 607
     sql_list = get_sql_reset(app)
609 608
 
610  
-    confirm = raw_input("""
  609
+    if interactive:
  610
+        confirm = raw_input("""
611 611
 You have requested a database reset.
612 612
 This will IRREVERSIBLY DESTROY any data in your database.
613 613
 Are you sure you want to do this?
614 614
 
615 615
 Type 'yes' to continue, or 'no' to cancel: """)
  616
+    else:
  617
+        confirm = 'yes'
  618
+        
616 619
     if confirm == 'yes':
617 620
         try:
618 621
             cursor = connection.cursor()
619 622
             for sql in sql_list:
620 623
                 cursor.execute(sql)
621 624
         except Exception, e:
622  
-            sys.stderr.write(style.ERROR("""Error: %s couldn't be installed. Possible reasons:
  625
+            sys.stderr.write(style.ERROR("""Error: %s couldn't be reset. Possible reasons:
623 626
   * The database isn't running or isn't configured correctly.
624  
-  * At least one of the database tables already exists.
  627
+  * At least one of the database tables doesn't exist.
625 628
   * The SQL was invalid.
626 629
 Hint: Look at the output of 'django-admin.py sqlreset %s'. That's the SQL this command wasn't able to run.
627 630
 The full error: """ % (app_name, app_name)) + style.ERROR_OUTPUT(str(e)) + '\n')
@@ -1361,7 +1364,10 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
1361 1364
         if action not in NO_SQL_TRANSACTION:
1362 1365
             print style.SQL_KEYWORD("BEGIN;")
1363 1366
         for mod in mod_list:
1364  
-            output = action_mapping[action](mod)
  1367
+            if action == 'reset':
  1368
+                output = action_mapping[action](mod, options.interactive)
  1369
+            else:
  1370
+                output = action_mapping[action](mod)
1365 1371
             if output:
1366 1372
                 print '\n'.join(output)
1367 1373
         if action not in NO_SQL_TRANSACTION:

0 notes on commit b5a7122

Please sign in to comment.
Something went wrong with that request. Please try again.