Ticket #3475: invalid_app_and_project_names.patch
File invalid_app_and_project_names.patch, 2.4 KB (added by , 18 years ago) |
---|
-
django/core/management.py
25 25 # which has been installed. 26 26 PROJECT_TEMPLATE_DIR = os.path.join(django.__path__[0], 'conf', '%s_template') 27 27 28 INVALID_PROJECT_NAMES = ('django', 'site', 'test')29 30 28 # Set up the terminal color scheme. 31 29 class dummy: pass 32 30 style = dummy() … … 50 48 if sys.platform == 'win32' or sys.platform == 'Pocket PC' or not sys.stdout.isatty(): 51 49 disable_termcolors() 52 50 51 def _is_valid_project_or_app_name(name): 52 valid_name = False 53 try: 54 eval(name) 55 except NameError: 56 try: 57 __import__(name) 58 except ImportError: 59 valid_name = True 60 except: 61 pass 62 except: 63 pass 64 return valid_name 65 53 66 def _is_valid_dir_name(s): 54 67 return bool(re.search(r'^\w+$', s)) 55 68 … … 707 720 def startproject(project_name, directory): 708 721 "Creates a Django project for the given project_name in the given directory." 709 722 from random import choice 710 if project_name in INVALID_PROJECT_NAMES:711 sys.stderr.write(style.ERROR("Error: '%r' conflicts with the name of an existing Python module and cannot be used as a project name. Please try another name.\n" % project_name))723 if not _is_valid_project_or_app_name(project_name): 724 sys.stderr.write(style.ERROR("Error: '%r' conflicts with the name of an existing Python module or keyword and cannot be used as a project name. Please try another name.\n" % project_name)) 712 725 sys.exit(1) 713 726 _start_helper('project', project_name, directory) 714 727 # Create a random SECRET_KEY hash, and put it in the main settings. … … 726 739 "Creates a Django app for the given app_name in the given directory." 727 740 # Determine the project_name a bit naively -- by looking at the name of 728 741 # the parent directory. 742 if not _is_valid_project_or_app_name(app_name): 743 sys.stderr.write(style.ERROR("Error: '%r' conflicts with the name of an existing Python module or keyword and cannot be used as a application name. Please try another name.\n" % app_name)) 744 sys.exit(1) 729 745 project_dir = os.path.normpath(os.path.join(directory, '..')) 730 746 project_name = os.path.basename(project_dir) 731 747 if app_name == os.path.basename(directory):