Total Complexity | 2 |
Total Lines | 14 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
1 | import random |
||
7 | class UserCookieMiddleWare(object): |
||
8 | """ |
||
9 | Middleware to set user cookie |
||
10 | If user is authenticated and there is no cookie, set the cookie, |
||
11 | If the user is not authenticated and the cookie remains, delete it |
||
12 | """ |
||
13 | |||
14 | def process_request(self, request): |
||
15 | try: |
||
16 | local.random |
||
17 | except AttributeError: |
||
18 | local.random = str(random.randint(0, 10000)).rjust(4, '0') |
||
19 | local.user = str(getattr(request.user, 'username', '')).rjust(8, ' ') |
||
20 | local.client_ip = get_client_ip(request) |
||
21 |