mirror of
https://github.com/django/django.git
synced 2025-06-05 19:49:13 +00:00
Reflow django/contrib/auth/management/__init__.py for readability.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14408 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
15b3350d30
commit
282e53b499
@ -17,24 +17,29 @@ def _get_all_permissions(opts):
|
|||||||
|
|
||||||
def create_permissions(app, created_models, verbosity, **kwargs):
|
def create_permissions(app, created_models, verbosity, **kwargs):
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.contrib.auth.models import Permission
|
|
||||||
app_models = get_models(app)
|
app_models = get_models(app)
|
||||||
if not app_models:
|
|
||||||
return
|
|
||||||
for klass in app_models:
|
for klass in app_models:
|
||||||
ctype = ContentType.objects.get_for_model(klass)
|
ctype = ContentType.objects.get_for_model(klass)
|
||||||
for codename, name in _get_all_permissions(klass._meta):
|
for codename, name in _get_all_permissions(klass._meta):
|
||||||
p, created = Permission.objects.get_or_create(codename=codename, content_type__pk=ctype.id,
|
p, created = auth_app.Permission.objects.get_or_create(
|
||||||
defaults={'name': name, 'content_type': ctype})
|
codename=codename,
|
||||||
|
content_type__pk=ctype.id,
|
||||||
|
defaults={
|
||||||
|
'name': name,
|
||||||
|
'content_type': ctype
|
||||||
|
}
|
||||||
|
)
|
||||||
if created and verbosity >= 2:
|
if created and verbosity >= 2:
|
||||||
print "Adding permission '%s'" % p
|
print "Adding permission '%s'" % p
|
||||||
|
|
||||||
def create_superuser(app, created_models, verbosity, **kwargs):
|
def create_superuser(app, created_models, verbosity, **kwargs):
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
if User in created_models and kwargs.get('interactive', True):
|
|
||||||
msg = "\nYou just installed Django's auth system, which means you don't have " \
|
if auth_app.User in created_models and kwargs.get('interactive', True):
|
||||||
"any superusers defined.\nWould you like to create one now? (yes/no): "
|
msg = ("\nYou just installed Django's auth system, which means you "
|
||||||
|
"don't have any superusers defined.\nWould you like to create one "
|
||||||
|
"now? (yes/no): ")
|
||||||
confirm = raw_input(msg)
|
confirm = raw_input(msg)
|
||||||
while 1:
|
while 1:
|
||||||
if confirm not in ('yes', 'no'):
|
if confirm not in ('yes', 'no'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user