Revision 8fb8d0cf snf-astakos-app/astakos/im/util.py
b/snf-astakos-app/astakos/im/util.py | ||
---|---|---|
40 | 40 |
from datetime import tzinfo, timedelta |
41 | 41 |
|
42 | 42 |
from django.http import HttpResponse, HttpResponseBadRequest, urlencode, \ |
43 |
HttpResponseRedirect
|
|
43 |
HttpResponseRedirect |
|
44 | 44 |
from django.template import RequestContext |
45 | 45 |
from django.contrib.auth import authenticate |
46 | 46 |
from django.core.urlresolvers import reverse |
47 | 47 |
from django.shortcuts import redirect |
48 | 48 |
from django.core.exceptions import ValidationError, ObjectDoesNotExist |
49 | 49 |
from django.utils.translation import ugettext as _ |
50 |
from django.core.urlresolvers import reverse |
|
51 | 50 |
|
52 | 51 |
from astakos.im.models import AstakosUser, Invitation |
53 | 52 |
from astakos.im.functions import login |
... | ... | |
75 | 74 |
return d.replace(tzinfo=UTC()).isoformat() |
76 | 75 |
|
77 | 76 |
|
78 |
def epoch(datetime):
|
|
79 |
return int(time.mktime(datetime.timetuple()) * 1000)
|
|
77 |
def epoch(dt):
|
|
78 |
return int(time.mktime(dt.timetuple()) * 1000)
|
|
80 | 79 |
|
81 | 80 |
|
82 | 81 |
def get_context(request, extra_context=None, **kwargs): |
... | ... | |
224 | 223 |
response.status_code = 302 |
225 | 224 |
return response |
226 | 225 |
|
226 |
|
|
227 | 227 |
class lazy_string(object): |
228 | 228 |
def __init__(self, function, *args, **kwargs): |
229 | 229 |
self.function = function |
... | ... | |
254 | 254 |
except AttributeError: |
255 | 255 |
return {} |
256 | 256 |
|
257 |
|
|
257 | 258 |
def get_properties(obj): |
258 | 259 |
def get_class_attr(_class, attr): |
259 | 260 |
try: |
... | ... | |
261 | 262 |
except AttributeError: |
262 | 263 |
return |
263 | 264 |
|
264 |
return (i for i in vars(obj.__class__) \ |
|
265 |
if isinstance(get_class_attr(obj.__class__, i), property)) |
|
265 |
return (i for i in vars(obj.__class__) |
|
266 |
if isinstance(get_class_attr(obj.__class__, i), property)) |
|
267 |
|
|
266 | 268 |
|
267 | 269 |
def model_to_dict(obj, exclude=['AutoField', 'ForeignKey', 'OneToOneField'], |
268 | 270 |
include_empty=True): |
... | ... | |
280 | 282 |
except (ObjectDoesNotExist, AttributeError): |
281 | 283 |
continue |
282 | 284 |
|
283 |
if field.__class__.__name__ in ['RelatedManager', 'ManyRelatedManager']: |
|
285 |
if field.__class__.__name__ in ['RelatedManager', |
|
286 |
'ManyRelatedManager']: |
|
284 | 287 |
if field.model.__name__ in exclude: |
285 | 288 |
continue |
286 | 289 |
|
... | ... | |
312 | 315 |
tree[field_name] = value |
313 | 316 |
properties = list(get_properties(obj)) |
314 | 317 |
for p in properties: |
315 |
tree[p] = getattr(obj, p) |
|
318 |
tree[p] = getattr(obj, p)
|
|
316 | 319 |
tree['str_repr'] = obj.__str__() |
317 | 320 |
|
318 | 321 |
return tree |
319 | 322 |
|
323 |
|
|
320 | 324 |
def login_url(request): |
321 | 325 |
attrs = {} |
322 | 326 |
for attr in ['login', 'key', 'code']: |
Also available in: Unified diff