diff options
author | Zachary Sloan | 2013-06-20 22:20:23 +0000 |
---|---|---|
committer | Zachary Sloan | 2013-06-20 22:20:23 +0000 |
commit | 4ffee373494170e708678039dca132f1bd729ab1 (patch) | |
tree | a9d6054380f5a9d612a4d1d88889f68ea4923a75 /wqflask/wqflask/model.py | |
parent | 939058c4a3b668037974f2876b072c4be008da26 (diff) | |
parent | 52ac4b6e1c014801080cbbcad53df868058d2657 (diff) | |
download | genenetwork2-4ffee373494170e708678039dca132f1bd729ab1.tar.gz |
Merge branch 'flask'
Diffstat (limited to 'wqflask/wqflask/model.py')
-rw-r--r-- | wqflask/wqflask/model.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py new file mode 100644 index 00000000..5beba9ff --- /dev/null +++ b/wqflask/wqflask/model.py @@ -0,0 +1,67 @@ +from __future__ import print_function, division, absolute_import + +from flask.ext.sqlalchemy import SQLAlchemy +from flask.ext.security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin + +from wqflask import app + +# Create database connection object +db = SQLAlchemy(app) + +# Is this right? -Sam +#from sqlalchemy.ext.declarative import declarative_base +#Base = declarative_base() + +#@classmethod +#def get(cls, key): +# """Convenience get method using the primary key +# +# If record doesn't exist, returns None +# +# Allows the following: User.get('121') +# +# """ +# print("in get cls is:", cls) +# print(" key is {} : {}".format(type(key), key)) +# query = db.Model.query(cls) +# print("query is: ", query) +# record = query.get(key) +# return record +# +# +#print("db.Model is:", vars(db.Model)) +#db.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')) + +# Setup Flask-Security +user_datastore = SQLAlchemyUserDatastore(db, User, Role) +security = Security(app, user_datastore) + +db.metadata.create_all(db.engine) + +user_datastore.create_role(name="Genentech", description="Genentech Beta Project(testing)") |