aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam2013-10-23 16:00:40 -0500
committerSam2013-10-23 16:00:40 -0500
commit5c5671f3c3353f6adc1ce5d9cab8f9f4de5a4e05 (patch)
treecbbde9627627607805624a7af54e54460fc8ca5c
parentd8f8598ff4fd2a3f6c8ad904b8423782eed5f641 (diff)
downloadgenenetwork2-5c5671f3c3353f6adc1ce5d9cab8f9f4de5a4e05.tar.gz
Adding new collections works
-rw-r--r--wqflask/wqflask/collect.py14
-rw-r--r--wqflask/wqflask/model.py65
2 files changed, 24 insertions, 55 deletions
diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py
index 4ec37014..f61ea3dc 100644
--- a/wqflask/wqflask/collect.py
+++ b/wqflask/wqflask/collect.py
@@ -51,7 +51,10 @@ def collections_add():
@app.route("/collections/new")
def collections_new():
- new_collection = request.args['new_collection']
+ uc = model.UserCollection()
+ uc.name = request.args['new_collection']
+ print("user_session:", g.user_session.__dict__)
+ uc.user = g.user_session.record['user_id']
unprocessed_traits = request.args['traits']
print("unprocessed_traits are:", unprocessed_traits)
unprocessed_traits = unprocessed_traits.split(",")
@@ -64,5 +67,12 @@ def collections_new():
assert hmac==user_manager.actual_hmac_creation(data), "Data tampering?"
traits.add(str(data))
+ uc.members = json.dumps(list(traits))
print("traits are:", traits)
- return "Created: " + new_collection
+
+ db_session.add(uc)
+ db_session.commit()
+
+
+
+ return "Created: " + uc.name
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py
index ca1364d7..c89dc80a 100644
--- a/wqflask/wqflask/model.py
+++ b/wqflask/wqflask/model.py
@@ -7,10 +7,6 @@ import simplejson as json
from flask import request
from flask.ext.sqlalchemy import SQLAlchemy
-#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
@@ -19,33 +15,7 @@ from sqlalchemy.orm import relationship, backref
from wqflask.database import Base, init_db
-# 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 = Model.query(cls)
-# print("query is: ", query)
-# record = query.get(key)
-# return record
-#
-#
-#print("Model is:", vars(Model))
-#Model.get = get
+
# Define models
#roles_users = Table('roles_users',
@@ -83,10 +53,7 @@ class User(Base):
@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):
@@ -104,16 +71,10 @@ class User(Base):
return None
-
- #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()))
@@ -127,15 +88,13 @@ class Login(Base):
self.user = user.id
self.ip_address = request.remote_addr
-# Setup Flask-Security
-#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)")
+class UserCollection(Base):
+ __tablename__ = "user_collection"
+ id = Column(Unicode(36), primary_key=True, default=lambda: unicode(uuid.uuid4()))
+ user = Column(Unicode(36), ForeignKey('user.id'))
+ name = Column(Text)
+ 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