aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/model.py
diff options
context:
space:
mode:
authorLei Yan2014-07-14 16:23:12 +0000
committerLei Yan2014-07-14 17:02:01 +0000
commit214bf0128b8ecdda718983c5563cf34160743758 (patch)
tree917e7a5ae78dc4ff65dc08d107a0e3ae3a47c67c /wqflask/wqflask/model.py
parent8de6fec18cd98a10c58702c448a1e01e147dc5f7 (diff)
parentfbdbf4b7410185e2a978ecc8e120ae56ff6da0ce (diff)
downloadgenenetwork2-214bf0128b8ecdda718983c5563cf34160743758.tar.gz
Merge /home/zas1024/gene
Conflicts: wqflask/wqflask/static/new/javascript/dataset_select_menu.js wqflask/wqflask/templates/corr_scatter_plot_old.html
Diffstat (limited to 'wqflask/wqflask/model.py')
-rwxr-xr-x[-rw-r--r--]wqflask/wqflask/model.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py
index b508f18e..fa8c1aab 100644..100755
--- 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,24 @@ 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 ""
+
+
+def user_uuid():
+ """Unique cookie for a user"""
+ user_uuid = request.cookies.get('user_uuid')
+ \ No newline at end of file