| 1 |
def is_user_happy(request): |
| 2 |
return request.user.is_auth and request.user.is_happy |
| 3 |
|
| 4 |
|
| 5 |
def is_paid_user(request): |
| 6 |
return request.user.is_auth and request.user.is_happy |
| 7 |
|
| 8 |
|
| 9 |
def is_main_site(request): |
| 10 |
""" |
| 11 |
Non-User condition. |
| 12 |
""" |
| 13 |
return True |
| 14 |
|
| 15 |
|
| 16 |
def validator_with_parameters(request, param1, param2): |
| 17 |
return True |
| 18 |
|
| 19 |
|
| 20 |
class TestUser(object): |
| 21 |
""" |
| 22 |
Test User Object. |
| 23 |
""" |
| 24 |
is_auth = False |
| 25 |
is_staff = False |
| 26 |
is_superuser = False |
| 27 |
is_happy = False |
| 28 |
is_paid = False |
| 29 |
permissions = [] |
| 30 |
|
| 31 |
def __init__(self, staff=False, superuser=False, authenticated=False, happy=False, paid=False): |
| 32 |
self.is_auth = authenticated |
| 33 |
self.is_staff = authenticated and staff |
| 34 |
self.is_superuser = authenticated and superuser |
| 35 |
self.is_happy = authenticated and happy |
| 36 |
self.is_paid = authenticated and paid |
| 37 |
self.permissions = [] |
| 38 |
|
| 39 |
@property |
| 40 |
def is_authenticated(self): |
| 41 |
return self.is_auth |
| 42 |
|
| 43 |
def add_perm(self, permission): |
| 44 |
""" |
| 45 |
Method for add a permission to test user |
| 46 |
:param permission: Permission to be added |
| 47 |
""" |
| 48 |
self.permissions.append(permission) |
| 49 |
|
| 50 |
def has_perm(self, permission): |
| 51 |
""" |
| 52 |
Method for checking if a test user has a permission |
| 53 |
:param permission: Permission to be checked |
| 54 |
:return: Boolean indicating if a test user has a permission or not |
| 55 |
""" |
| 56 |
return permission in self.permissions |