aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/collect.py
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask/wqflask/collect.py')
-rw-r--r--wqflask/wqflask/collect.py57
1 files changed, 49 insertions, 8 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py
index f61ea3dc..39a63a1f 100644
--- a/wqflask/wqflask/collect.py
+++ b/wqflask/wqflask/collect.py
@@ -46,16 +46,48 @@ from wqflask import user_manager
@app.route("/collections/add")
def collections_add():
- return render_template("collections/add.html", traits=request.args['traits'])
+ 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,
+ )
@app.route("/collections/new")
def collections_new():
- uc = model.UserCollection()
- uc.name = request.args['new_collection']
- print("user_session:", g.user_session.__dict__)
- uc.user = g.user_session.record['user_id']
- unprocessed_traits = request.args['traits']
+ print("request.args in collections_new are:", request.args)
+ if "create_new" in request.args:
+ return create_new()
+ elif "add_to_existing" in request.args:
+ return add_to_existing()
+ elif "continue" in request.args:
+ return unnamed()
+ else:
+ CauseAnError
+
+
+def unnamed():
+ return "unnamed"
+
+def add_to_existing():
+ params = request.args
+ print("---> params are:", params.keys())
+ print(" type(params):", type(params))
+ uc = model.UserCollection.query.get(params['existing_collection'])
+ members = set(json.loads(uc.members))
+
+ traits = process_traits(params['traits'])
+
+ uc.members = json.dumps(list(members | traits))
+
+ uc.changed_timestamp = datetime.datetime.utcnow()
+
+ db_session.commit()
+
+ return "added to existing, now set is:" + str(uc.members)
+
+def process_traits(unprocessed_traits):
print("unprocessed_traits are:", unprocessed_traits)
unprocessed_traits = unprocessed_traits.split(",")
traits = set()
@@ -66,6 +98,17 @@ def collections_new():
print("hmac is:", hmac)
assert hmac==user_manager.actual_hmac_creation(data), "Data tampering?"
traits.add(str(data))
+ return traits
+
+def create_new():
+ params = request.args
+ uc = model.UserCollection()
+ uc.name = params['new_collection']
+ print("user_session:", g.user_session.__dict__)
+ uc.user = g.user_session.user_id
+ unprocessed_traits = params['traits']
+
+ traits = process_traits(unprocessed_traits)
uc.members = json.dumps(list(traits))
print("traits are:", traits)
@@ -73,6 +116,4 @@ def collections_new():
db_session.add(uc)
db_session.commit()
-
-
return "Created: " + uc.name