diff options
-rw-r--r-- | wqflask/wqflask/__init__.py | 4 | ||||
-rw-r--r-- | wqflask/wqflask/oauth2/collections.py | 16 | ||||
-rw-r--r-- | wqflask/wqflask/templates/base.html | 2 | ||||
-rw-r--r-- | wqflask/wqflask/templates/collections/list.html | 8 |
4 files changed, 26 insertions, 4 deletions
diff --git a/wqflask/wqflask/__init__.py b/wqflask/wqflask/__init__.py index 38a69d33..13685324 100644 --- a/wqflask/wqflask/__init__.py +++ b/wqflask/wqflask/__init__.py @@ -32,6 +32,7 @@ from wqflask.api.markdown import news_blueprint from wqflask.api.jobs import jobs as jobs_bp from wqflask.oauth2.routes import oauth2 from wqflask.oauth2.checks import user_logged_in +from wqflask.oauth2.collections import num_collections from wqflask.oauth2.request_utils import user_details, authserver_authorise_uri from wqflask.jupyter_notebooks import jupyter_notebooks @@ -55,7 +56,8 @@ app.jinja_env.globals.update( numify=formatting.numify, logged_in=user_logged_in, authserver_authorise_uri=authserver_authorise_uri, - user_details=user_details) + user_details=user_details, + num_collections=num_collections) app.config["SESSION_REDIS"] = redis.from_url(app.config["REDIS_URL"]) diff --git a/wqflask/wqflask/oauth2/collections.py b/wqflask/wqflask/oauth2/collections.py new file mode 100644 index 00000000..e31b4ad2 --- /dev/null +++ b/wqflask/wqflask/oauth2/collections.py @@ -0,0 +1,16 @@ +"""Functions for collections.""" +from .session import session_info +from .checks import user_logged_in +from .client import oauth2_get, no_token_get + +def num_collections() -> int: + """Compute the number of collections available for tte current sussion.""" + anon_id = session_info()["anon_id"] + all_collections = no_token_get( + f"oauth2/user/collections/{anon_id}/list").either( + lambda _err: [], lambda colls: colls) + if user_logged_in(): + all_collections = all_collections + oauth2_get( + "oauth2/user/collections/list").either( + lambda _err: [], lambda colls: colls) + return len(all_collections) diff --git a/wqflask/wqflask/templates/base.html b/wqflask/wqflask/templates/base.html index 38819240..126e1b82 100644 --- a/wqflask/wqflask/templates/base.html +++ b/wqflask/wqflask/templates/base.html @@ -141,7 +141,7 @@ {% if g.user_session %} <li class=""> <a href="/collections/list">Collections - <span class="badge badge-info">{{ g.user_session.num_collections }}</span> + <span class="badge badge-info">{{num_collections()}}</span> </a> </li> <li class=""> diff --git a/wqflask/wqflask/templates/collections/list.html b/wqflask/wqflask/templates/collections/list.html index 437b0cc3..fc524c73 100644 --- a/wqflask/wqflask/templates/collections/list.html +++ b/wqflask/wqflask/templates/collections/list.html @@ -34,7 +34,7 @@ {{display_error("Anonymous Collections", anon_collections_error)}} {%endif%} {%if anon_collections | length > 0%} - <table class="table-hover table-striped cell-border" id='trait_table' + <table class="table-hover table-striped cell-border" id='anon_trait_table' style="float: left;"> <caption>Anonymous Collections</caption> <thead> @@ -64,7 +64,10 @@ </tbody> </table> {%endif%} - {% if collections|length > 0 %} + {% if collections|length > 0 %} + {% if (anon_collections | length > 0) and (collections | length > 0) %} + <hr /> + {%endif%} <table class="table-hover table-striped cell-border" id='trait_table' style="float: left;"> <caption>User Collections</caption> <thead> @@ -126,6 +129,7 @@ { "type": "natural", "width": "15%", "targets": 5} ]; + create_table("anon_trait_table", [], columnDefs) create_table(tableId, [], columnDefs) submit_special = function(url) { |