MCPcopy
hub / github.com/django/django / _build_app_dict

Method _build_app_dict

django/contrib/admin/sites.py:469–539  ·  view source on GitHub ↗

Build the app dictionary. The optional `label` parameter filters models of a specific app.

(self, request, label=None)

Source from the content-addressed store, hash-verified

467 raise Http404
468
469 def _build_app_dict(self, request, label=None):
470 """
471 Build the app dictionary. The optional `label` parameter filters models
472 of a specific app.
473 """
474 app_dict = {}
475
476 if label:
477 models = {
478 m: m_a
479 for m, m_a in self._registry.items()
480 if m._meta.app_label == label
481 }
482 else:
483 models = self._registry
484
485 for model, model_admin in models.items():
486 app_label = model._meta.app_label
487
488 has_module_perms = model_admin.has_module_permission(request)
489 if not has_module_perms:
490 continue
491
492 perms = model_admin.get_model_perms(request)
493
494 # Check whether user has any perm for this module.
495 # If so, add the module to the model_list.
496 if True not in perms.values():
497 continue
498
499 info = (app_label, model._meta.model_name)
500 model_dict = {
501 "model": model,
502 "name": capfirst(model._meta.verbose_name_plural),
503 "object_name": model._meta.object_name,
504 "perms": perms,
505 "admin_url": None,
506 "add_url": None,
507 }
508 if perms.get("change") or perms.get("view"):
509 model_dict["view_only"] = not perms.get("change")
510 try:
511 model_dict["admin_url"] = reverse(
512 "admin:%s_%s_changelist" % info, current_app=self.name
513 )
514 except NoReverseMatch:
515 pass
516 if perms.get("add"):
517 try:
518 model_dict["add_url"] = reverse(
519 "admin:%s_%s_add" % info, current_app=self.name
520 )
521 except NoReverseMatch:
522 pass
523
524 if app_label in app_dict:
525 app_dict[app_label]["models"].append(model_dict)
526 else:

Callers 1

get_app_listMethod · 0.95

Calls 9

capfirstFunction · 0.90
reverseFunction · 0.90
get_model_permsMethod · 0.80
get_app_configMethod · 0.80
itemsMethod · 0.45
has_module_permissionMethod · 0.45
valuesMethod · 0.45
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected