From: Ben Darnell Date: Mon, 13 May 2013 00:02:54 +0000 (-0400) Subject: Allow handlers to assign to self.current_user X-Git-Tag: v3.1.0~76^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b0f5d6c983584bc4bb04a5750222e7a6b1a2fbe;p=thirdparty%2Ftornado.git Allow handlers to assign to self.current_user --- diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 5e813e5d0..a1df2eb83 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -1278,3 +1278,18 @@ class MultipleExceptionTest(SimpleHandlerTestCase): # seen at least three of them by now (the fourth may still be # in the queue). self.assertGreater(MultipleExceptionTest.Handler.exc_count, 2) + + +class SetCurrentUserTest(SimpleHandlerTestCase): + class Handler(RequestHandler): + def prepare(self): + self.current_user = 'Ben' + + def get(self): + self.write('Hello %s' % self.current_user) + + def test_set_current_user(self): + # Ensure that current_user can be assigned to normally for apps + # that want to forgo the lazy get_current_user property + response = self.fetch('/') + self.assertEqual(response.body, b'Hello Ben') diff --git a/tornado/web.py b/tornado/web.py index 686d8de39..bc97766eb 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -900,6 +900,10 @@ class RequestHandler(object): self._current_user = self.get_current_user() return self._current_user + @current_user.setter + def current_user(self, value): + self._current_user = value + def get_current_user(self): """Override to determine the current user from, e.g., a cookie.""" return None