def form_valid(self, form): instance = form.instance request = get_object_or_404(PizzeriaRequest, pk=self.kwargs['pk']) instance.request = request instance.schema_name = instance.name.lower().replace(" ", '_') instance.paid_until = datetime.datetime.now() + datetime.timedelta( days=30) instance.date_expired_paid = datetime.date.today( ) + datetime.timedelta(days=30) instance.phones = request.phone instance.email = request.email instance.address = request.address instance.plan = request.plan instance = form.save() domain = Domain() domain.domain = form.cleaned_data['domain'].lower().replace( " ", "_") + "." + self.request.tenant.domains.first().domain domain.is_primary = True domain.tenant = instance domain.save() with tenant_context(instance): password = "".join( [random.choice(string.ascii_lowercase[:26]) for i in range(8)]) # password = '******' user = UserProfile.objects.create( first_name='admin', last_name="admin", email=request.email, ) groups = { 'admin': [], 'vendedor': [], 'client': [], } for key, value in groups.items(): created, group = Group.objects.get_or_create(name=key) group = Group.objects.get(name="admin") user.is_staff = True user.set_password(password) user.is_superuser = True user.save() user.groups.add(group) send_mail( subject="Bienvenido a SuperPizzas", message= "Su solicitud de franquicia ha sido creado con exito. utilice el correo " + request.email + " y" " la contraseƱa " + password + " para loguearse. url: " + domain.domain, from_email="*****@*****.**", recipient_list=[request.email]) request.is_active = False request.save() return super(PizzeriaCreateView, self).form_valid(form)
def register(request): if request.method == "POST": username = request.POST['username'] password = request.POST['password'] name = request.POST['name'] email = request.POST['email'] phno = request.POST['phno'] # Storing phno in last_name # Function checks if the string contains any special character regex = re.compile('[@_!#$%^&*()<>?/\|}{~:]') if (regex.search(username) != None): messages.error(request, 'username must not conatain any special name') messages.info(request, 'Try Another Username') return redirect('home:register') if bool(re.search(r"\s", username)) == True: messages.error(request, 'username must not conatain space') messages.info(request, 'Try Another Username') return redirect('home:register') if username.islower() != True: messages.error(request, 'username must be lower case only') messages.info(request, 'Try Another Username') return redirect('home:register') if User.objects.filter(username=username).exists(): messages.error(request, 'Username is aldready taken') messages.info(request, 'Try Another Username') return redirect('home:register') user = User.objects.create_user(username=username, password=password, first_name=name, last_name=phno, email=email) user.save() tenant = Client.objects.create(user=user, schema_name=user.username) tenant.save() domain = Domain() domain.domain = tenant.schema_name + ".global.localhost" domain.tenant = tenant domain.is_primary = True domain.save() messages.success(request, 'Account created successfully for {}'.format(name)) with schema_context(username): ac = Accounts(name=username, money=0).save() return redirect('home:login') return render(request, 'login.html')
def handle(self, *args, **options): try: pubfound = Client.objects.filter(schema_name="public").exists() if not pubfound: # self.stdout.write(self.style.SUCCESS('Public tenant exists ')) # else: # TODO change for public client on bushfire ptenant = Client(schema_name='public', name='Schemas Inc.', paid_until='2012-12-05', on_trial=False) ptenant.save() # pdomain = Domain(domain='toodoo.com', tenant=ptenant, is_primary=True) pdomain = Domain( domain='polls-dev.ap-southeast-2.elasticbeanstalk.com', tenant=ptenant, is_primary=True) pdomain.save() # self.stdout.write(self.style.SUCCESS('Successfully created public tenant ')) except: pass
def setUpTestData(cls): connection.set_schema_to_public() cls.tenant = Tenant.objects.create(schema_name='tenant1') cls.tenant_domain = Domain() cls.tenant_domain.tenant = cls.tenant cls.tenant_domain.domain = 'tenant1.djangoredux.com' cls.tenant_domain.save() connection.set_tenant(cls.tenant) cls.account = Account.objects.create_superuser('tenant user', 'user', 'Tu112231') connection.set_schema_to_public()
def handle(self, *args, **options): if HOME_DEV_ENV: dlist = ['first', 'second', 'third', 'fourth'] else: dlist = ['kuringai', 'killara', 'hkops', 'westleigh'] for tn in dlist: try: tnfound = Client.objects.filter(schema_name=tn).exists() if not tnfound: # self.stdout.write(self.style.SUCCESS('Public tenant exists ')) # else: # TODO change for public client on bushfire ptenant = Client(schema_name=tn, name=tn, paid_until='2012-12-05', on_trial=False) ptenant.save() # pdomain = Domain(domain='toodoo.com', tenant=ptenant, is_primary=True) pdomain = Domain(domain=tn+'.polls-dev.ap-southeast-2.elasticbeanstalk.com', tenant=ptenant, is_primary=True) pdomain.save() # self.stdout.write(self.style.SUCCESS('Successfully created public tenant ')) except: pass
def create_account(data): account = AccountSerializer(data=data) account.is_valid(raise_exception=True) connection.set_schema_to_public() username = data['username'] tenant = Tenant.objects.create(schema_name=username) connection.set_tenant(tenant) domain = Domain() domain.tenant = tenant domain.domain = f"{username}.{APPLICATION_DOMAIN}" account.save() domain.save()
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 set_up_data(): # create your public tenant tenant = Client(schema_name='public', name='Schemas Inc.') tenant.save() # Add one or more domains for the tenant domain = Domain() domain.domain = 'localhost' # don't add your port or www here! on a local server you'll want to use localhost here domain.tenant = tenant domain.is_primary = True domain.save() user = get_user_model().objects.create(username="******") user.set_password("dummypassword") user.save() user = get_user_model().objects.create(username="******") user.set_password("dummypassword") user.save()