Ticket #9444: anonuser.management.__init__.patch

File anonuser.management.__init__.patch, 1.5 KB (added by Digitalxero, 16 years ago)

Add the Signal Listener to ask if they wish to create an Anon User

  • \django\contrib\auth\management\__init__.py

    old new  
    4343            if confirm == 'yes':
    4444                call_command("createsuperuser", interactive=True)
    4545            break
     46           
     47def create_anonuser(app, created_models, verbosity, **kwargs):
     48    from django.contrib.auth.models import User
     49    from django.core.management import call_command
     50    if User in created_models and kwargs.get('interactive', True):
     51        msg = "\nYou just installed Django's auth system, which means you don't have " \
     52                "an anonymous user defined.\nWould you like to create one now? (yes/no): "
     53        confirm = raw_input(msg)
     54        while 1:
     55            if confirm not in ('yes', 'no'):
     56                confirm = raw_input('Please enter either "yes" or "no": ')
     57                continue
     58            if confirm == 'yes':
     59                call_command("createanonuser", interactive=False)
     60            break
    4661
    4762signals.post_syncdb.connect(create_permissions,
    4863    dispatch_uid = "django.contrib.auth.management.create_permissions")
     64signals.post_syncdb.connect(create_anonuser,
     65    sender=auth_app, dispatch_uid = "django.contrib.auth.management.create_anonuser")
    4966signals.post_syncdb.connect(create_superuser,
    5067    sender=auth_app, dispatch_uid = "django.contrib.auth.management.create_superuser")
Back to Top