Django

Code

Ticket #6654: startproject-startapp.patch

File startproject-startapp.patch, 2.5 kB (added by i_i, 9 months ago)

startapp included

  • django/core/management/commands/startapp.py

    old new  
    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        try: 
     27            __import__(app_name) 
     28        except ImportError: 
     29            pass 
     30        else: 
     31            raise CommandError("%r conflicts with the name of an existing" 
     32                               " Python module and cannot be used as" 
     33                               " an app name. Please try another name." 
     34                               % project_name) 
     35 
    2636        copy_helper(self.style, 'app', app_name, directory, project_name) 
    2737 
    2838class ProjectCommand(Command): 
  • django/core/management/commands/startproject.py

    old new  
    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