aboutsummaryrefslogtreecommitdiff
path: root/app/app_sessions.py
diff options
context:
space:
mode:
authorpacien2021-07-29 18:04:48 +0200
committerpacien2021-07-29 18:04:48 +0200
commit57ff25198a82b3f6f413440e4005f0ade8dfb8d8 (patch)
tree817c43e04b3413d773a999c1950e1af43f26c3e2 /app/app_sessions.py
parentf80c19c18eb01ed7e7c6f44cc25535c14659ba20 (diff)
downloaduge_l2_rdbms_python_proto-57ff25198a82b3f6f413440e4005f0ade8dfb8d8.tar.gz
app: render and serve proper web pages
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.