aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/wqflask/collect.py20
-rw-r--r--wqflask/wqflask/user_manager.py23
2 files changed, 19 insertions, 24 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py
index f1c6ddd5..fedf6dfc 100644
--- a/wqflask/wqflask/collect.py
+++ b/wqflask/wqflask/collect.py
@@ -15,35 +15,26 @@ import urlparse
import simplejson as json
-#from sqlalchemy import orm
-
-#from redis import StrictRedis
import redis
Redis = redis.StrictRedis()
-
from flask import (Flask, g, render_template, url_for, request, make_response,
redirect, flash, jsonify)
from wqflask import app
-
from pprint import pformat as pf
-
from wqflask.database import db_session
from wqflask import model
+from wqflask import user_manager
from utility import Bunch, Struct
from utility.formatting import numify
-from wqflask import user_manager
-
-
from base import trait
-
def get_collection():
if g.user_session.logged_in:
return UserCollection()
@@ -78,7 +69,6 @@ class AnonCollection(object):
if self.id == None:
self.id = str(uuid.uuid4())
-
def get_members(self):
traits = []
collections_list = json.loads(Redis.get(self.key))
@@ -301,7 +291,7 @@ def create_new(collection_name):
unprocessed_traits = params['traits']
traits = process_traits(unprocessed_traits)
- if 'uc_id' in params:
+ if g.user_session.logged_in:
uc = model.UserCollection()
uc.name = collection_name
print("user_session:", g.user_session.__dict__)
@@ -322,7 +312,7 @@ def create_new(collection_name):
def list_collections():
params = request.args
print("PARAMS:", params)
- if 'uc_id' in params:
+ if g.user_session.logged_in:
user_collections = list(g.user_session.user_ob.user_collections)
print("user_collections are:", user_collections)
return render_template("collections/list.html",
@@ -372,7 +362,7 @@ def remove_traits():
def delete_collection():
params = request.form
print("params:", params)
- if "uc_id" in params:
+ if g.user_session.logged_in:
uc_id = params['uc_id']
uc = model.UserCollection.query.get(uc_id)
# Todo: For now having the id is good enough since it's so unique
@@ -383,7 +373,7 @@ def delete_collection():
collection_name = params['collection_name']
user_manager.AnonUser().delete_collection(collection_name)
- flash("We've deletet the collection: {}.".format(collection_name), "alert-info")
+ flash("We've deleted the collection: {}.".format(collection_name), "alert-info")
return redirect(url_for('list_collections'))
diff --git a/wqflask/wqflask/user_manager.py b/wqflask/wqflask/user_manager.py
index f1a798d4..4ff3e79c 100644
--- a/wqflask/wqflask/user_manager.py
+++ b/wqflask/wqflask/user_manager.py
@@ -62,7 +62,7 @@ def timestamp():
class AnonUser(object):
- cookie_name = 'anon_user_v7'
+ cookie_name = 'anon_user_v8'
def __init__(self):
self.cookie = request.cookies.get(self.cookie_name)
@@ -74,7 +74,6 @@ class AnonUser(object):
logger.debug("creating new cookie")
self.anon_id, self.cookie = create_signed_cookie()
self.key = "anon_collection:v1:{}".format(self.anon_id)
- print("THE KEY IS:", self.key)
@after.after_this_request
def set_cookie(response):
@@ -89,21 +88,27 @@ class AnonUser(object):
Redis.set(self.key, json.dumps(collection_dict))
Redis.expire(self.key, 60 * 60 * 24 * 5)
- len_now = len(Redis.smembers(self.key))
- print("LENGTH NOW:", len_now)
def delete_collection(self, collection_name):
existing_collections = self.get_collections()
+ updated_collections = []
for i, collection in enumerate(existing_collections):
- collection['created_timestamp'] = collection['created_timestamp'].strftime('%b %d %Y %I:%M%p')
- collection['changed_timestamp'] = collection['changed_timestamp'].strftime('%b %d %Y %I:%M%p')
if collection['name'] == collection_name:
- existing_collections.pop(i)
- Redis.set(self.key, json.dumps(existing_collections))
+ continue
+ else:
+ this_collection = {}
+ this_collection['id'] = collection['id']
+ this_collection['name'] = collection['name']
+ this_collection['created_timestamp'] = collection['created_timestamp'].strftime('%b %d %Y %I:%M%p')
+ this_collection['changed_timestamp'] = collection['changed_timestamp'].strftime('%b %d %Y %I:%M%p')
+ this_collection['num_members'] = collection['num_members']
+ this_collection['members'] = collection['members']
+ updated_collections.append(this_collection)
+
+ Redis.set(self.key, json.dumps(updated_collections))
def get_collections(self):
json_collections = Redis.get(self.key)
- print("json_collections:", json_collections)
if json_collections == None or json_collections == "None":
return []
else: