Révision 964ebb51
Ajouté par Thomas Noël il y a environ 9 ans
entrouvert/djommon/multitenant/management/commands/sync_schemas.py | ||
---|---|---|
4 | 4 |
# License: MIT license |
5 | 5 |
# Home-page: http://github.com/bcarneiro/django-tenant-schemas |
6 | 6 |
import django |
7 |
from django.core.management.base import CommandError |
|
7 | 8 |
|
8 |
if django.VERSION < (1, 7, 0): |
|
9 |
from django.conf import settings |
|
10 |
from django.contrib.contenttypes.models import ContentType |
|
11 |
from django.db.models import get_apps, get_models |
|
12 |
if "south" in settings.INSTALLED_APPS: |
|
13 |
from south.management.commands.syncdb import Command as SyncdbCommand |
|
14 |
else: |
|
15 |
from django.core.management.commands.syncdb import Command as SyncdbCommand |
|
16 |
from django.db import connection |
|
17 |
from entrouvert.djommon.multitenant.middleware import TenantMiddleware |
|
9 |
from django.conf import settings |
|
10 |
from django.contrib.contenttypes.models import ContentType |
|
11 |
from django.db.models import get_apps, get_models |
|
12 |
if 'south' in settings.INSTALLED_APPS: |
|
13 |
from south.management.commands.syncdb import Command as SyncdbCommand |
|
14 |
else: |
|
15 |
from django.core.management.commands.syncdb import Command as SyncdbCommand |
|
16 |
from django.db import connection |
|
17 |
from entrouvert.djommon.multitenant.middleware import TenantMiddleware |
|
18 | 18 |
from entrouvert.djommon.multitenant.management.commands import SyncCommon |
19 | 19 |
|
20 | 20 |
|
21 |
class SyncSchemasCommand(SyncCommon):
|
|
21 |
class Command(SyncCommon): |
|
22 | 22 |
help = "Sync schemas based on TENANT_APPS and SHARED_APPS settings" |
23 | 23 |
option_list = SyncdbCommand.option_list + SyncCommon.option_list |
24 | 24 |
|
25 | 25 |
def handle(self, *args, **options): |
26 |
if django.VERSION >= (1, 7, 0): |
|
27 |
raise CommandError('This command is only meant to be used for 1.6' |
|
28 |
' and older version of django. For 1.7, use' |
|
29 |
' `migrate_schemas` instead.') |
|
26 | 30 |
super(Command, self).handle(*args, **options) |
27 | 31 |
|
28 | 32 |
if "south" in settings.INSTALLED_APPS: |
... | ... | |
81 | 85 |
apps = self.shared_apps or self.installed_apps |
82 | 86 |
self._set_managed_apps(apps) |
83 | 87 |
SyncdbCommand().execute(**self.options) |
84 |
|
|
85 |
if django.VERSION < (1, 7, 0): |
|
86 |
Command = SyncSchemasCommand |
|
87 |
else: |
|
88 |
raise RuntimeError('Django 1.7: use migrate_schemas') |
|
89 |
|
Formats disponibles : Unified diff
multitenant: sync_schemas disabled for django 1.7