aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/model.py
diff options
context:
space:
mode:
authorZachary Sloan2013-10-11 14:46:52 -0500
committerZachary Sloan2013-10-11 14:46:52 -0500
commit34c6c908ac072609a2f923946d474504d3fa0331 (patch)
tree8f7635a312115419bf8ce12602fe9c46e048a92c /wqflask/wqflask/model.py
parent51be798ef6311a86ea1ca8c5092277d727b98a5a (diff)
parent38ae30a5fb46753a361e1c7454871430d7097c3b (diff)
downloadgenenetwork2-34c6c908ac072609a2f923946d474504d3fa0331.tar.gz
Merge /home/sam/gene
Diffstat (limited to 'wqflask/wqflask/model.py')
-rw-r--r--wqflask/wqflask/model.py110
1 files changed, 77 insertions, 33 deletions
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py
index 5beba9ff..5c514bde 100644
--- a/wqflask/wqflask/model.py
+++ b/wqflask/wqflask/model.py
@@ -1,12 +1,25 @@
from __future__ import print_function, division, absolute_import
+import uuid
+import datetime
+
+from flask import request
from flask.ext.sqlalchemy import SQLAlchemy
-from flask.ext.security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin
+#from flask.ext.security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin
+
+#from flask_security.forms import TextField
+#from flask_security.forms import RegisterForm
from wqflask import app
+from sqlalchemy import Column, Integer, String, Table, ForeignKey, Unicode, Boolean, DateTime, Text
+from sqlalchemy.orm import relationship, backref
+
+from wqflask.database import Base, init_db
+
# Create database connection object
-db = SQLAlchemy(app)
+#db = SQLAlchemy(app)
+
# Is this right? -Sam
#from sqlalchemy.ext.declarative import declarative_base
@@ -23,45 +36,76 @@ db = SQLAlchemy(app)
# """
# print("in get cls is:", cls)
# print(" key is {} : {}".format(type(key), key))
-# query = db.Model.query(cls)
+# query = Model.query(cls)
# print("query is: ", query)
# record = query.get(key)
# return record
#
#
-#print("db.Model is:", vars(db.Model))
-#db.Model.get = get
+#print("Model is:", vars(Model))
+#Model.get = get
# Define models
-roles_users = db.Table('roles_users',
- db.Column('user_id', db.Integer(), db.ForeignKey('user.id')),
- db.Column('role_id', db.Integer(), db.ForeignKey('role.id')))
-
-class Role(db.Model, RoleMixin):
- id = db.Column(db.Integer(), primary_key=True)
- name = db.Column(db.String(80), unique=True)
- description = db.Column(db.String(255))
-
-class User(db.Model, UserMixin):
- id = db.Column(db.Integer(), primary_key=True)
- email = db.Column(db.String(255), unique=True)
- password = db.Column(db.String(255))
- active = db.Column(db.Boolean())
- confirmed_at = db.Column(db.DateTime())
-
- last_login_at = db.Column(db.DateTime())
- current_login_at = db.Column(db.DateTime())
- last_login_ip = db.Column(db.String(39))
- current_login_ip = db.Column(db.String(39))
- login_count = db.Column(db.Integer())
-
- roles = db.relationship('Role', secondary=roles_users,
- backref=db.backref('users', lazy='dynamic'))
+#roles_users = Table('roles_users',
+# Column('user_id', Integer(), ForeignKey('user.the_id')),
+# Column('role_id', Integer(), ForeignKey('role.the_id')))
+
+class Role(Base):
+ __tablename__ = "role"
+ id = Column(Unicode(36), primary_key=True, default=lambda: unicode(uuid.uuid4()))
+ name = Column(Unicode(80), unique=True, nullable=False)
+ description = Column(Unicode(255))
+
+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.
+
+ #last_login_at = Column(DateTime())
+ #current_login_at = Column(DateTime())
+ #last_login_ip = Column(Unicode(39))
+ #current_login_ip = Column(Unicode(39))
+ #login_count = Column(Integer())
+
+ #roles = relationship('Role', secondary=roles_users,
+ # backref=backref('users', lazy='dynamic'))
+
+class Login(Base):
+ __tablename__ = "login"
+ id = Column(Unicode(36), primary_key=True, default=lambda: unicode(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
+
+ def __init__(self, user):
+ self.user = user.id
+ self.ip_address = request.remote_addr
+
# Setup Flask-Security
-user_datastore = SQLAlchemyUserDatastore(db, User, Role)
-security = Security(app, user_datastore)
+#user_datastore = SQLAlchemyUserDatastore(db, User, Role)
+
+#class ExtendedRegisterForm(RegisterForm):
+# name = TextField('name')
+# #print("name is:", name['_name'], vars(name))
+# organization = TextField('organization')
+#
+#security = Security(app, user_datastore, register_form=ExtendedRegisterForm)
+
+
+#user_datastore.create_role(name="Genentech", description="Genentech Beta Project(testing)")
-db.metadata.create_all(db.engine)
-user_datastore.create_role(name="Genentech", description="Genentech Beta Project(testing)")