diff options
author | Zachary Sloan | 2014-02-25 23:27:20 +0000 |
---|---|---|
committer | Zachary Sloan | 2014-02-25 23:27:20 +0000 |
commit | f016dc75c7fed1e55e6e459bdf497f4149425137 (patch) | |
tree | a93048befab2c62e840434b08d31b6d0de76a5d3 /wqflask/wqflask | |
parent | 16672f2b8d486ea5ec6b460a2436043610996b01 (diff) | |
download | genenetwork2-f016dc75c7fed1e55e6e459bdf497f4149425137.tar.gz |
Made some more progress towards getting anonymous collections working
Diffstat (limited to 'wqflask/wqflask')
-rw-r--r-- | wqflask/wqflask/collect.py | 15 | ||||
-rw-r--r-- | wqflask/wqflask/user_manager.py | 11 | ||||
-rw-r--r-- | wqflask/wqflask/views.py | 6 |
3 files changed, 24 insertions, 8 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py index b1ea46d8..77be68b2 100644 --- a/wqflask/wqflask/collect.py +++ b/wqflask/wqflask/collect.py @@ -48,7 +48,7 @@ from base import trait @app.route("/collections/add") def collections_add(): - traits=request.args['traits'], + traits=request.args['traits'] if g.user_session.logged_in: user_collections = g.user_session.user_ob.user_collections @@ -68,19 +68,25 @@ def collections_new(): params = request.args print("request.args in collections_new are:", params) + if "anonymous_add" in params: + return add_anon_traits(params) + collection_name = params['new_collection'] if "create_new" in params: return create_new(collection_name) elif "add_to_existing" in params: return add_traits(params, collection_name) - elif "Default" in params: - return add_traits(params, "Default") - else: CauseAnError +def add_anon_traits(params): + # Todo: assert user isn't logged in + anon_id = user_manager.AnonUser().anon_id + traits = process_traits(params['traits']) + print("anon traits:", traits) + def add_traits(params, collection_name): print("---> params are:", params.keys()) @@ -122,6 +128,7 @@ def process_traits(unprocessed_traits): unprocessed_traits = unprocessed_traits.split(",") traits = set() for trait in unprocessed_traits: + print("trait is:", trait) data, _separator, hmac = trait.rpartition(':') data = data.strip() print("data is:", data) diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py index a80dff3b..3d50cb4c 100644 --- a/wqflask/wqflask/user_manager.py +++ b/wqflask/wqflask/user_manager.py @@ -30,7 +30,7 @@ import redis Redis = redis.StrictRedis() -from flask import (Flask, g, render_template, url_for, request, make_response, +from flask import (Flask, g, render_template, url_for, request, make_response, redirect, flash, abort) from wqflask import app @@ -66,8 +66,11 @@ class AnonUser(object): self.anon_id = verify_cookie(cookie) else: self.anon_id, self.cookie = create_signed_cookie() - after.set_cookie(self.cookie_name, self.cookie) - + + @after.after_this_request + def set_cookie(response): + response.set_cookie(self.cookie_name, self.cookie) + def verify_cookie(cookie): @@ -81,7 +84,7 @@ def verify_cookie(cookie): def create_signed_cookie(): the_uuid = str(uuid.uuid4()) signature = actual_hmac_creation(the_uuid) - uuid_signed = the_id + ":" + signature + uuid_signed = the_uuid + ":" + signature print("uuid_signed:", uuid_signed) return the_uuid, uuid_signed diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 89820145..c3048ca4 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -342,6 +342,12 @@ def get_temp_data(): temp_uuid = request.args['key'] return flask.jsonify(temp_data.TempData(temp_uuid).get_all()) +@app.after_request +def call_after_request_callbacks(response): + for callback in getattr(g, 'after_request_callbacks', ()): + callback(response) + return response + ################################################################################################### |