Skip to content

Commit

Permalink
Merge pull request #362 from goodtune/fix-basetenantcommand
Browse files Browse the repository at this point in the history
Fix BaseTenantCommand to correctly add arguments from COMMAND_NAME
  • Loading branch information
goodtune committed Aug 22, 2016
2 parents 2bcacb6 + 515ef03 commit 9d72566
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions tenant_schemas/management/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,30 @@ def __new__(cls, *args, **kwargs):
app_name = get_commands()[obj.COMMAND_NAME]
if isinstance(app_name, BaseCommand):
# If the command is already loaded, use it directly.
cmdclass = app_name
obj._original_command = app_name
else:
cmdclass = load_command_class(app_name, obj.COMMAND_NAME)
obj._original_command = load_command_class(app_name, obj.COMMAND_NAME)

# prepend the command's original help with the info about schemata
# iteration
obj.help = (
"Calls {cmd} for all registered schemata. You can use regular "
"{cmd} options.\n\nOriginal help for {cmd}:\n\n{help}".format(
cmd=obj.COMMAND_NAME,
help=getattr(obj._original_command, 'help', 'none'),
)
)

# prepend the command's original help with the info about schemata iteration
obj.help = "Calls %s for all registered schemata. You can use regular %s options. " \
"Original help for %s: %s" % (obj.COMMAND_NAME, obj.COMMAND_NAME, obj.COMMAND_NAME,
getattr(cmdclass, 'help', 'none'))
return obj

def add_arguments(self, parser):
super(BaseTenantCommand, self).add_arguments(parser)
parser.add_argument("-s", "--schema", dest="schema_name")
parser.add_argument("-p", "--skip-public", dest="skip_public", action="store_true", default=False)
parser.add_argument("-p", "--skip-public", dest="skip_public",
action="store_true", default=False)
# use the privately held reference to the underlying command to invoke
# the add_arguments path on this parser instance
self._original_command.add_arguments(parser)

def execute_command(self, tenant, command_name, *args, **options):
verbosity = int(options.get('verbosity'))
Expand Down

0 comments on commit 9d72566

Please sign in to comment.