Ticket #6654: startproject-startapp.2.patch

File startproject-startapp.2.patch, 2.3 KB (added by Ivan Illarionov, 17 years ago)

fixed startapp.py

  • startapp.py

     
    2323        if app_name == project_name:
    2424            raise CommandError("You cannot create an app with the same name"
    2525                               " (%r) as your project." % app_name)
     26        # Check that the app_name cannot be imported
     27        try:
     28            __import__(app_name)
     29        except ImportError:
     30            pass
     31        else:
     32            raise CommandError("%r conflicts with the name of an existing"
     33                               " Python module and cannot be used as"
     34                               " an app name. Please try another name."
     35                               % app_name)
     36
    2637        copy_helper(self.style, 'app', app_name, directory, project_name)
    2738
    2839class ProjectCommand(Command):
  • startproject.py

     
    33import re
    44from random import choice
    55
    6 INVALID_PROJECT_NAMES = ('django', 'site', 'test')
    7 
    86class Command(LabelCommand):
    97    help = "Creates a Django project directory structure for the given project name in the current directory."
    108    args = "[projectname]"
     
    2018        # the parent directory.
    2119        directory = os.getcwd()
    2220
     21        # Check that the project_name is free and can't be imported
    2322        try:
    24             proj_name = __import__(project_name)
    25             if proj_name:
    26                 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)
     23            __import__(project_name)
    2724        except ImportError:
    28             if project_name in INVALID_PROJECT_NAMES:
    29                 raise CommandError("%r contains an invalid project name. Please try another name." % project_name)
     25            pass
     26        else:
     27            raise CommandError("%r conflicts with the name of an existing"
     28                               " Python module and cannot be used as"
     29                               " a project name. Please try another name."
     30                               % project_name)
    3031
    3132        copy_helper(self.style, 'project', project_name, directory)
    3233
Back to Top