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
|
2007-10-28 00:09:52 +08:00
|
|
|
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2011-12-23 06:38:02 +08:00
|
|
|
class Command(TemplateCommand):
|
|
|
|
help = ("Creates a Django app directory structure for the given app "
|
|
|
|
"name in the current directory or optionally in the given "
|
|
|
|
"directory.")
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2011-12-23 06:38:02 +08:00
|
|
|
def handle(self, app_name=None, target=None, **options):
|
2012-10-13 22:05:34 +08:00
|
|
|
self.validate_name(app_name, "app")
|
2008-06-16 11:56:48 +08:00
|
|
|
|
|
|
|
# Check that the app_name cannot be imported.
|
|
|
|
try:
|
2009-03-19 00:55:59 +08:00
|
|
|
import_module(app_name)
|
2008-06-16 11:56:48 +08:00
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
else:
|
2011-12-23 06:38:02 +08:00
|
|
|
raise CommandError("%r conflicts with the name of an existing "
|
|
|
|
"Python module and cannot be used as an app "
|
|
|
|
"name. Please try another name." % app_name)
|
2008-06-16 11:56:48 +08:00
|
|
|
|
2011-12-23 06:38:02 +08:00
|
|
|
super(Command, self).handle('app', app_name, target, **options)
|