aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/model.py
diff options
context:
space:
mode:
authorzsloan2021-04-30 18:40:13 +0000
committerzsloan2021-04-30 18:40:13 +0000
commit21b2e2a552b8b6bedb789263543a4d6d039ac8a9 (patch)
treefe55511b99a522198c1b840909d7b91c9b45ab22 /wqflask/wqflask/model.py
parent699b952c7bda5426f3f3e947454f656a4ec7538b (diff)
parent799b25481fffc97e2adb07004adf502096bf371c (diff)
downloadgenenetwork2-21b2e2a552b8b6bedb789263543a4d6d039ac8a9.tar.gz
Merge branch 'testing' of github.com:genenetwork/genenetwork2 into testing
Diffstat (limited to 'wqflask/wqflask/model.py')
-rw-r--r--wqflask/wqflask/model.py51
1 files changed, 32 insertions, 19 deletions
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py
index 772f74e4..a222b87c 100644
--- a/wqflask/wqflask/model.py
+++ b/wqflask/wqflask/model.py
@@ -14,9 +14,11 @@ from sqlalchemy.orm import relationship
from wqflask.database import Base, init_db
+
class User(Base):
__tablename__ = "user"
- id = Column(Unicode(36), primary_key=True, default=lambda: str(uuid.uuid4()))
+ id = Column(Unicode(36), primary_key=True,
+ default=lambda: str(uuid.uuid4()))
email_address = Column(Unicode(50), unique=True, nullable=False)
# Todo: Turn on strict mode for Mysql
@@ -27,23 +29,25 @@ class User(Base):
active = Column(Boolean(), nullable=False, default=True)
- registration_info = Column(Text) # json detailing when they were registered, etc.
+ # json detailing when they were registered, etc.
+ registration_info = Column(Text)
- confirmed = Column(Text) # json detailing when they confirmed, etc.
+ confirmed = Column(Text) # json detailing when they confirmed, etc.
- superuser = Column(Text) # json detailing when they became a superuser, otherwise empty
- # if not superuser
+ # json detailing when they became a superuser, otherwise empty
+ superuser = Column(Text)
+ # if not superuser
logins = relationship("Login",
order_by="desc(Login.timestamp)",
- lazy='dynamic', # Necessary for filter in login_count
+ lazy='dynamic', # Necessary for filter in login_count
foreign_keys="Login.user",
)
user_collections = relationship("UserCollection",
- order_by="asc(UserCollection.name)",
- lazy='dynamic',
- )
+ order_by="asc(UserCollection.name)",
+ lazy='dynamic',
+ )
def display_num_collections(self):
"""
@@ -63,11 +67,11 @@ class User(Base):
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).first()
- except sqlalchemy.orm.exc.NoResultFound:
+ collect = self.user_collections.filter_by(
+ name=collection_name).first()
+ except sqlalchemy.orm.exc.NoResultFound:
collect = None
return collect
@@ -83,7 +87,6 @@ class User(Base):
def login_count(self):
return self.logins.filter_by(successful=True).count()
-
@property
def confirmed_at(self):
if self.confirmed:
@@ -116,14 +119,18 @@ class User(Base):
except IndexError:
return None
+
class Login(Base):
__tablename__ = "login"
- id = Column(Unicode(36), primary_key=True, default=lambda: str(uuid.uuid4()))
+ id = Column(Unicode(36), primary_key=True,
+ default=lambda: str(uuid.uuid4()))
user = Column(Unicode(36), ForeignKey('user.id'))
timestamp = Column(DateTime(), default=lambda: datetime.datetime.utcnow())
ip_address = Column(Unicode(39))
- successful = Column(Boolean(), nullable=False) # False if wrong password was entered
- session_id = Column(Text) # Set only if successfully logged in, otherwise should be blank
+ # False if wrong password was entered
+ successful = Column(Boolean(), nullable=False)
+ # Set only if successfully logged in, otherwise should be blank
+ session_id = Column(Text)
# Set to user who assumes identity if this was a login for debugging purposes by a superuser
assumed_by = Column(Unicode(36), ForeignKey('user.id'))
@@ -134,15 +141,19 @@ class Login(Base):
##################################################################################################
+
class UserCollection(Base):
__tablename__ = "user_collection"
- id = Column(Unicode(36), primary_key=True, default=lambda: str(uuid.uuid4()))
+ id = Column(Unicode(36), primary_key=True,
+ default=lambda: str(uuid.uuid4()))
user = Column(Unicode(36), ForeignKey('user.id'))
# I'd prefer this to not have a length, but for the index below it needs one
name = Column(Unicode(50))
- created_timestamp = Column(DateTime(), default=lambda: datetime.datetime.utcnow())
- changed_timestamp = Column(DateTime(), default=lambda: datetime.datetime.utcnow())
+ created_timestamp = Column(
+ DateTime(), default=lambda: datetime.datetime.utcnow())
+ changed_timestamp = Column(
+ DateTime(), default=lambda: datetime.datetime.utcnow())
members = Column(Text) # We're going to store them as a json list
# This index ensures a user doesn't have more than one collection with the same name
@@ -158,12 +169,14 @@ class UserCollection(Base):
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')