aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/wqflask/templates/base.html2
-rw-r--r--wqflask/wqflask/user_manager.py22
2 files changed, 23 insertions, 1 deletions
diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html
index 759c4a8d..6af07edc 100644
--- a/wqflask/wqflask/templates/base.html
+++ b/wqflask/wqflask/templates/base.html
@@ -43,6 +43,8 @@
<a href="/collections/list">Collections
{% if g.user_session.user_ob %}
<span class="badge badge-info">{{ g.user_session.user_ob.display_num_collections() }}</span>
+ {% else %}
+ <span class="badge badge-info">{{ g.cookie_session.display_num_collections() }}</span>
{% endif %}
</a>
</li>
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index e91c7327..31754ff5 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -99,6 +99,25 @@ class AnonUser(object):
return {}
else:
return json.loads(collections)
+
+ def display_num_collections(self):
+ """
+ Returns the number of collections or a blank string if there are zero.
+
+ Because this is so unimportant...we wrap the whole thing in a try/expect...last thing we
+ want is a webpage not to be displayed because of an error here
+
+ Importand TODO: use redis to cache this, don't want to be constantly computing it
+ """
+ try:
+ num = len(self.get_collections().keys())
+ if num > 0:
+ return num
+ else:
+ return ""
+ except Exception as why:
+ print("Couldn't display_num_collections:", why)
+ return ""
def verify_cookie(cookie):
the_uuid, separator, the_signature = cookie.partition(':')
@@ -186,7 +205,8 @@ class UserSession(object):
@app.before_request
def before_request():
g.user_session = UserSession()
-
+ g.cookie_session = AnonUser()
+
class UsersManager(object):
def __init__(self):
self.users = model.User.query.all()