def save(self, *args, **kwargs): super().save(*args, **kwargs) if self.tenant_set.count() == 0: t = Tenant() t.save() t.users.add(self) mail_admins("New User: "******"")
def main(domain_name): os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'saleor.settings') import django from django.core.management.commands.runserver import Command as runserver from django.core.management import execute_from_command_line django.setup() from tenants.models import Tenant, Domain Tenant.objects.all() tenant = Tenant(schema_name='public', name='admin tenant') tenant.save() domain = Domain() domain.domain = domain_name domain.tenant = tenant domain.is_primary = True domain.save()
def start(self): with open(str(self.input_path), newline="") as csvfile: reader = csv.DictReader(csvfile) for row in tqdm(reader): people: List[Person] = [] # Handle multiple tenants in one room if " and " in row["Tenancy"]: tenancy0: str = row["Tenancy"].split(" and ")[0] tenancy1: str = row["Tenancy"].split(" and ")[1] email0: Optional[str] = None email1: Optional[str] = None if row["Email"]: email0 = row["Email"].split(",")[0].strip() email1 = row["Email"].split(",")[1].strip() people.append(self._create_person(tenancy0, email0)) people.append(self._create_person(tenancy1, email1)) else: people.append( self._create_person(row["Tenancy"], row["Email"])) unit_n: int = int( list(filter(None, re.split("[U,R,/]", row["Property"])))[0]) room_n: int = int( list(filter(None, re.split("[U,R,/]", row["Property"])))[1]) room = Room.objects.get(number=room_n, unit__number=unit_n) lease_start: date = dateutil.parser.parse(row["Lease Start"]) lease_end: date = dateutil.parser.parse(row["Lease End"]) tenant = Tenant(room=room, lease_start=lease_start, lease_end=lease_end) tenant.save() tenant.people.set(people) tenant.save()
def tenant_creation_handler(sender, instance, created, **kwargs): if created: server = None uid = instance.uid try: server = DatabaseServer.objects.get(id=1) except DatabaseServer.DoesNotExist: print('DatabaseServer objects DoesNotExist') # Create and store tenant definition if not server: raise Exception('Server must be defined for tenant creation') db_name = ''.join( [chr for chr in str(uid).replace('-', '') if chr.isalpha()]) db_user = credentials_generator() db_password = credentials_generator() alias = db_name tenant = Tenant(application=instance, db_server=server, db_name=db_name, db_user=db_user, db_password=db_password, alias=alias) tenant.save() TenantLog.objects.create( tenant=tenant, message=_('Tenant object created for app {uid}'.format( uid=instance.uid))) #Create database and sql Credentials tenant_manager = TenantManager(tenant) tenant_manager.create_database() tenant_manager.create_db_user() tenant_manager.grant_privileges() tenant_manager.sync_database()
# This script create a public and a private tenant for testing from tenants.models import Tenant tenant = Tenant(domain_url='localhost', schema_name='public', name='public', paid_until='2018-12-05', on_trial=False) tenant.save() tenant = Tenant(domain_url='tenant.localhost', schema_name='tenant', name='Tenant One', paid_until='2018-12-05', on_trial=True) tenant.save()