Ticket #798: createsuperuser.patch
File createsuperuser.patch, 3.4 KB (added by , 19 years ago) |
---|
-
django/bin/django-admin.py
81 81 translation.activate('en-us') 82 82 83 83 if action in ('createsuperuser', 'init', 'validate'): 84 ACTION_MAPPING[action]( )84 ACTION_MAPPING[action](*args[1:]) 85 85 elif action == 'inspectdb': 86 86 try: 87 87 param = args[1] -
django/core/management.py
480 480 startapp.help_doc = "Creates a Django app directory structure for the given app name in the current directory." 481 481 startapp.args = "[appname]" 482 482 483 def createsuperuser( ):483 def createsuperuser(username=None, email=None, password=None): 484 484 "Creates a superuser account." 485 485 from django.core import validators 486 486 from django.models.auth import users 487 487 import getpass 488 488 try: 489 489 while 1: 490 username = raw_input('Username (only letters, digits and underscores): ')490 if not username: username = raw_input('Username (only letters, digits and underscores): ') 491 491 if not username.isalnum(): 492 sys.stderr.write("Error: That username is invalid .\n")493 continue492 sys.stderr.write("Error: That username is invalid\n") 493 username = None 494 494 try: 495 495 users.get_object(username__exact=username) 496 496 except users.UserDoesNotExist: 497 497 break 498 498 else: 499 sys.stderr.write("Error: That username is already taken.\n") 499 sys.stderr.write("Error: That username is already taken\n") 500 username = None 500 501 while 1: 501 email = raw_input('E-mail address: ')502 if not email: email = raw_input('E-mail address: ') 502 503 try: 503 504 validators.isValidEmail(email, None) 504 505 except validators.ValidationError: 505 sys.stderr.write("Error: That e-mail address is invalid.\n") 506 sys.stderr.write("Error: That e-mail address is invalid\n") 507 email = None 506 508 else: 507 509 break 508 510 while 1: 509 password = getpass.getpass() 510 password2 = getpass.getpass('Password (again): ') 511 if password != password2: 512 sys.stderr.write("Error: Your passwords didn't match.\n") 513 continue 511 if not password: 512 password = getpass.getpass() 513 password2 = getpass.getpass('Password (again): ') 514 if password != password2: 515 sys.stderr.write("Error: Your passwords didn't match.\n") 516 continue 514 517 if password.strip() == '': 515 518 sys.stderr.write("Error: Blank passwords aren't allowed.\n") 519 password = None 516 520 continue 517 521 break 518 522 except KeyboardInterrupt: … … 524 528 u.is_superuser = True 525 529 u.save() 526 530 print "User created successfully." 527 createsuperuser.args = ' '531 createsuperuser.args = '[optional username, email, password]' 528 532 529 533 def inspectdb(db_name): 530 534 "Generator that introspects the tables in the given database name and returns a Django model, one line at a time."