aboutsummaryrefslogtreecommitdiff
path: root/app/app_sessions.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/app_sessions.py')
-rw-r--r--app/app_sessions.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/app_sessions.py b/app/app_sessions.py
index 89521fb..7a931d5 100644
--- a/app/app_sessions.py
+++ b/app/app_sessions.py
@@ -15,6 +15,33 @@ cookie_key = environ['COOKIE_SECRET_KEY']
15SessionManager = partial(SessionMiddleware, secret_key=cookie_key) 15SessionManager = partial(SessionMiddleware, secret_key=cookie_key)
16 16
17 17
18class FlashMessageQueue:
19 """
20 Session decorator for managing session flash messages to be displayed to
21 the user from one page to another. This suits confirmation and error
22 messages. Messages are stored in the session cookie, which is limited in
23 size to about 4kb.
24 """
25
26 def __init__(self, request: Request):
27 if 'messages' not in request.session:
28 request.session['messages'] = []
29
30 self._messages = request.session['messages']
31
32 def add(self, class_: str, message: str):
33 self._messages.append((class_, message))
34
35 def __iter__(self):
36 return self
37
38 def __next__(self):
39 if not self._messages:
40 raise StopIteration
41
42 return self._messages.pop(0)
43
44
18class UserSession: 45class UserSession:
19 """ 46 """
20 Session decorator for managing user login sessions. 47 Session decorator for managing user login sessions.