root / env / lib / python2.7 / site-packages / south / management / commands / __init__.py @ d1a4905f
History | View | Annotate | Download (1.51 KB)
1 |
|
---|---|
2 |
# Common framework for syncdb actions
|
3 |
|
4 |
import copy |
5 |
|
6 |
from django.core import management |
7 |
from django.conf import settings |
8 |
|
9 |
# Make sure the template loader cache is fixed _now_ (#448)
|
10 |
import django.template.loaders.app_directories |
11 |
|
12 |
from south.hacks import hacks |
13 |
from south.management.commands.syncdb import Command as SyncCommand |
14 |
|
15 |
class MigrateAndSyncCommand(SyncCommand): |
16 |
"""Used for situations where "syncdb" is called by test frameworks."""
|
17 |
|
18 |
option_list = copy.deepcopy(SyncCommand.option_list) |
19 |
|
20 |
for opt in option_list: |
21 |
if "--migrate" == opt.get_opt_string(): |
22 |
opt.default = True
|
23 |
break
|
24 |
|
25 |
def patch_for_test_db_setup(): |
26 |
# Load the commands cache
|
27 |
management.get_commands() |
28 |
# Repoint to the correct version of syncdb
|
29 |
if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE: |
30 |
# point at the core syncdb command when creating tests
|
31 |
# tests should always be up to date with the most recent model structure
|
32 |
management._commands['syncdb'] = 'django.core' |
33 |
else:
|
34 |
management._commands['syncdb'] = MigrateAndSyncCommand()
|
35 |
# Avoid flushing data migrations.
|
36 |
# http://code.djangoproject.com/ticket/14661 introduced change that flushed custom
|
37 |
# sql during the test database creation (thus flushing the data migrations).
|
38 |
# we patch flush to be no-op during create_test_db, but still allow flushing
|
39 |
# after each test for non-transactional backends.
|
40 |
hacks.patch_flush_during_test_db_creation() |