diff options
author | Zachary Sloan | 2014-02-26 23:40:31 +0000 |
---|---|---|
committer | Zachary Sloan | 2014-02-26 23:40:31 +0000 |
commit | b1fd0e00050ef7ba95fd077fb78773265629fb1b (patch) | |
tree | f1e3bffccd956114e023cf03082abb59f6238853 | |
parent | f016dc75c7fed1e55e6e459bdf497f4149425137 (diff) | |
download | genenetwork2-b1fd0e00050ef7ba95fd077fb78773265629fb1b.tar.gz |
Collection page now displays for temp/anon collections, but
still needs the option to remove traits from them
-rw-r--r-- | wqflask/wqflask/collect.py | 38 | ||||
-rw-r--r-- | wqflask/wqflask/user_manager.py | 5 | ||||
-rw-r--r-- | wqflask/wqflask/views.py | 10 |
3 files changed, 38 insertions, 15 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py index 77be68b2..5a68c7c9 100644 --- a/wqflask/wqflask/collect.py +++ b/wqflask/wqflask/collect.py @@ -74,19 +74,38 @@ def collections_new(): collection_name = params['new_collection'] if "create_new" in params: + print("in create_new") return create_new(collection_name) elif "add_to_existing" in params: + print("in add to existing") return add_traits(params, collection_name) else: + print("ELSE") CauseAnError def add_anon_traits(params): # Todo: assert user isn't logged in anon_id = user_manager.AnonUser().anon_id + print("anon_id is:", anon_id) + + key = "anon_collection:v1:" + anon_id + + len_before = len(Redis.smembers(key)) traits = process_traits(params['traits']) - print("anon traits:", traits) + print("redis key is:", key) + Redis.expire(key, 60*60*72) + for trait in traits: + Redis.sadd(key, trait) + #print("set members:", Redis.smembers(key)) + + len_now = len(Redis.smembers(key)) + new_length = len_now - len_before + print("new_length:", new_length) + #print("anon traits:", traits) + + return redirect(url_for('view_collection', key=key)) def add_traits(params, collection_name): print("---> params are:", params.keys()) @@ -211,9 +230,16 @@ def delete_collection(): def view_collection(): params = request.args print("params in view collection:", params) - uc_id = params['uc_id'] - uc = model.UserCollection.query.get(uc_id) - traits = json.loads(uc.members) + + if "uc_id" in params: + uc_id = params['uc_id'] + uc = model.UserCollection.query.get(uc_id) + traits = json.loads(uc.members) + else: + anon_id = params['key'] + uc = model.AnonCollection + traits = Redis.smembers(anon_id) + print("the traits are:", traits) print("in view_collection traits are:", traits) @@ -236,9 +262,9 @@ def view_collection(): # lrs_location=trait_ob.LRS_location_repr)) # dis=trait_ob.description)) #json_version.append(trait_ob.__dict__th) - + collection_info = dict(trait_obs=trait_obs, - uc = uc) + uc = uc) if "json" in params: print("json_version:", json_version) return json.dumps(json_version) diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py index 3d50cb4c..e4fb60e4 100644 --- a/wqflask/wqflask/user_manager.py +++ b/wqflask/wqflask/user_manager.py @@ -63,14 +63,15 @@ class AnonUser(object): def __init__(self): self.cookie = request.cookies.get(self.cookie_name) if self.cookie: - self.anon_id = verify_cookie(cookie) + print("already is cookie") + self.anon_id = verify_cookie(self.cookie) else: + print("creating new cookie") self.anon_id, self.cookie = create_signed_cookie() @after.after_this_request def set_cookie(response): response.set_cookie(self.cookie_name, self.cookie) - def verify_cookie(cookie): diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index c3048ca4..d3a7d6ce 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -14,8 +14,9 @@ import simplejson as json #import json import yaml -from redis import Redis -Redis = Redis() +#Switching from Redis to StrictRedis; might cause some issues +import redis +Redis = redis.StrictRedis() import flask import sqlalchemy @@ -342,11 +343,6 @@ 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 ################################################################################################### |