Ticket #8348: 8348-default_to_all_apps.diff

File 8348-default_to_all_apps.diff, 8.2 KB (added by Graham King, 16 years ago)

Makes all the command that take a list of apps default to all the apps if none are given on the command line

  • django/core/management/commands/sqlall.py

     
    11from django.core.management.base import AppCommand
    22
    33class Command(AppCommand):
    4     help = "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s)."
     4    help = "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given "+\
     5            "app name(s), or all the apps if none specified."
    56
    67    output_transaction = True
    78
  • django/core/management/commands/sqlcustom.py

     
    11from django.core.management.base import AppCommand
    22
    33class Command(AppCommand):
    4     help = "Prints the custom table modifying SQL statements for the given app name(s)."
     4    help = "Prints the custom table modifying SQL statements for the given app name(s), "+ \
     5            "or all the apps if none specified."
    56
    67    output_transaction = True
    78
  • django/core/management/commands/sqlsequencereset.py

     
    11from django.core.management.base import AppCommand
    22
    33class Command(AppCommand):
    4     help = 'Prints the SQL statements for resetting sequences for the given app name(s).'
     4    help = "Prints the SQL statements for resetting sequences for the given app name(s), "+ \
     5            "or all the apps if none specified."
    56    output_transaction = True
    67
    78    def handle_app(self, app, **options):
  • django/core/management/commands/sql.py

     
    11from django.core.management.base import AppCommand
    22
    33class Command(AppCommand):
    4     help = "Prints the CREATE TABLE SQL statements for the given app name(s)."
     4    help = "Prints the CREATE TABLE SQL statements for the given app name(s), "+ \
     5            "or all the apps if none specified."
    56
    67    output_transaction = True
    78
  • django/core/management/commands/sqlreset.py

     
    11from django.core.management.base import AppCommand
    22
    33class Command(AppCommand):
    4     help = "Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given app name(s)."
     4    help = "Prints the DROP TABLE SQL, then the CREATE TABLE SQL, for the given app name(s), "+ \
     5            "or all the apps if none specified."
    56
    67    output_transaction = True
    78
  • django/core/management/commands/sqlclear.py

     
    11from django.core.management.base import AppCommand
    22
    33class Command(AppCommand):
    4     help = "Prints the DROP TABLE SQL statements for the given app name(s)."
     4    help = "Prints the DROP TABLE SQL statements for the given app name(s), "+ \
     5            "or all the apps if none specified."
    56
    67    output_transaction = True
    78
  • django/core/management/commands/sqlindexes.py

     
    11from django.core.management.base import AppCommand
    22
    33class Command(AppCommand):
    4     help = "Prints the CREATE INDEX SQL statements for the given model module name(s)."
     4    help = "Prints the CREATE INDEX SQL statements for the given app name(s), "+ \
     5            "or all the apps if none specified."
    56
    67    output_transaction = True
    78
  • django/core/management/commands/reset.py

     
    77        make_option('--noinput', action='store_false', dest='interactive', default=True,
    88            help='Tells Django to NOT prompt the user for input of any kind.'),
    99    )
    10     help = "Executes ``sqlreset`` for the given app(s) in the current database."
     10    help = "Executes ``sqlreset`` for the given app(s) in the current database, "+ \
     11            "or all the apps if none specified."
    1112    args = '[appname ...]'
    1213
    1314    output_transaction = True
  • django/core/management/base.py

     
    1111import django
    1212from django.core.exceptions import ImproperlyConfigured
    1313from django.core.management.color import color_style
     14from django.conf import settings
    1415
    1516try:
    1617    set
     
    271272    ``handle_app()``, which will be called once for each application.
    272273   
    273274    """
    274     args = '<appname appname ...>'
     275    args = '[appname appname ...]'
    275276
    276277    def handle(self, *app_labels, **options):
    277278        from django.db import models
    278         if not app_labels:
    279             raise CommandError('Enter at least one appname.')
     279       
     280        if not app_labels:    # If no app given default to all apps
     281            for full_app_name in settings.INSTALLED_APPS:
     282                if full_app_name.startswith('django.contrib'):
     283                    candidate_label = full_app_name[ len('django.contrib.'): ]
     284                else:
     285                    candidate_label =  full_app_name
     286                try:
     287                    models.get_app(candidate_label)
     288                    app_labels += (candidate_label,)
     289                except ImproperlyConfigured:
     290                    # No models in this app, so skip it
     291                    pass
     292       
    280293        try:
    281294            app_list = [models.get_app(app_label) for app_label in app_labels]
    282295        except (ImproperlyConfigured, ImportError), e:
  • tests/regressiontests/admin_scripts/tests.py

     
    914914        args = ['sqlall','--help']
    915915        out, err = self.run_manage(args)
    916916        self.assertNoOutput(err)
    917         self.assertOutput(out, "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).")
     917        self.assertOutput(out, "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL "+\
     918                          "statements for the given app name(s), or all the apps if none specified")
    918919
    919920    def test_base_command(self):
    920921        "User BaseCommands can execute when a label is provided"
     
    974975        self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
    975976
    976977    def test_app_command_no_apps(self):
    977         "User AppCommands raise an error when no app name is provided"
     978        "User AppCommands defaults to all the apps when no app name is provided"
    978979        args = ['app_command']
    979980        out, err = self.run_manage(args)
    980         self.assertOutput(err, 'Error: Enter at least one appname.')
     981        self.assertNoOutput(err)
     982        self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.auth.models'")
     983        self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.contenttypes.models'")
     984        self.assertOutput(out, "EXECUTE:AppCommand app=<module 'admin_scripts.models'")
    981985
    982986    def test_app_command_multiple_apps(self):
    983987        "User AppCommands raise an error when multiple app names are provided"
Back to Top