2013-07-29 21:50:58 +08:00
|
|
|
from importlib import import_module
|
|
|
|
|
2011-12-23 06:38:02 +08:00
|
|
|
from django.core.management.base import CommandError
|
|
|
|
from django.core.management.templates import TemplateCommand
|
2015-04-18 16:09:41 +08:00
|
|
|
|
|
|
|
from ..utils import get_random_secret_key
|
2011-12-23 06:38:02 +08:00
|
|
|
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2011-12-23 06:38:02 +08:00
|
|
|
class Command(TemplateCommand):
|
2016-03-29 06:33:29 +08:00
|
|
|
help = (
|
|
|
|
"Creates a Django project directory structure for the given project "
|
|
|
|
"name in the current directory or optionally in the given directory."
|
|
|
|
)
|
2014-06-07 04:39:33 +08:00
|
|
|
missing_args_message = "You must provide a project name."
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2014-06-07 04:39:33 +08:00
|
|
|
def handle(self, **options):
|
|
|
|
project_name, target = options.pop('name'), options.pop('directory')
|
2012-10-13 22:05:34 +08:00
|
|
|
self.validate_name(project_name, "project")
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2008-06-16 11:56:48 +08:00
|
|
|
# Check that the project_name cannot be imported.
|
2008-03-19 23:10:31 +08:00
|
|
|
try:
|
2009-03-19 00:55:59 +08:00
|
|
|
import_module(project_name)
|
2008-03-19 23:10:31 +08:00
|
|
|
except ImportError:
|
2008-06-16 11:56:48 +08:00
|
|
|
pass
|
|
|
|
else:
|
2016-03-29 06:33:29 +08:00
|
|
|
raise CommandError(
|
|
|
|
"%r conflicts with the name of an existing Python module and "
|
|
|
|
"cannot be used as a project name. Please try another name." % project_name
|
|
|
|
)
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2014-05-22 18:19:54 +08:00
|
|
|
# Create a random SECRET_KEY to put it in the main settings.
|
2015-04-18 16:09:41 +08:00
|
|
|
options['secret_key'] = get_random_secret_key()
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2011-12-23 06:38:02 +08:00
|
|
|
super(Command, self).handle('project', project_name, target, **options)
|