Ticket #8348: 8343-prompt.diff
File 8343-prompt.diff, 4.9 KB (added by , 16 years ago) |
---|
-
django/db/backends/util.py
45 45 def __iter__(self): 46 46 return iter(self.cursor) 47 47 48 class CursorInteractiveWrapper(object): 49 def __init__(self, cursor, db): 50 self.cursor = cursor 51 self.db = db # Instance of a BaseDatabaseWrapper subclass 52 53 def _confirm(self, sql, params): 54 """Ask the user whether to execute this SQL""" 55 if sql and not sql.lower().startswith("select") and not sql.lower().startswith("show"): 56 print sql 57 if params: 58 print "PARAMS:", params 59 answer = raw_input("Execute this [y/N]?") 60 print '-'*20 61 if not answer or answer.lower() != 'y': 62 return False 63 return True 64 65 def execute(self, sql, params=()): 66 if self._confirm(sql, params): 67 return self.cursor.execute(sql, params) 68 else: 69 return None 70 71 def executemany(self, sql, param_list): 72 if self._confirm(sql, param_list): 73 return self.cursor.executemany(sql, param_list) 74 else: 75 return None 76 77 def __getattr__(self, attr): 78 if attr in self.__dict__: 79 return self.__dict__[attr] 80 else: 81 return getattr(self.cursor, attr) 82 83 def __iter__(self): 84 return iter(self.cursor) 85 48 86 ############################################### 49 87 # Converters from database (string) to Python # 50 88 ############################################### -
django/db/backends/__init__.py
28 28 self.connection = None 29 29 self.queries = [] 30 30 self.options = kwargs 31 31 self.is_interactive = False 32 32 33 def _commit(self): 33 34 if self.connection is not None: 34 35 return self.connection.commit() … … 58 59 self.connection = None 59 60 60 61 def cursor(self): 61 from django.conf import settings 62 from django.conf import settings 62 63 cursor = self._cursor(settings) 63 64 if settings.DEBUG: 64 return self.make_debug_cursor(cursor) 65 cursor = self.make_debug_cursor(cursor) 66 if self.is_interactive: 67 cursor = self.make_interactive_cursor(cursor) 65 68 return cursor 66 69 67 70 def make_debug_cursor(self, cursor): 68 71 return util.CursorDebugWrapper(cursor, self) 69 72 73 def make_interactive_cursor(self, cursor): 74 return util.CursorInteractiveWrapper(cursor, self) 75 70 76 class BaseDatabaseFeatures(object): 71 77 allows_group_by_pk = False 72 78 # True if django.db.backend.utils.typecast_timestamp is used on values -
django/core/management/commands/syncdb.py
12 12 option_list = NoArgsCommand.option_list + ( 13 13 make_option('--noinput', action='store_false', dest='interactive', default=True, 14 14 help='Tells Django to NOT prompt the user for input of any kind.'), 15 make_option('--prompt', action='store_true', dest='prompt', default=False, 16 help='Show each SQL statement before executing, and prompt whether to run it') 15 17 ) 16 18 help = "Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created." 17 19 … … 23 25 verbosity = int(options.get('verbosity', 1)) 24 26 interactive = options.get('interactive') 25 27 show_traceback = options.get('traceback', False) 28 connection.is_interactive = options.get('prompt', False) 26 29 27 30 self.style = no_style() 28 31 -
docs/ref/django-admin.txt
665 665 "Are you sure?" confirmation messages. This is useful if ``django-admin.py`` 666 666 is being executed as an unattended, automated script. 667 667 668 --prompt 669 ~~~~~~~~ 670 .. versionadded:: 1.1 671 672 Use the ``--prompt`` option to be prompted before each line of SQL that changes data 673 gets executed (i.e. you won't get prompted for SELECT statement). The SQL will be displayed along 674 with a yes or no prompt, and if you say no that line of SQL will not get executed. 675 676 Note that some of the SQL will depend on previous statements having been executed. For example, 677 if you say no to the SQL to create a table, then yes to the SQL to insert into it, 678 you're on your own. 679 680 If you say both ``--noinput`` and ``--prompt``, you wil get prompted. Don't use both. 681 668 682 test 669 683 ---- 670 684