aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/model.py
diff options
context:
space:
mode:
authorZachary Sloan2014-02-25 21:31:16 +0000
committerZachary Sloan2014-02-25 21:31:16 +0000
commitf4f4b8a0badba231a72ab41d86d87408c871ac1b (patch)
tree48cfdaf0204cb75d15b199ebcc09b7d3b8c59b8c /wqflask/wqflask/model.py
parentd8a6e48b4896d8ce74d9c082c21101a5a288cb80 (diff)
parent1ab9e95d11da24e087774ac38786ae934f783fa6 (diff)
downloadgenenetwork2-f4f4b8a0badba231a72ab41d86d87408c871ac1b.tar.gz
Merge /home/sam/gene
Diffstat (limited to 'wqflask/wqflask/model.py')
-rw-r--r--wqflask/wqflask/model.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py
index b508f18e..71bda550 100644
--- a/wqflask/wqflask/model.py
+++ b/wqflask/wqflask/model.py
@@ -10,6 +10,8 @@ from flask.ext.sqlalchemy import SQLAlchemy
from wqflask import app
+import sqlalchemy
+
from sqlalchemy import (Column, Integer, String, Table, ForeignKey, Unicode, Boolean, DateTime,
Text, Index)
from sqlalchemy.orm import relationship, backref
@@ -57,8 +59,35 @@ class User(Base):
user_collections = relationship("UserCollection",
order_by="asc(UserCollection.name)",
+ lazy='dynamic',
)
+ def display_num_collections(self):
+ """
+ Returns the number of collections or a blank string if there are zero.
+
+
+ Because this is so unimportant...we wrap the whole thing in a try/expect...last thing we
+ want is a webpage not to be displayed because of an error here
+
+ Importand TODO: use redis to cache this, don't want to be constantly computing it
+
+ """
+ try:
+ num = len(list(self.user_collections))
+ return display_collapsible(num)
+ except Exception as why:
+ print("Couldn't display_num_collections:", why)
+ return ""
+
+
+ def get_collection_by_name(self, collection_name):
+ try:
+ collect = self.user_collections.filter_by(name=collection_name).one()
+ except sqlalchemy.orm.exc.NoResultFound:
+ collect = None
+ return collect
+
@property
def name_and_org(self):
"""Nice shortcut for printing out who the user is"""
@@ -145,3 +174,18 @@ class UserCollection(Base):
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))
+
+
+def display_collapsible(number):
+ if number:
+ return number
+ else:
+ return ""