Revision e4c26c85 snf-astakos-app/astakos/im/notification_xctx.py

b/snf-astakos-app/astakos/im/notification_xctx.py
44 44
#     ...
45 45
#     return http response
46 46
#
47
# OR
47
# OR (more cleanly)
48 48
#
49 49
# def a_view(args):
50 50
#     with notification_transaction_context(notify=False) as ctx:
......
56 56
def notification_transaction_context(**kwargs):
57 57
    return TransactionHandler(ctx=NotificationTransactionContext, **kwargs)
58 58

  
59

  
59 60
class NotificationTransactionContext(TransactionContext):
60 61
    def __init__(self, notify=True, **kwargs):
61 62
        self._notifications = []
......
66 67
    def register(self, o):
67 68
        if isinstance(o, dict):
68 69
            msg = o.get('msg', None)
69
            if msg is not None and request is not None:
70
            if msg is not None:
70 71
                if isinstance(msg, basestring):
71 72
                    self.queue_message(msg)
72 73

  
73 74
            notif = o.get('notif', None)
74
            fst, snd = o
75
            if isinstance(snd, Notification):
76
                self.queue_notification(snd)
77
                return fst
75
            if notif is not None:
76
                if isinstance(notif, Notification):
77
                    self.queue_notification(notif)
78

  
79
            if o.has_key('value'):
80
                return o['value']
78 81
        return o
79 82

  
80
    def queue_message(m):
83
    def queue_message(self, m):
81 84
        self._messages.append(m)
82 85

  
83 86
    def queue_notification(self, n):

Also available in: Unified diff