mirror of
https://github.com/django/django.git
synced 2024-11-29 22:56:46 +01:00
Made startapp/project's overlaying error message use 'app' or 'project'.
This commit is contained in:
parent
96446c7152
commit
03bee42a7e
@ -58,10 +58,11 @@ class TemplateCommand(BaseCommand):
|
|||||||
|
|
||||||
def handle(self, app_or_project, name, target=None, **options):
|
def handle(self, app_or_project, name, target=None, **options):
|
||||||
self.app_or_project = app_or_project
|
self.app_or_project = app_or_project
|
||||||
|
self.a_or_an = 'an' if app_or_project == 'app' else 'a'
|
||||||
self.paths_to_remove = []
|
self.paths_to_remove = []
|
||||||
self.verbosity = options['verbosity']
|
self.verbosity = options['verbosity']
|
||||||
|
|
||||||
self.validate_name(name, app_or_project)
|
self.validate_name(name)
|
||||||
|
|
||||||
# if some directory is given, make sure it's nicely expanded
|
# if some directory is given, make sure it's nicely expanded
|
||||||
if target is None:
|
if target is None:
|
||||||
@ -139,10 +140,12 @@ class TemplateCommand(BaseCommand):
|
|||||||
break # Only rewrite once
|
break # Only rewrite once
|
||||||
|
|
||||||
if path.exists(new_path):
|
if path.exists(new_path):
|
||||||
raise CommandError("%s already exists, overlaying a "
|
raise CommandError(
|
||||||
"project or app into an existing "
|
"%s already exists. Overlaying %s %s into an existing "
|
||||||
"directory won't replace conflicting "
|
"directory won't replace conflicting files." % (
|
||||||
"files" % new_path)
|
new_path, self.a_or_an, app_or_project,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Only render the Python files, as we don't want to
|
# Only render the Python files, as we don't want to
|
||||||
# accidentally render Django templates files
|
# accidentally render Django templates files
|
||||||
@ -202,12 +205,11 @@ class TemplateCommand(BaseCommand):
|
|||||||
raise CommandError("couldn't handle %s template %s." %
|
raise CommandError("couldn't handle %s template %s." %
|
||||||
(self.app_or_project, template))
|
(self.app_or_project, template))
|
||||||
|
|
||||||
def validate_name(self, name, app_or_project):
|
def validate_name(self, name):
|
||||||
a_or_an = 'an' if app_or_project == 'app' else 'a'
|
|
||||||
if name is None:
|
if name is None:
|
||||||
raise CommandError('you must provide {an} {app} name'.format(
|
raise CommandError('you must provide {an} {app} name'.format(
|
||||||
an=a_or_an,
|
an=self.a_or_an,
|
||||||
app=app_or_project,
|
app=self.app_or_project,
|
||||||
))
|
))
|
||||||
# Check it's a valid directory name.
|
# Check it's a valid directory name.
|
||||||
if not name.isidentifier():
|
if not name.isidentifier():
|
||||||
@ -215,7 +217,7 @@ class TemplateCommand(BaseCommand):
|
|||||||
"'{name}' is not a valid {app} name. Please make sure the "
|
"'{name}' is not a valid {app} name. Please make sure the "
|
||||||
"name is a valid identifier.".format(
|
"name is a valid identifier.".format(
|
||||||
name=name,
|
name=name,
|
||||||
app=app_or_project,
|
app=self.app_or_project,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# Check it cannot be imported.
|
# Check it cannot be imported.
|
||||||
@ -229,8 +231,8 @@ class TemplateCommand(BaseCommand):
|
|||||||
"module and cannot be used as {an} {app} name. Please try "
|
"module and cannot be used as {an} {app} name. Please try "
|
||||||
"another name.".format(
|
"another name.".format(
|
||||||
name=name,
|
name=name,
|
||||||
an=a_or_an,
|
an=self.a_or_an,
|
||||||
app=app_or_project,
|
app=self.app_or_project,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1938,7 +1938,11 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
|||||||
# running again..
|
# running again..
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "already exists")
|
self.assertOutput(
|
||||||
|
err,
|
||||||
|
"already exists. Overlaying a project into an existing directory "
|
||||||
|
"won't replace conflicting files."
|
||||||
|
)
|
||||||
|
|
||||||
def test_custom_project_template(self):
|
def test_custom_project_template(self):
|
||||||
"Make sure the startproject management command is able to use a different project template"
|
"Make sure the startproject management command is able to use a different project template"
|
||||||
@ -2128,6 +2132,15 @@ class StartApp(AdminScriptTestCase):
|
|||||||
)
|
)
|
||||||
self.assertFalse(os.path.exists(testproject_dir))
|
self.assertFalse(os.path.exists(testproject_dir))
|
||||||
|
|
||||||
|
def test_overlaying_app(self):
|
||||||
|
self.run_django_admin(['startapp', 'app1'])
|
||||||
|
out, err = self.run_django_admin(['startapp', 'app2', 'app1'])
|
||||||
|
self.assertOutput(
|
||||||
|
err,
|
||||||
|
"already exists. Overlaying an app into an existing directory "
|
||||||
|
"won't replace conflicting files."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class DiffSettings(AdminScriptTestCase):
|
class DiffSettings(AdminScriptTestCase):
|
||||||
"""Tests for diffsettings management command."""
|
"""Tests for diffsettings management command."""
|
||||||
|
Loading…
Reference in New Issue
Block a user