|
0
|
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('--addrport', action='store', dest='addrport', |
|
|
8 |
type='string', default='', |
|
|
9 |
help='port number or ipaddr:port to run the server on'), |
|
|
10 |
) |
|
|
11 |
help = 'Runs a development server with data from the given fixture(s).' |
|
|
12 |
args = '[fixture ...]' |
|
|
13 |
|
|
|
14 |
requires_model_validation = False |
|
|
15 |
|
|
|
16 |
def handle(self, *fixture_labels, **options): |
|
|
17 |
from django.core.management import call_command |
|
|
18 |
from django.db import connection |
|
|
19 |
|
|
|
20 |
verbosity = int(options.get('verbosity', 1)) |
|
|
21 |
addrport = options.get('addrport') |
|
|
22 |
|
|
|
23 |
# Create a test database. |
|
|
24 |
db_name = connection.creation.create_test_db(verbosity=verbosity) |
|
|
25 |
|
|
|
26 |
# Import the fixture data into the test database. |
|
|
27 |
call_command('loaddata', *fixture_labels, **{'verbosity': verbosity}) |
|
|
28 |
|
|
|
29 |
# Run the development server. Turn off auto-reloading because it causes |
|
|
30 |
# a strange error -- it causes this handle() method to be called |
|
|
31 |
# multiple times. |
|
|
32 |
shutdown_message = '\nServer stopped.\nNote that the test database, %r, has not been deleted. You can explore it on your own.' % db_name |
|
|
33 |
call_command('runserver', addrport=addrport, shutdown_message=shutdown_message, use_reloader=False) |