Mercurial > libervia-web
comparison libervia/server/session_iface.py @ 1186:352865f4a268
server: added a generic way to have notification messages in pages
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 26 May 2019 22:16:07 +0200 |
parents | 6424d3684d1e |
children | b2d067339de3 |
comparison
equal
deleted
inserted
replaced
1185:7d6c0e5d5f34 | 1186:352865f4a268 |
---|---|
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 from zope.interface import Interface, Attribute, implements | 19 from zope.interface import Interface, Attribute, implements |
20 from sat.tools.common import data_objects | 20 from sat.tools.common import data_objects |
21 from libervia.server.constants import Const as C | 21 from libervia.server.constants import Const as C |
22 from libervia.server.classes import Notification | |
22 from collections import OrderedDict | 23 from collections import OrderedDict |
23 import os.path | 24 import os.path |
24 import shortuuid | 25 import shortuuid |
25 import time | 26 import time |
26 | 27 |
27 FLAGS_KEY = "_flags" | 28 FLAGS_KEY = "_flags" |
29 NOTIFICATIONS_KEY = "_notifications" | |
28 MAX_CACHE_AFFILIATIONS = 100 # number of nodes to keep in cache | 30 MAX_CACHE_AFFILIATIONS = 100 # number of nodes to keep in cache |
29 | 31 |
30 | 32 |
31 class ISATSession(Interface): | 33 class ISATSession(Interface): |
32 profile = Attribute("Sat profile") | 34 profile = Attribute("Sat profile") |
140 del self.pages_data[page] | 142 del self.pages_data[page] |
141 return True | 143 return True |
142 else: | 144 else: |
143 return False | 145 return False |
144 | 146 |
147 def setPageNotification(self, page, message, level=C.LVL_INFO): | |
148 """set a flag for this page | |
149 | |
150 @param page(LiberviaPage): instance of the page | |
151 @param flag(unicode): flag to set | |
152 """ | |
153 notif = Notification(message, level) | |
154 notifs = self.getPageData(page, NOTIFICATIONS_KEY) | |
155 if notifs is None: | |
156 notifs = self.setPageData(page, NOTIFICATIONS_KEY, []) | |
157 notifs.append(notif) | |
158 | |
159 def popPageNotifications(self, page): | |
160 """Return and remove last page notification | |
161 | |
162 @param page(LiberviaPage): instance of the page | |
163 @return (list[Notification]): notifications if any | |
164 """ | |
165 page_data = self.pages_data.get(page, {}) | |
166 notifs = page_data.get(NOTIFICATIONS_KEY) | |
167 if not notifs: | |
168 return [] | |
169 ret = notifs[:] | |
170 del notifs[:] | |
171 return ret | |
172 | |
145 def getAffiliation(self, service, node): | 173 def getAffiliation(self, service, node): |
146 """retrieve affiliation for a pubsub node | 174 """retrieve affiliation for a pubsub node |
147 | 175 |
148 @param service(jid.JID): pubsub service | 176 @param service(jid.JID): pubsub service |
149 @param node(unicode): pubsub node | 177 @param node(unicode): pubsub node |