diff options
author | Sam | 2014-01-30 04:35:21 +0000 |
---|---|---|
committer | Sam | 2014-01-30 04:35:21 +0000 |
commit | c4f507c6e1042a1e42f0fe8c08e2eff13fa12d8c (patch) | |
tree | c2354d7308237c6e43d09482d855a5f74e046d68 /wqflask | |
parent | a9f63aadeeedb7c28bbcd16396c8c6e7d5cbbfd0 (diff) | |
download | genenetwork2-c4f507c6e1042a1e42f0fe8c08e2eff13fa12d8c.tar.gz |
Before trying to fix user login issue
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/collect.py | 19 | ||||
-rw-r--r-- | wqflask/wqflask/model.py | 30 | ||||
-rw-r--r-- | wqflask/wqflask/templates/base.html | 8 |
3 files changed, 51 insertions, 6 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py index 29b73130..b1ea46d8 100644 --- a/wqflask/wqflask/collect.py +++ b/wqflask/wqflask/collect.py @@ -48,12 +48,19 @@ from base import trait @app.route("/collections/add") def collections_add(): - user_collections = g.user_session.user_ob.user_collections - print("user_collections are:", user_collections) - return render_template("collections/add.html", - traits=request.args['traits'], - user_collections = user_collections, - ) + traits=request.args['traits'], + + if g.user_session.logged_in: + user_collections = g.user_session.user_ob.user_collections + print("user_collections are:", user_collections) + return render_template("collections/add.html", + traits=traits, + user_collections = user_collections, + ) + else: + return render_template("collections/add_anonymous.html", + traits=traits + ) @app.route("/collections/new") diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py index e588e78a..71bda550 100644 --- a/wqflask/wqflask/model.py +++ b/wqflask/wqflask/model.py @@ -62,6 +62,25 @@ class User(Base): lazy='dynamic', ) + 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(list(self.user_collections)) + return display_collapsible(num) + except Exception as why: + print("Couldn't display_num_collections:", why) + return "" + + def get_collection_by_name(self, collection_name): try: collect = self.user_collections.filter_by(name=collection_name).one() @@ -156,6 +175,17 @@ class UserCollection(Base): print("members are:", json.loads(self.members)) return len(json.loads(self.members)) + #@property + #def display_num_members(self): + # return display_collapsible(self.num_members) + def members_as_set(self): return set(json.loads(self.members)) + + +def display_collapsible(number): + if number: + return number + else: + return "" diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html index 9b98c955..48078670 100644 --- a/wqflask/wqflask/templates/base.html +++ b/wqflask/wqflask/templates/base.html @@ -104,6 +104,14 @@ <a href="/links">Links</a> </li> <li class=""> + <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> + {% endif %} + </a> + </li> + + <li class=""> {% if g.user_session.logged_in %} <a id="login_out" title="Signed in as {{ g.user_session.user_ob.name_and_org }}." href="/n/logout">Sign out</a> {% else %} |