Projet

Général

Profil

0002-management-command-for-listing-tenants.patch

Serghei Mihai, 24 juin 2014 14:18

Télécharger (1,68 ko)

Voir les différences:

Subject: [PATCH 2/2] management command for listing tenants

 .../management/commands/list_tenants.py            | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 entrouvert/djommon/multitenant/management/commands/list_tenants.py
entrouvert/djommon/multitenant/management/commands/list_tenants.py
1
from django.core.management.base import BaseCommand, CommandError
2
from optparse import make_option
3

  
4
class Command(BaseCommand):
5
    requires_model_validation = True
6
    can_import_settings = True
7
    option_list = BaseCommand.option_list + (
8
            make_option('--list-settings',
9
                action='store_true',
10
                default=False,
11
                help='List settings'),
12
    )
13

  
14
    def handle(self, **options):
15

  
16
        import tenant_schemas.utils
17

  
18
        TenantModel = tenant_schemas.utils.get_tenant_model()
19
        all_tenants = TenantModel.objects.all()
20

  
21
        if not all_tenants:
22
            raise CommandError("""There are no tenants in the system.
23
            To learn how create a tenant, see:
24
            https://django-tenant-schemas.readthedocs.org/en/latest/use.html#creating-a-tenant""")
25

  
26
        schemas = ((t.schema_name, t.domain_url,) for t in all_tenants)
27
        print('\n'.join(["%s : %s" % schema for schema in schemas]))
0
-