|
1 from django.core.management.base import BaseCommand |
|
2 |
|
3 from optparse import make_option |
|
4 |
|
5 class Command(BaseCommand): |
|
6 option_list = BaseCommand.option_list + ( |
|
7 make_option('--verbosity', action='store', dest='verbosity', default='1', |
|
8 type='choice', choices=['0', '1', '2'], |
|
9 help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'), |
|
10 make_option('--addrport', action='store', dest='addrport', |
|
11 type='string', default='', |
|
12 help='port number or ipaddr:port to run the server on'), |
|
13 ) |
|
14 help = 'Runs a development server with data from the given fixture(s).' |
|
15 args = '[fixture ...]' |
|
16 |
|
17 requires_model_validation = False |
|
18 |
|
19 def handle(self, *fixture_labels, **options): |
|
20 from django.conf import settings |
|
21 from django.core.management import call_command |
|
22 from django.test.utils import create_test_db |
|
23 |
|
24 verbosity = int(options.get('verbosity', 1)) |
|
25 addrport = options.get('addrport') |
|
26 |
|
27 # Create a test database. |
|
28 db_name = create_test_db(verbosity=verbosity) |
|
29 |
|
30 # Import the fixture data into the test database. |
|
31 call_command('loaddata', *fixture_labels, **{'verbosity': verbosity}) |
|
32 |
|
33 # Run the development server. Turn off auto-reloading because it causes |
|
34 # a strange error -- it causes this handle() method to be called |
|
35 # multiple times. |
|
36 shutdown_message = '\nServer stopped.\nNote that the test database, %r, has not been deleted. You can explore it on your own.' % db_name |
|
37 call_command('runserver', addrport=addrport, shutdown_message=shutdown_message, use_reloader=False) |