class Set(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(32), db.ForeignKey('user.username')) name = db.Column(db.String(50)) start = db.Column(db.Integer) end = db.Column(db.Integer) low_or_high = db.Column(db.String( 4)) # Whether this set contains 'low', 'high', or 'any' observations. eor = db.Column(db.String( 4)) # Whether this set contains 'EOR0', 'EOR1', or 'any' observations. total_data_hrs = db.Column(db.Float) flagged_data_hrs = db.Column(db.Float) created_on = db.Column(db.DateTime, default=datetime.utcnow)
class User(db.Model): username = db.Column(db.String(32), primary_key=True) # SHA-512 returns a 512-bit hash, which is 512 bits / 8 bits per byte * 2 hex digits per byte = 128 hex digits. password = db.Column(db.String(128), nullable=False) # 254 is the maximum length of an email address. email = db.Column(db.String(254), nullable=False) first_name = db.Column(db.String(50), nullable=False) last_name = db.Column(db.String(50), nullable=False) owned_sets = db.relationship('Set', backref='user') subscribed_sets = db.relationship('Set', secondary=set_subscriptions) subscribed_data_sources = db.relationship( 'GraphDataSource', secondary=data_source_subscriptions) active_data_sources = db.relationship('GraphDataSource', secondary=active_data_sources) admin = db.Column(db.Boolean, default=False) def __init__(self, username, password, email, first_name, last_name): self.username = username self.password = password self.email = email self.first_name = first_name self.last_name = last_name def __repr__(self): return '<User %r>' % (self.username) def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return self.username
class GraphDataSource(db.Model): name = db.Column(db.String(100), primary_key=True) graph_type = db.Column(db.String(100), db.ForeignKey('graph_type.name')) host = db.Column(db.String(100)) database = db.Column(db.String(100)) table = db.Column(db.String(100)) obs_column = db.Column( db.String(100)) # Which column has the observation ids. projectid = db.Column( db.Boolean) # Whether the table has a projectid field. width_slider = db.Column( db.Boolean ) # Whether the graph should come with a column width slider.
class GraphDataSourceColumn(db.Model): id = db.Column(db.Integer, primary_key=True) graph_data_source = db.Column(db.String(100), db.ForeignKey('graph_data_source.name')) name = db.Column(db.String(100))
class GraphType(db.Model): name = db.Column(db.String(100), primary_key=True)
class Comment(db.Model): id = db.Column(db.Integer, primary_key=True) thread_id = db.Column(db.Integer, db.ForeignKey('thread.id')) text = db.Column(db.String(1000), nullable=False) username = db.Column(db.String(32), db.ForeignKey('user.username')) created_on = db.Column(db.DateTime, default=datetime.utcnow)
class Thread(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) username = db.Column(db.String(32), db.ForeignKey('user.username')) created_on = db.Column(db.DateTime, default=datetime.utcnow) last_updated = db.Column(db.DateTime, default=datetime.utcnow)
from app.flask_app import db from datetime import datetime set_subscriptions = db.Table( 'set_subscriptions', db.Column('username', db.String(32), db.ForeignKey('user.username')), db.Column('set_id', db.Integer, db.ForeignKey('set.id'))) data_source_subscriptions = db.Table( 'data_source_subscriptions', db.Column('username', db.String(32), db.ForeignKey('user.username')), db.Column('data_source', db.String(100), db.ForeignKey('graph_data_source.name'))) active_data_sources = db.Table( 'active_data_sources', db.Column('username', db.String(32), db.ForeignKey('user.username')), db.Column('data_source', db.String(100), db.ForeignKey('graph_data_source.name'))) class User(db.Model): username = db.Column(db.String(32), primary_key=True) # SHA-512 returns a 512-bit hash, which is 512 bits / 8 bits per byte * 2 hex digits per byte = 128 hex digits. password = db.Column(db.String(128), nullable=False) # 254 is the maximum length of an email address. email = db.Column(db.String(254), nullable=False) first_name = db.Column(db.String(50), nullable=False) last_name = db.Column(db.String(50), nullable=False) owned_sets = db.relationship('Set', backref='user') subscribed_sets = db.relationship('Set', secondary=set_subscriptions)