3 |
3 |
# Email: carneiro.be@gmail.com
|
4 |
4 |
# License: MIT license
|
5 |
5 |
# Home-page: http://github.com/bcarneiro/django-tenant-schemas
|
|
6 |
|
6 |
7 |
import argparse
|
|
8 |
|
|
9 |
from django.conf import settings
|
7 |
10 |
from django.core.management.base import BaseCommand, CommandError
|
8 |
11 |
from django.core.management import call_command, get_commands, load_command_class
|
9 |
12 |
from django.db import connection
|
... | ... | |
15 |
18 |
help = "Wrapper around django commands for use with an individual tenant"
|
16 |
19 |
args = '<other_command>'
|
17 |
20 |
|
18 |
|
def run_from_argv(self, argv):
|
|
21 |
def run_from_argv(self, argv, **kwargs):
|
19 |
22 |
"""
|
20 |
23 |
Changes the option_list to use the options from the wrapped command.
|
21 |
24 |
Adds schema parameter to specify which schema will be used when
|
... | ... | |
40 |
43 |
args_parser.add_argument("--all-tenants", help="apply command to all tenants",
|
41 |
44 |
action='store_true')
|
42 |
45 |
args_parser.add_argument("-d", "--domain", dest="domain_name", help="specify tenant domain name")
|
|
46 |
args_parser.add_argument(
|
|
47 |
'--force-job', dest='force_job', action='store_true',
|
|
48 |
help='Run command even if DISABLE_CRON_JOBS is set' )
|
43 |
49 |
args_namespace, args = args_parser.parse_known_args(argv)
|
44 |
50 |
|
|
51 |
if args_namespace.all_tenants and not args_namespace.force_job \
|
|
52 |
and getattr(settings, 'DISABLE_CRON_JOBS', False):
|
|
53 |
if kwargs.get('verbosity') > 1:
|
|
54 |
print('Command %s is ignored because DISABLE_CRON_JOBS is set'
|
|
55 |
% app_name)
|
|
56 |
return
|
|
57 |
|
45 |
58 |
if args_namespace.all_tenants:
|
46 |
59 |
for tenant in TenantMiddleware.get_tenants():
|
47 |
60 |
connection.set_tenant(tenant)
|
48 |
|
-
|