当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_tenant_model函数代码示例

本文整理汇总了Python中tenant_schemas.utils.get_tenant_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_tenant_model函数的具体用法?Python get_tenant_model怎么用?Python get_tenant_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_tenant_model函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: receive

    def receive(self, content, **kwargs):
        tenant_pk = self.message.channel_session.get('tenant')
        logger.info('tenant pk: {}'.format(tenant_pk))

        if tenant_pk is None:
            logger.error('TransactionConsumer tenant not in session')
            return

        try:
            tenant = get_tenant_model().objects.get(
                pk=tenant_pk
            )
        except get_tenant_model().DoesNotExist:
            return

        with tenant_context(tenant):
            more_blocks = Block.objects.exclude(
                height__isnull=True
            ).filter(
                height__lt=content.get('height')
            ).order_by(
                '-height'
            )[:20]

            kwargs.get('multiplexer').send(
                {
                    "more_blocks": [
                        block.serialize() for block in more_blocks
                    ]
                }
            )
开发者ID:inuitwallet,项目名称:crypto-daio,代码行数:31,代码来源:block.py

示例2: migrate_tenant_apps

    def migrate_tenant_apps(self, schema_name=None):
        self._save_south_settings()

        apps = self.tenant_apps or self.installed_apps
        self._set_managed_apps(included_apps=apps, excluded_apps=self.shared_apps)

        syncdb_command = MigrateCommand()
        if schema_name:
            print self.style.NOTICE("=== Running migrate for schema: %s" % schema_name)
            connection.set_schema_to_public()
            sync_tenant = get_tenant_model().objects.filter(schema_name=schema_name).get()
            connection.set_tenant(sync_tenant, include_public=False)
            syncdb_command.execute(**self.options)
        else:
            public_schema_name = get_public_schema_name()
            tenant_schemas_count = get_tenant_model().objects.exclude(schema_name=public_schema_name).count()
            if not tenant_schemas_count:
                print self.style.NOTICE("No tenants found")

            for tenant_schema in get_tenant_model().objects.exclude(schema_name=public_schema_name).all():
                Migrations._dependencies_done = False  # very important, the dependencies need to be purged from cache
                print self.style.NOTICE("=== Running migrate for schema %s" % tenant_schema.schema_name)
                connection.set_tenant(tenant_schema, include_public=False)
                syncdb_command.execute(**self.options)

        self._restore_south_settings()
开发者ID:emikil,项目名称:django-tenant-schemas,代码行数:26,代码来源:migrate_schemas.py

示例3: sync_tenant_apps

    def sync_tenant_apps(self, schema_name=None):
        if schema_name:
            tenant = get_tenant_model().objects.filter(schema_name=schema_name).get()
            self._sync_tenant(tenant)
        else:
            all_tenants = get_tenant_model().objects.exclude(schema_name=get_public_schema_name())
            if not all_tenants:
                self._notice("No tenants found!")

            for tenant in all_tenants:
                self._sync_tenant(tenant)
开发者ID:MatheusCampello,项目名称:django-tenant-schemas,代码行数:11,代码来源:sync_schemas.py

示例4: handle

 def handle(self, *args, **options):
     """
     Iterates a command over all registered schemata.
     """
     if options['schema_name']:
         # only run on a particular schema
         connection.set_schema_to_public()
         self.execute_command(get_tenant_model().objects.get(schema_name=options['schema_name']), self.COMMAND_NAME, *args, **options)
     else:
         for tenant in get_tenant_model().objects.all():
             self.execute_command(tenant, self.COMMAND_NAME, *args, **options)
开发者ID:bogeymin,项目名称:django-tenant-schemas,代码行数:11,代码来源:__init__.py

示例5: load_fixtures

    def load_fixtures(self, client_name):
        from django.db import connection

        try:
            tenant = get_tenant_model().objects.get(client_name=client_name)
            connection.set_tenant(tenant)
            call_command('loaddata', 'skills')
            call_command('loaddata', 'redirects')
            call_command('loaddata', 'project_data')
            call_command('loaddata', 'geo_data')
        except get_tenant_model().DoesNotExist:
            self.stdout.write("Client not found. Skipping loading fixtures")
开发者ID:jfterpstra,项目名称:bluebottle,代码行数:12,代码来源:new_tenant.py

示例6: setUpClass

    def setUpClass(cls):
        # create a tenant
        tenant_domain = 'tenant.test.com'
        cls.tenant = get_tenant_model()(domain_url=tenant_domain, schema_name='test')
        cls.tenant.save()

        connection.set_tenant(cls.tenant)
开发者ID:gijs,项目名称:django-tenant-schemas,代码行数:7,代码来源:cases.py

示例7: setUpClass

    def setUpClass(cls):
        # create a tenant
        tenant_domain = "testserver"
        cls.tenant = get_tenant_model()(domain_url=tenant_domain, schema_name="test")
        cls.tenant.save(verbosity=0)  # todo: is there any way to get the verbosity from the test command here?

        connection.set_tenant(cls.tenant)
开发者ID:Jafula,项目名称:django-tenant-schemas,代码行数:7,代码来源:cases.py

示例8: connect

    def connect(self, message, **kwargs):
        try:
            tenant = get_tenant_model().objects.get(
                domain_url=get_host(message.content)
            )
        except get_tenant_model().DoesNotExist:
            logger.error(
                'no tenant found for {}'.format(
                    get_host(message.content)
                )
            )
            message.reply_channel.send({"close": True})
            return

        message.channel_session['tenant'] = tenant.pk
        super().connect(message, **kwargs)
开发者ID:inuitwallet,项目名称:crypto-daio,代码行数:16,代码来源:block.py

示例9: process_request

    def process_request(self, request):
        # Connection needs first to be at the public schema, as this is where
        # the tenant metadata is stored.
        connection.set_schema_to_public()

        hostname = self.hostname_from_request(request)
        TenantModel = get_tenant_model()

        try:
            # get_tenant must be implemented by extending this class.
            tenant = self.get_tenant(TenantModel, hostname, request)
            assert isinstance(tenant, TenantModel)
        except TenantModel.DoesNotExist:
            raise self.TENANT_NOT_FOUND_EXCEPTION(
                'No tenant for {!r}'.format(request.get_host()))
        except AssertionError:
            raise self.TENANT_NOT_FOUND_EXCEPTION(
                'Invalid tenant {!r}'.format(request.tenant))

        request.tenant = tenant
        connection.set_tenant(request.tenant)

        # Content type can no longer be cached as public and tenant schemas
        # have different models. If someone wants to change this, the cache
        # needs to be separated between public and shared schemas. If this
        # cache isn't cleared, this can cause permission problems. For example,
        # on public, a particular model has id 14, but on the tenants it has
        # the id 15. if 14 is cached instead of 15, the permissions for the
        # wrong model will be fetched.
        ContentType.objects.clear_cache()

        # Do we have a public-specific urlconf?
        if hasattr(settings, 'PUBLIC_SCHEMA_URLCONF') and request.tenant.schema_name == get_public_schema_name():
            request.urlconf = settings.PUBLIC_SCHEMA_URLCONF
开发者ID:mikicz,项目名称:django-tenant-schemas,代码行数:34,代码来源:middleware.py

示例10: get_tenant_from_options_or_interactive

    def get_tenant_from_options_or_interactive(self, **options):
        TenantModel = get_tenant_model()
        all_tenants = TenantModel.objects.all()

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

        if options.get('schema_name'):
            tenant_schema = options['schema_name']
        else:
            while True:
                tenant_schema = input(
                    "Enter Tenant Schema ('?' to list schemas): ")
                if tenant_schema == '?':
                    print(
                        '\n'.join(["%s - %s" % (t.schema_name, t.domain_url,) for t in all_tenants]))
                else:
                    break

        if tenant_schema not in [t.schema_name for t in all_tenants]:
            raise CommandError(
                "Invalid tenant schema, '%s'" % (tenant_schema,))

        return TenantModel.objects.get(schema_name=tenant_schema)
开发者ID:ojengwa,项目名称:django-multitenants,代码行数:26,代码来源:__init__.py

示例11: process_request

    def process_request(self, request):
        """
        Resets to public schema

        Some nasty weird bugs happened at the production environment without this call.
        connection.pg_thread.schema_name would already be set and then terrible errors
        would occur. Any idea why? My theory is django implements connection as some sort
        of threading local variable.
        """
        connection.set_schema_to_public()
        hostname_without_port = remove_www_and_dev(request.get_host().split(':')[0])

        TenantModel = get_tenant_model()
        request.tenant = get_object_or_404(TenantModel, domain_url=hostname_without_port)
        connection.set_tenant(request.tenant)

        # content type can no longer be cached as public and tenant schemas have different
        # models. if someone wants to change this, the cache needs to be separated between
        # public and shared schemas. if this cache isn't cleared, this can cause permission
        # problems. for example, on public, a particular model has id 14, but on the tenants
        # it has the id 15. if 14 is cached instead of 15, the permissions for the wrong
        # model will be fetched.
        ContentType.objects.clear_cache()

        # do we have a public-specific token?
        if hasattr(settings, 'PUBLIC_SCHEMA_URL_TOKEN') and request.tenant.schema_name == get_public_schema_name():
            request.path_info = settings.PUBLIC_SCHEMA_URL_TOKEN + request.path_info
开发者ID:cgranet,项目名称:django-tenant-schemas,代码行数:27,代码来源:middleware.py

示例12: setUp

    def setUp(self):
        super(TestMultiTenant, self).setUp()

        now = timezone.now()

        self.init_projects()
        self.tenant1 = connection.tenant
        status_running = ProjectPhase.objects.get(slug='campaign')

        # Create a project for the main tenant
        self.project = ProjectFactory.create(status=ProjectPhase.objects.get(slug='campaign'),
                                             deadline=now - timezone.timedelta(days=5),
                                             amount_asked=0)

        # Create a second tenant
        connection.set_schema_to_public()
        tenant_domain = 'testserver2'
        self.tenant2 = get_tenant_model()(
            domain_url=tenant_domain,
            schema_name='test2',
            client_name='test2')

        self.tenant2.save(verbosity=0)
        connection.set_tenant(self.tenant2)

        self.init_projects()
        self.project2 = ProjectFactory.create(status=ProjectPhase.objects.get(slug='campaign'),
                                              deadline=now - timezone.timedelta(days=5),
                                              amount_asked=0)
开发者ID:pombredanne,项目名称:bluebottle,代码行数:29,代码来源:test_management.py

示例13: get_context_data

    def get_context_data(self, **kwargs):
        form = kwargs.get('form')

        if form and form.is_valid():
            start = form.get_start()
            stop = form.get_stop()
            tenant = form.cleaned_data.get('tenant', None)

            if tenant:
                connection.set_tenant(tenant)
                header = ' - {}'.format(tenant.name)
                statistics = get_accounting_statistics(start, stop)
            else:
                header = ' - All tenants'
                statistics = mydict()

                for tenant in get_tenant_model().objects.all():
                    connection.set_tenant(tenant)
                    statistics += get_accounting_statistics(start, stop)
        else:
            header = ''
            statistics = {}

        context = super(MultiTenantAccountingOverviewView, self).get_context_data(**kwargs)

        context.update({
             'app_label': 'accounting',
             'title': _('Accountancy Overview') + header,
             'statistics': statistics,
        })
        return context
开发者ID:repodevs,项目名称:bluebottle,代码行数:31,代码来源:views.py

示例14: wrapper

 def wrapper(*args, **kwargs):
     if settings.MULTI_TENANT:
         for tenant in get_tenant_model().objects.exclude(schema_name="public"):
             with tenant_context(tenant):
                 f(*args, **kwargs)
     else:
         f(*args, **kwargs)
开发者ID:Alejoss,项目名称:django-sis,代码行数:7,代码来源:helper_functions.py

示例15: process_request

    def process_request(self, request):
        # Connection needs first to be at the public schema, as this is where
        # the tenant metadata is stored.
        connection.set_schema_to_public()
        hostname = self.hostname_from_request(request)

        tenant_model = get_tenant_model()
        try:
            request.tenant = tenant_model.objects.get(domain_url=hostname)
            connection.set_tenant(request.tenant)
        except tenant_model.DoesNotExist:
            pass

        # Content type can no longer be cached as public and tenant schemas
        # have different models. If someone wants to change this, the cache
        # needs to be separated between public and shared schemas. If this
        # cache isn't cleared, this can cause permission problems. For example,
        # on public, a particular model has id 14, but on the tenants it has
        # the id 15. if 14 is cached instead of 15, the permissions for the
        # wrong model will be fetched.
        ContentType.objects.clear_cache()

        # Do we have a public-specific urlconf?
        if hasattr(settings, 'PUBLIC_SCHEMA_URLCONF') and request.tenant.schema_name == get_public_schema_name():
            request.urlconf = settings.PUBLIC_SCHEMA_URLCONF
开发者ID:Proteus-tech,项目名称:django-tenant-schemas,代码行数:25,代码来源:middleware.py


注:本文中的tenant_schemas.utils.get_tenant_model函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。