# Path: shared_schema_tenants/helpers/tenants.py
# def create_tenant(name, slug, extra_data, domains=[], user=None):
#     from shared_schema_tenants.models import Tenant
#     with transaction.atomic():
#         tenant = Tenant.objects.create(
#             name=name, slug=slug, extra_data=extra_data)
# 
#         if len(domains) > 0:
#             for domain in domains:
#                 site = Site.objects.create(name=name, domain=domain)
#                 tenant.tenant_sites.create(site=site)
# 
#         if user:
#             rel = tenant.relationships.create(user=user)
#             rel.groups.add(create_default_tenant_groups()[0])
# 
#         return tenant


from django.db import transaction
from django.core.management.base import BaseCommand
from django.utils.text import slugify
from shared_schema_tenants.helpers.tenants import create_tenant


class Command(BaseCommand):
    help = 'Creates a new Tenant'

    def handle(self, *args, **options):
        name = input('Enter the Tenant name: ')
        slug = input('Enter the Tenant slug: (%s)' % slugify(name))
        domain = input('Enter the Tenant site: (localhost:8000)')


# Path: shared_schema_tenants/helpers/tenants.py
# def create_tenant(name, slug, extra_data, domains=[], user=None):
#     from shared_schema_tenants.models import Tenant
#     with transaction.atomic():
#         tenant = Tenant.objects.create(
#             name=name, slug=slug, extra_data=extra_data)
# 
#         if len(domains) > 0:
#             for domain in domains:
#                 site = Site.objects.create(name=name, domain=domain)
#                 tenant.tenant_sites.create(site=site)
# 
#         if user:
#             rel = tenant.relationships.create(user=user)
#             rel.groups.add(create_default_tenant_groups()[0])
# 
#         return tenant


# Path: shared_schema_tenants/management/commands/createtenant.py
from django.db import transaction
from django.core.management.base import BaseCommand
from django.utils.text import slugify
from shared_schema_tenants.helpers.tenants import create_tenant



class Command(BaseCommand):
    help = 'Creates a new Tenant'

    def handle(self, *args, **options):
        name = input('Enter the Tenant name: ')
        slug = input('Enter the Tenant slug: (%s)' % slugify(name))
        domain = input('Enter the Tenant site: (localhost:8000)')


        if not slug: