Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 37 lines (29 sloc) 1.277 kB
0b23bf6 @diogobaeder Notification documentation
authored
1 '''
e6c6349 @diogobaeder Inserting dict-like behaviour with setitem and getitem
authored
2 This module is the same as the sessions module, except that:
3 1. NotificationMixin sets a "notifications" property instead a "session" one,
4 and that the NotificationManager ("notifications") gets an object only once, and
5 deletes it from the database after retrieving;
50ed4b4 @diogobaeder Supporting custom dataset numbers
authored
6 2. The objects are stored in db 1 (for default) instead of 0 to avoid conflicts
7 with sessions. (You can change this setting with the "db_notifications" setting
35a9a97 @diogobaeder Changing settings structure
authored
8 in the "storage" setting.)
0b23bf6 @diogobaeder Notification documentation
authored
9 '''
10
b3c9cd6 @diogobaeder Using numeric identifiers for databases
authored
11 from pycket.session import create_mixin, SessionManager, SessionMixin
f369ad9 @diogobaeder Adding notification support
authored
12
13
14 class NotificationManager(SessionManager):
4645d09 @diogobaeder Encapsulating driver creation logic into factory
authored
15 STORAGE_CATEGORY = 'db_notifications'
f369ad9 @diogobaeder Adding notification support
authored
16
e6c6349 @diogobaeder Inserting dict-like behaviour with setitem and getitem
authored
17 def get(self, name, default=None):
0b23bf6 @diogobaeder Notification documentation
authored
18 '''
19 Retrieves the object with "name", like with SessionManager.get(), but
20 removes the object from the database after retrieval, so that it can be
21 retrieved only once
22 '''
b3c9cd6 @diogobaeder Using numeric identifiers for databases
authored
23
e6c6349 @diogobaeder Inserting dict-like behaviour with setitem and getitem
authored
24 session_object = super(NotificationManager, self).get(name, default)
f369ad9 @diogobaeder Adding notification support
authored
25 if session_object is not None:
26 self.delete(name)
27 return session_object
28
29
b3c9cd6 @diogobaeder Using numeric identifiers for databases
authored
30 class NotificationMixin(object):
f369ad9 @diogobaeder Adding notification support
authored
31 @property
f0a7262 @diogobaeder Changing from 'notification' to 'notifications'
authored
32 def notifications(self):
f369ad9 @diogobaeder Adding notification support
authored
33 '''
34 Returns a NotificationManager instance
35 '''
36
b3c9cd6 @diogobaeder Using numeric identifiers for databases
authored
37 return create_mixin(self, '__notification_manager', NotificationManager)
Something went wrong with that request. Please try again.