def test_redirection_url_stack(self): self.assertFalse('redirection_url_stack' in self.request.session) for url in self.test_urls: push_redirection_url_stack(self.request, url) self.assertIn(url, self.request.session['redirection_url_stack']) self.assertTrue('redirection_url_stack' in self.request.session) i = 0 for test_url in self.test_urls[::-1]: i += 1 redirection_url = http_redirect(self.request) self.assertEqual(redirection_url.url, test_url) self.assertNotIn(test_url, self.request.session['redirection_url_stack']) self.assertEqual(len(self.request.session['redirection_url_stack']), len(self.test_urls) - i) self.assertEqual(len(self.request.session['redirection_url_stack']), 0) self.assertEqual('/', http_redirect(self.request).url) self.assertEqual('/', http_redirect(self.request).url)
def redirect_login_redirect(request, redirection_url): ''' When a potential subject is trying to access an experiment page but is not yet logged in, we must first redirect them to the login page. If they would like to proceed they will then either log in, or else if they do not already have an account, or forgotten their password, they will find their way to the signup sheet or to the forgot-my-password page, take care of business there and then log in. After all that, we redirect them to the page that they were trying to reach initially. ''' push_redirection_url_stack(request, redirection_url) return redirect(login_url)