parameters: (request)
return_statement: return my_redirect('/exam/')
docstring: Allow moderator to switch to student and back
docstring_summary: Allow moderator to switch to student and back
docstring_tokens: Allow moderator to switch to student and back
function: def toggle_moderator_role(request):
      """ Allow moderator to switch to student and back """
  
      user = request.user
  
      try:
          group = Group.objects.get(name='moderator')
      except Group.DoesNotExist:
          raise Http404('The Moderator group does not exist')
  
      if not user.profile.is_moderator:
          raise Http404('You are not allowed to view this page!')
  
      if user not in group.user_set.all():
          group.user_set.add(user)
      else:
          group.user_set.remove(user)
  
      return my_redirect('/exam/')
function_tokens: def toggle_moderator_role ( request ) : user = request . user try : group = Group . objects . get ( name = 'moderator' ) except Group . DoesNotExist : raise Http404 ( 'The Moderator group does not exist' ) if not user . profile . is_moderator : raise Http404 ( 'You are not allowed to view this page!' ) if user not in group . user_set . all ( ) : group . user_set . add ( user ) else : group . user_set . remove ( user ) return my_redirect ( '/exam/' )