docs: def set_site(request):
      """
      Put the selected site ID into the session - posted to from
      the "Select site" drop-down in the header of the admin. The
      site ID is then used in favour of the current request's
      domain in ``yacms.core.managers.CurrentSiteManager``.
      """
      site_id = int(request.GET["site_id"])
      if not request.user.is_superuser:
          try:
              SitePermission.objects.get(user=request.user, sites=site_id)
          except SitePermission.DoesNotExist:
              raise PermissionDenied
      request.session["site_id"] = site_id
      admin_url = reverse("admin:index")
      next = next_url(request) or admin_url
      # Don't redirect to a change view for an object that won't exist
      # on the selected site - go to its list view instead.
      if next.startswith(admin_url):
          parts = next.split("/")
          if len(parts) > 4 and parts[4].isdigit():
              next = "/".join(parts[:4])
      return redirect(next)