| Conditions | 6 |
| Total Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | from django.core.exceptions import PermissionDenied |
||
| 11 | def method_wrapper(f): |
||
| 12 | def wrap(*args, **kwargs): |
||
| 13 | # handle self |
||
| 14 | request = args[0] if isinstance(args[0], HttpRequest) else args[1] |
||
| 15 | if request.user.is_authenticated(): |
||
| 16 | return f(*args, **kwargs) |
||
| 17 | else: |
||
| 18 | if do_redirect is None: |
||
| 19 | raise PermissionDenied |
||
| 20 | else: |
||
| 21 | type_arg = "login" if do_redirect else "register" |
||
| 22 | return redirect('/register?type={}&next={}'.format(type_arg, request.path)) |
||
| 23 | |||
| 24 | wrap.__doc__ = f.__doc__ |
||
| 25 | wrap.__name__ = f.__name__ |
||
| 26 | return wrap |
||
| 27 | return method_wrapper |