Django

Code

Show
Ignore:
Timestamp:
06/09/08 23:03:09 (7 months ago)
Author:
brosner
Message:

newforms-admin: Merged from trunk up to [7602].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin

    • Property svnmerge-integrated changed from /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7583 to /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6390,6392-7603
  • django/branches/newforms-admin/django/contrib/auth/create_superuser.py

    r7022 r7604  
    11""" 
    2 Helper function for creating superusers in the authentication system. 
    3  
    4 If run from the command line, this module lets you create a superuser 
    5 interactively. 
     2Create a superuser from the command line. Deprecated; use manage.py 
     3createsuperuser instead. 
    64""" 
    75 
    8 from django.core import validators 
    9 from django.contrib.auth.models import User 
    10 import getpass 
    11 import os 
    12 import sys 
    13 import re 
    14  
    15 RE_VALID_USERNAME = re.compile('\w+$') 
    16  
    17 def createsuperuser(username=None, email=None, password=None): 
    18     """ 
    19     Helper function for creating a superuser from the command line. All 
    20     arguments are optional and will be prompted-for if invalid or not given. 
    21     """ 
    22     try: 
    23         import pwd 
    24     except ImportError: 
    25         default_username = '' 
    26     else: 
    27         # Determine the current system user's username, to use as a default. 
    28         default_username = pwd.getpwuid(os.getuid())[0].replace(' ', '').lower() 
    29  
    30     # Determine whether the default username is taken, so we don't display 
    31     # it as an option. 
    32     if default_username: 
    33         try: 
    34             User.objects.get(username=default_username) 
    35         except User.DoesNotExist: 
    36             pass 
    37         else: 
    38             default_username = '' 
    39  
    40     try: 
    41         while 1: 
    42             if not username: 
    43                 input_msg = 'Username' 
    44                 if default_username: 
    45                     input_msg += ' (Leave blank to use %r)' % default_username 
    46                 username = raw_input(input_msg + ': ') 
    47             if default_username and username == '': 
    48                 username = default_username 
    49             if not RE_VALID_USERNAME.match(username): 
    50                 sys.stderr.write("Error: That username is invalid. Use only letters, digits and underscores.\n") 
    51                 username = None 
    52                 continue 
    53             try: 
    54                 User.objects.get(username=username) 
    55             except User.DoesNotExist: 
    56                 break 
    57             else: 
    58                 sys.stderr.write("Error: That username is already taken.\n") 
    59                 username = None 
    60         while 1: 
    61             if not email: 
    62                 email = raw_input('E-mail address: ') 
    63             try: 
    64                 validators.isValidEmail(email, None) 
    65             except validators.ValidationError: 
    66                 sys.stderr.write("Error: That e-mail address is invalid.\n") 
    67                 email = None 
    68             else: 
    69                 break 
    70         while 1: 
    71             if not password: 
    72                 password = getpass.getpass() 
    73                 password2 = getpass.getpass('Password (again): ') 
    74                 if password != password2: 
    75                     sys.stderr.write("Error: Your passwords didn't match.\n") 
    76                     password = None 
    77                     continue 
    78             if password.strip() == '': 
    79                 sys.stderr.write("Error: Blank passwords aren't allowed.\n") 
    80                 password = None 
    81                 continue 
    82             break 
    83     except KeyboardInterrupt: 
    84         sys.stderr.write("\nOperation cancelled.\n") 
    85         sys.exit(1) 
    86     u = User.objects.create_user(username, email, password) 
    87     u.is_staff = True 
    88     u.is_active = True 
    89     u.is_superuser = True 
    90     u.save() 
    91     print "Superuser created successfully." 
    92  
    936if __name__ == "__main__": 
    94     createsuperuser() 
     7    from django.core.management import call_command 
     8    call_command("createsuperuser")