aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/model.py
diff options
context:
space:
mode:
authorSam2013-10-22 21:01:00 -0500
committerSam2013-10-22 21:01:00 -0500
commitd8f8598ff4fd2a3f6c8ad904b8423782eed5f641 (patch)
tree36573f83709053573c073054084754db51978854 /wqflask/wqflask/model.py
parentad94850e0916346af8cdb72c77f4ef7889d6ee95 (diff)
downloadgenenetwork2-d8f8598ff4fd2a3f6c8ad904b8423782eed5f641.tar.gz
Bunch of work on collections and user management
Diffstat (limited to 'wqflask/wqflask/model.py')
-rw-r--r--wqflask/wqflask/model.py46
1 files changed, 38 insertions, 8 deletions
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py
index 5c514bde..ca1364d7 100644
--- a/wqflask/wqflask/model.py
+++ b/wqflask/wqflask/model.py
@@ -3,6 +3,8 @@ from __future__ import print_function, division, absolute_import
import uuid
import datetime
+import simplejson as json
+
from flask import request
from flask.ext.sqlalchemy import SQLAlchemy
#from flask.ext.security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin
@@ -60,19 +62,49 @@ class User(Base):
__tablename__ = "user"
id = Column(Unicode(36), primary_key=True, default=lambda: unicode(uuid.uuid4()))
email_address = Column(Unicode(50), unique=True, nullable=False)
-
+
# Todo: Turn on strict mode for Mysql
password = Column(Text, nullable=False)
-
+
full_name = Column(Unicode(50))
organization = Column(Unicode(50))
-
+
active = Column(Boolean(), nullable=False, default=True)
registration_info = Column(Text) # json detailing when they were registered, etc.
-
+
confirmed = Column(Text) # json detailing when they confirmed, etc.
+ logins = relationship("Login",
+ order_by="desc(Login.timestamp)",
+ lazy='dynamic' # Necessary for filter in login_count
+ )
+
+ @property
+ def login_count(self):
+ return self.logins.filter_by(successful=True).count()
+ #return self.query.filter
+ #return len(self.logins)
+ #return 8
+ #return len(self.logins.query.filter(User.logins.has(successful=True)))
+
+ @property
+ def confirmed_at(self):
+ if self.confirmed:
+ confirmed_info = json.loads(self.confirmed)
+ return confirmed_info['timestamp']
+ else:
+ return None
+
+ @property
+ def most_recent_login(self):
+ try:
+ return self.logins[0]
+ except IndexError:
+ return None
+
+
+
#last_login_at = Column(DateTime())
#current_login_at = Column(DateTime())
#last_login_ip = Column(Unicode(39))
@@ -90,11 +122,11 @@ class Login(Base):
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
-
+
def __init__(self, user):
self.user = user.id
self.ip_address = request.remote_addr
-
+
# Setup Flask-Security
#user_datastore = SQLAlchemyUserDatastore(db, User, Role)
@@ -107,5 +139,3 @@ class Login(Base):
#user_datastore.create_role(name="Genentech", description="Genentech Beta Project(testing)")
-
-