@staff_member_required
def set_site(request):
 site_id = int(request.GET[u'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[u'site_id'] = site_id
 admin_url = reverse(u'admin:index')
 next = (next_url(request) or admin_url)
 if next.startswith(admin_url):
  parts = next.split(u'/')
  if ((len(parts) > 4) and parts[4].isdigit()):
   next = u'/'.join(parts[:4])
 return redirect(next)

@ staff_member_required def set_site ( request ) : site_id = int ( request . GET [ u'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 [ u'site_id' ] = site_id admin_url = reverse ( u'admin:index' ) next = ( next_url ( request ) or admin_url ) if next . startswith ( admin_url ) : parts = next . split ( u'/' ) if ( ( len ( parts ) > 4 ) and parts [ 4 ] . isdigit ( ) ) : next = u'/' . join ( parts [ : 4 ] ) return redirect ( next )
put the selected site id into the session - posted to from the "select site" drop-down in the header of the admin .