-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added django>=2.0 compat #551
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,27 +86,31 @@ class InteractiveTenantOption(object): | |
def add_arguments(self, parser): | ||
parser.add_argument("-s", "--schema", dest="schema_name", help="specify tenant schema") | ||
|
||
def get_tenant_from_options_or_interactive(self, **options): | ||
def get_tenant_from_options_or_interactive(self, schema_name=None): | ||
TenantModel = get_tenant_model() | ||
all_tenants = TenantModel.objects.all() | ||
values = TenantModel.objects.values_list( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of |
||
"schema_name", "domain_url" | ||
) | ||
|
||
if not all_tenants: | ||
if not values: | ||
raise CommandError("""There are no tenants in the system. | ||
To learn how create a tenant, see: | ||
https://django-tenant-schemas.readthedocs.io/en/latest/use.html#creating-a-tenant""") | ||
|
||
if options.get('schema_name'): | ||
tenant_schema = options['schema_name'] | ||
if schema_name is not None: | ||
tenant_schema = 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])) | ||
print('\n'.join(["%s - %s" % item for item in values])) | ||
else: | ||
break | ||
|
||
if tenant_schema not in [t.schema_name for t in all_tenants]: | ||
raise CommandError("Invalid tenant schema, '%s'" % (tenant_schema,)) | ||
if tenant_schema not in [schema_name for schema_name, _ in values]: | ||
raise CommandError( | ||
"Invalid tenant schema, '%s'" % (tenant_schema,) | ||
) | ||
|
||
return TenantModel.objects.get(schema_name=tenant_schema) | ||
|
||
|
@@ -130,7 +134,8 @@ def add_arguments(self, parser): | |
self.command_instance.add_arguments(parser) | ||
|
||
def handle(self, *args, **options): | ||
tenant = self.get_tenant_from_options_or_interactive(**options) | ||
schema_name = options.pop("schema_name", None) | ||
tenant = self.get_tenant_from_options_or_interactive(schema_name) | ||
connection.set_tenant(tenant) | ||
|
||
self.command_instance.execute(*args, **options) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,7 @@ | |
from tenant_schemas.utils import get_public_schema_name, get_limit_set_calls | ||
from tenant_schemas.postgresql_backend.introspection import DatabaseSchemaIntrospection | ||
|
||
|
||
ORIGINAL_BACKEND = getattr(settings, 'ORIGINAL_BACKEND', 'django.db.backends.postgresql_psycopg2') | ||
# Django 1.9+ takes care to rename the default backend to 'django.db.backends.postgresql' | ||
original_backend = django.db.utils.load_backend(ORIGINAL_BACKEND) | ||
original_backend = django.db.utils.load_backend('django.db.backends.postgresql') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can cause issues, i can see the need to not break this, i can come up with a couple scenarios on why you would want to override this. |
||
|
||
EXTRA_SEARCH_PATHS = getattr(settings, 'PG_EXTRA_SEARCH_PATHS', []) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pypi/warehouse#4090
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AGASS007 great!
are you planning to release a new version soon?