diff options
Diffstat (limited to 'wqflask/base')
-rw-r--r-- | wqflask/base/trait_collection.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/wqflask/base/trait_collection.py b/wqflask/base/trait_collection.py index 797a4d63..49b0eaea 100644 --- a/wqflask/base/trait_collection.py +++ b/wqflask/base/trait_collection.py @@ -22,6 +22,45 @@ from sqlalchemy import (Column, Integer, String, Table, ForeignKey, Unicode, Boo Text, Index)
from sqlalchemy.orm import relationship, backref
+#from redis import StrictRedis
+import redis
+Redis = redis.StrictRedis()
+
from wqflask.database import Base, init_db
class TraitCollection(object):
+
+
+class AnonCollection(TraitCollection):
+
+ def __init__(self, anon_id)
+ self.anon_id = anon_id
+ self.collection_members = Redis.smembers(self.anon_id)
+ print("self.collection_members is:", self.collection_members)
+ self.num_members = len(self.collection_members)
+
+
+ @app.route("/collections/remove", methods=('POST',))
+ def remove_traits(traits_to_remove):
+ print("traits_to_remove:", traits_to_remove)
+ for trait in traits_to_remove:
+ Redis.srem(self.anon_id, trait)
+ members_now = self.collection_members - traits_to_remove
+ print("members_now:", members_now)
+ print("Went from {} to {} members in set.".format(len(self.collection_members), len(members_now)))
+
+ # We need to return something so we'll return this...maybe in the future
+ # we can use it to check the results
+ return str(len(members_now))
+
+ @property
+ def num_members(self):
+ print("members are:", json.loads(self.members))
+ return len(json.loads(self.members))
+
+ #@property
+ #def display_num_members(self):
+ # return display_collapsible(self.num_members)
+
+ def members_as_set(self):
+ return set(json.loads(self.members))
\ No newline at end of file |