docs: def set_page_permissions(context, token):
      """
      Assigns a permissions dict to the given page instance, combining
      Django's permission for the page's model and a permission check
      against the instance itself calling the page's ``can_add``,
      ``can_change`` and ``can_delete`` custom methods.
  
      Used within the change list for pages, to implement permission
      checks for the navigation tree.
      """
      page = context[token.split_contents()[1]]
      model = page.get_content_model()
      try:
          opts = model._meta
      except AttributeError:
          if model is None:
              error = _("Could not load the model for the following page, "
                        "was it removed?")
              obj = page
          else:
              # A missing inner Meta class usually means the Page model
              # hasn't been directly subclassed.
              error = _("An error occured with the following class. Does "
                        "it subclass Page directly?")
              obj = model.__class__.__name__
          raise ImproperlyConfigured(error + " '%s'" % obj)
      perm_name = opts.app_label + ".%s_" + opts.object_name.lower()
      request = context["request"]
      setattr(page, "perms", {})
      for perm_type in ("add", "change", "delete"):
          perm = request.user.has_perm(perm_name % perm_type)
          perm = perm and getattr(model, "can_%s" % perm_type)(request)
          page.perms[perm_type] = perm
      return ""