0001-add-a-delete_tenant-command.patch
hobo/multitenant/management/commands/delete_tenant.py | ||
---|---|---|
1 |
import sys |
|
2 | ||
3 |
from django.core.management.base import CommandError, BaseCommand |
|
4 | ||
5 |
from hobo.multitenant.middleware import TenantMiddleware |
|
6 | ||
7 | ||
8 |
class Command(BaseCommand): |
|
9 |
help = "Delete tenant(s) by hostname(s)" |
|
10 |
args = ['...'] |
|
11 | ||
12 |
def handle(self, *args, **options): |
|
13 |
if not args: |
|
14 |
raise CommandError("you must give at least one tenant hostname") |
|
15 | ||
16 |
# if - is given on the command line, get list of hostnames from stdin |
|
17 |
if '-' in args: |
|
18 |
args = list(args) |
|
19 |
args.remove('-') |
|
20 |
args.extend([x.strip() for x in sys.stdin.readlines()]) |
|
21 | ||
22 |
for hostname in args: |
|
23 |
tenant = TenantMiddleware.get_tenant_by_hostname(hostname) |
|
24 |
tenant.delete() |
|
0 |
- |