showard | ff90138 | 2008-07-07 23:22:16 +0000 | [diff] [blame] | 1 | import threading |
| 2 | |
showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 3 | # when using the models from a script, use this object to avoid null checks all |
| 4 | # over the place |
| 5 | class NullUser(object): |
| 6 | def is_superuser(self): |
| 7 | return True |
| 8 | |
| 9 | |
showard | ff90138 | 2008-07-07 23:22:16 +0000 | [diff] [blame] | 10 | _store = threading.local() |
showard | 2bab8f4 | 2008-11-12 18:15:22 +0000 | [diff] [blame] | 11 | _store.user = NullUser() |
showard | ff90138 | 2008-07-07 23:22:16 +0000 | [diff] [blame] | 12 | |
| 13 | def set_user(user): |
| 14 | """\ |
| 15 | Sets the current request's logged-in user. user should be a |
| 16 | afe.models.User object. |
| 17 | """ |
| 18 | _store.user = user |
| 19 | |
| 20 | |
| 21 | def get_user(): |
| 22 | 'Get the currently logged-in user as a afe.models.User object.' |
| 23 | return _store.user |