Skip to content
Browse files

Make the first argument of shortcuts \(notif class\) optionnal

  • Loading branch information...
1 parent 4121fa7 commit 665e02552232d1834a3c7d2a3ada54c783633542 @jpic committed
Showing with 20 additions and 4 deletions.
  1. +20 −4 subscription/examples/yourlabs/shortcuts.py
View
24 subscription/examples/yourlabs/shortcuts.py
@@ -1,24 +1,40 @@
import datetime
-from subscription.examples.yourlabs.notification import Lazy
+from subscription.examples.yourlabs.notification import Lazy, Notification
-def emit_lazy(cls, **kwargs):
+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(cls, **kwargs):
+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)

0 comments on commit 665e025

Please sign in to comment.
Something went wrong with that request. Please try again.