MCPcopy
hub / github.com/django/django / create_permissions

Function create_permissions

django/contrib/auth/management/__init__.py:41–111  ·  view source on GitHub ↗
(
    app_config,
    verbosity=2,
    interactive=True,
    using=DEFAULT_DB_ALIAS,
    apps=global_apps,
    **kwargs,
)

Source from the content-addressed store, hash-verified

39
40
41def create_permissions(
42 app_config,
43 verbosity=2,
44 interactive=True,
45 using=DEFAULT_DB_ALIAS,
46 apps=global_apps,
47 **kwargs,
48):
49 if not app_config.models_module:
50 return
51
52 try:
53 Permission = apps.get_model("auth", "Permission")
54 except LookupError:
55 return
56 if not router.allow_migrate_model(using, Permission):
57 return
58
59 # Ensure that contenttypes are created for this app. Needed if
60 # 'django.contrib.auth' is in INSTALLED_APPS before
61 # 'django.contrib.contenttypes'.
62 create_contenttypes(
63 app_config,
64 verbosity=verbosity,
65 interactive=interactive,
66 using=using,
67 apps=apps,
68 **kwargs,
69 )
70
71 app_label = app_config.label
72 try:
73 app_config = apps.get_app_config(app_label)
74 ContentType = apps.get_model("contenttypes", "ContentType")
75 except LookupError:
76 return
77
78 models = list(app_config.get_models())
79
80 # Grab all the ContentTypes.
81 ctypes = ContentType.objects.db_manager(using).get_for_models(
82 *models, for_concrete_models=False
83 )
84
85 # Find all the Permissions that have a content_type for a model we're
86 # looking for. We don't need to check for codenames since we already have
87 # a list of the ones we're going to create.
88 all_perms = set(
89 Permission.objects.using(using)
90 .filter(
91 content_type__in=set(ctypes.values()),
92 )
93 .values_list("content_type", "codename")
94 )
95
96 perms = []
97 for model in models:
98 ctype = ctypes[model]

Calls 15

create_contenttypesFunction · 0.90
_get_all_permissionsFunction · 0.85
PermissionClass · 0.85
get_app_configMethod · 0.80
get_for_modelsMethod · 0.80
db_managerMethod · 0.80
values_listMethod · 0.80
bulk_createMethod · 0.80
get_modelMethod · 0.45
allow_migrate_modelMethod · 0.45
get_modelsMethod · 0.45
filterMethod · 0.45