Revision 270dd48d snf-astakos-app/astakos/im/util.py
b/snf-astakos-app/astakos/im/util.py | ||
---|---|---|
46 | 46 |
from django.contrib.auth import login, authenticate |
47 | 47 |
from django.core.urlresolvers import reverse |
48 | 48 |
|
49 |
from astakos.im.models import AstakosUser, Invitation |
|
49 |
from astakos.im.models import AstakosUser, Invitation, ApprovalTerms
|
|
50 | 50 |
from astakos.im.settings import INVITATIONS_PER_LEVEL, COOKIE_NAME, COOKIE_DOMAIN, COOKIE_SECURE, FORCE_PROFILE_UPDATE |
51 | 51 |
|
52 | 52 |
logger = logging.getLogger(__name__) |
... | ... | |
128 | 128 |
expired, if the 'renew' parameter is present |
129 | 129 |
or user has not a valid token. |
130 | 130 |
""" |
131 |
|
|
132 | 131 |
renew = renew or (not user.auth_token) |
133 | 132 |
renew = renew or (user.auth_token_expires and user.auth_token_expires < datetime.datetime.now()) |
134 | 133 |
if renew: |
... | ... | |
161 | 160 |
response.set_cookie(COOKIE_NAME, value=cookie_value, |
162 | 161 |
expires=expire_fmt, path='/', |
163 | 162 |
domain=COOKIE_DOMAIN, secure=COOKIE_SECURE) |
163 |
|
|
164 |
class lazy_string(object): |
|
165 |
def __init__(self, function, *args, **kwargs): |
|
166 |
self.function=function |
|
167 |
self.args=args |
|
168 |
self.kwargs=kwargs |
|
169 |
|
|
170 |
def __str__(self): |
|
171 |
if not hasattr(self, 'str'): |
|
172 |
self.str=self.function(*self.args, **self.kwargs) |
|
173 |
return self.str |
|
174 |
|
|
175 |
def reverse_lazy(*args, **kwargs): |
|
176 |
return lazy_string(reverse, *args, **kwargs) |
|
177 |
|
|
178 |
def has_signed_terms(user): |
|
179 |
if not user.has_signed_terms: |
|
180 |
return False |
|
181 |
try: |
|
182 |
term = ApprovalTerms.objects.order_by('-id')[0] |
|
183 |
if user.date_signed_terms < term.date: |
|
184 |
return False |
|
185 |
except IndexError: |
|
186 |
pass |
|
187 |
return True |
Also available in: Unified diff