forked from jpic/django-social
/
shortcuts.py
44 lines (30 loc) · 1.05 KB
/
shortcuts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import datetime
from subscription.examples.yourlabs.notification import Lazy, Notification
def emit_lazy(*args, **kwargs):
kwargs['lazy'] = True
if len(args) == 0:
cls = Notification
else:
cls = args[0]
if getattr(cls, 'kwargs_factory', False):
kwargs = cls.kwargs_factory(**kwargs)
for key, value in kwargs.items():
kwargs[key] = Lazy(value)
if 'timestamp' not in kwargs.keys() and 'sent_at' not in kwargs.keys():
kwargs['sent_at'] = datetime.datetime.now()
notification = cls(**kwargs)
notification.emit()
return notification
def emit_static(*args, **kwargs):
kwargs['lazy'] = False
if len(args) == 0:
cls = Notification
else:
cls = args[0]
if 'timestamp' not in kwargs.keys() and 'sent_at' not in kwargs.keys():
kwargs['sent_at'] = datetime.datetime.now()
if getattr(cls, 'kwargs_factory', False):
kwargs = cls.kwargs_factory(**kwargs)
notification = cls(**kwargs)
notification.emit()
return notification