Ticket #10080: 10080-2.diff

File 10080-2.diff, 1.6 KB (added by Claude Paroz, 13 years ago)

Also fill defaults dict with options without defaults

  • django/core/management/__init__.py

    diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
    index 6edb0ba..16b27c8 100644
    a b def call_command(name, *args, **options):  
    140140    # when the script runs from the command line, but since call_command can
    141141    # be called programatically, we need to simulate the loading and handling
    142142    # of defaults (see #10080 for details).
    143     defaults = dict([(o.dest, o.default)
    144                      for o in klass.option_list
    145                      if o.default is not NO_DEFAULT])
     143    defaults = {}
     144    for opt in klass.option_list:
     145        if opt.default is not NO_DEFAULT:
     146            defaults[opt.dest] = opt.default
     147        else:
     148            defaults[opt.dest] = None
    146149    defaults.update(options)
    147150
    148151    return klass.execute(*args, **defaults)
  • tests/modeltests/user_commands/management/commands/dance.py

    diff --git a/tests/modeltests/user_commands/management/commands/dance.py b/tests/modeltests/user_commands/management/commands/dance.py
    index 34eb277..4ad5579 100644
    a b class Command(BaseCommand):  
    99    requires_model_validation = True
    1010
    1111    option_list =[
    12         make_option("-s", "--style", default="Rock'n'Roll")
     12        make_option("-s", "--style", default="Rock'n'Roll"),
     13        make_option("-x", "--example")
    1314    ]
    1415
    1516    def handle(self, *args, **options):
     17        example = options["example"]
    1618        self.stdout.write("I don't feel like dancing %s." % options["style"])
Back to Top