Django

Code

Ticket #2333: core.patch

File core.patch, 4.4 kB (added by russellm, 4 years ago)

Changes to the django.core package

  • core/management.py

    old new  
    420420get_sql_all.help_doc = "Prints the CREATE TABLE, initial-data and CREATE INDEX SQL statements for the given model module name(s)." 
    421421get_sql_all.args = APP_ARGS 
    422422 
    423 def syncdb(): 
     423def syncdb(verbosity=2, interactive=True): 
    424424    "Creates the database tables for all apps in INSTALLED_APPS whose tables haven't already been created." 
    425425    from django.db import connection, transaction, models, get_creation_module 
    426426    from django.db.models import signals 
     
    468468                except KeyError: 
    469469                    pending_references[refto] = refs 
    470470            sql.extend(_get_sql_for_pending_references(model, pending_references)) 
    471             print "Creating table %s" % model._meta.db_table 
     471            if verbosity >= 2: 
     472                print "Creating table %s" % model._meta.db_table 
    472473            for statement in sql: 
    473474                cursor.execute(statement) 
    474475            table_list.append(model._meta.db_table) 
     
    477478            if model in created_models: 
    478479                sql = _get_many_to_many_sql_for_model(model) 
    479480                if sql: 
    480                     print "Creating many-to-many tables for %s model" % model.__name__ 
     481                    if verbosity >= 2: 
     482                        print "Creating many-to-many tables for %s model" % model.__name__ 
    481483                    for statement in sql: 
    482484                        cursor.execute(statement) 
    483485 
     
    487489    # to do at this point. 
    488490    for app in models.get_apps(): 
    489491        dispatcher.send(signal=signals.post_syncdb, sender=app, 
    490             app=app, created_models=created_models) 
     492            app=app, created_models=created_models,  
     493            verbosity=verbosity, interactive=interactive) 
    491494 
    492495        # Install initial data for the app (but only if this is a model we've 
    493496        # just created) 
     
    11351138    runfastcgi(args) 
    11361139runfcgi.args = '[various KEY=val options, use `runfcgi help` for help]' 
    11371140 
     1141def test(verbosity, app_labels): 
     1142    "Runs the test suite for the specified applications" 
     1143    from django.conf import settings 
     1144    from django.db.models import get_app, get_apps 
     1145 
     1146    if len(app_labels) == 0: 
     1147        app_list = get_apps() 
     1148    else: 
     1149        app_list = [get_app(app_label) for app_label in app_labels] 
     1150     
     1151    test_module = __import__(settings.TEST_MODULE, [],[],'*') 
     1152    test_runner = getattr(test_module, settings.TEST_RUNNER) 
     1153     
     1154    test_runner(app_list, verbosity) 
     1155     
     1156test.help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified' 
     1157test.args = '[--verbosity] ' + APP_ARGS 
     1158 
    11381159# Utilities for command-line script 
    11391160 
    11401161DEFAULT_ACTION_MAPPING = { 
     
    11591180    'startproject': startproject, 
    11601181    'syncdb': syncdb, 
    11611182    'validate': validate, 
     1183    'test':test, 
    11621184} 
    11631185 
    11641186NO_SQL_TRANSACTION = ( 
     
    12091231        help='Lets you manually add a directory the Python path, e.g. "/home/djangoprojects/myproject".') 
    12101232    parser.add_option('--plain', action='store_true', dest='plain', 
    12111233        help='Tells Django to use plain Python, not IPython, for "shell" command.') 
     1234    parser.add_option('-v','--verbosity', action='store', dest='verbosity', default='1', 
     1235        type='choice', choices=['0', '1', '2'], 
     1236        help='Verbosity level; 0=minimal output, 1=normal output, 2=all output') 
     1237         
    12121238    options, args = parser.parse_args(argv[1:]) 
    12131239 
    12141240    # Take care of options. 
     
    12351261 
    12361262    if action == 'shell': 
    12371263        action_mapping[action](options.plain is True) 
    1238     elif action in ('syncdb', 'validate', 'diffsettings', 'dbshell'): 
     1264    elif action in ('validate', 'diffsettings', 'dbshell'): 
    12391265        action_mapping[action]() 
     1266    elif action == 'syncdb': 
     1267        action_mapping[action](int(options.verbosity)) 
    12401268    elif action == 'inspectdb': 
    12411269        try: 
    12421270            for line in action_mapping[action](): 
     
    12491277            action_mapping[action](args[1]) 
    12501278        except IndexError: 
    12511279            parser.print_usage_and_exit() 
     1280    elif action == 'test': 
     1281        try: 
     1282            action_mapping[action](int(options.verbosity), args[1:]) 
     1283        except IndexError: 
     1284            parser.print_usage_and_exit() 
    12521285    elif action in ('startapp', 'startproject'): 
    12531286        try: 
    12541287            name = args[1]