class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) user_picture = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) # All the children relationships to the user about_post = db.relationship('About_Post', backref='author', lazy=True) blog_posts = db.relationship('Blog_Post', backref='author', lazy=True) portfolio_posts = db.relationship('Portfolio_Post', backref="author", lazy=True) home_post = db.relationship('Home_Post', backref='author', lazy=True) gallery_posts = db.relationship('Gallery_Post', backref='author', lazy=True) # GETTING RESET TOKEN # get locked out? password reset? def get_reset_token(self, expires_sec=1800): # THIS MIGHT NEED TO BE CHANGED TO LOCAL VARIABLE IF IT DOESN'T WORK s = Serializer(current_app.config['SECRET_KEY']) return s.dumps({'user_id' : self.id}).decode('utf-8') # verifying the token @staticmethod def verify_reset_token(token): s = Serializer(current_app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}')"
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(30), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) confirmed = db.Column(db.Boolean, nullable=False, default=False) otp_secret = db.Column(db.String(16), nullable=False) questions = db.relationship("Question", backref="author", lazy=True) answers = db.relationship("Answer", backref="author", lazy=True) comments = db.relationship("Comment", backref="author", lazy=True) def __init__(self, *args, **kwargs): super(User, self).__init__(*args, **kwargs) # self.otp_secret = base64.b32encode(os.urandom(10)).decode() self.otp_secret = pyotp.random_base32() def get_auth_uri(self): servicer = 'Ask.it' return ('otpauth://totp/{0}:{1}?secret={2}&issuer={0}'.format( servicer, self.username, self.otp_secret)) def verify_totp(self, token): totp_client = pyotp.TOTP(self.otp_secret) return totp_client.verify(token) def __repr__(self): return "User('%s', '%s')" % (self.username, self.email)
class Artist(db.Model): """ Model of Artists A Artist is a single person or collection of people that attempt to create music """ __tablename__ = 'artists' id = db.Column(db.Integer, db.Sequence('artist_id_seq'), primary_key=True) name = db.Column(db.String(128)) bio = db.Column(db.String) large_image = db.Column(db.String) medium_image = db.Column(db.String) small_image = db.Column(db.String) spotify_url = db.Column(db.String) uri = db.Column(db.String) primary_label_id = db.Column( db.Integer, db.ForeignKey('labels.id', use_alter=True, name='fk_primary_label_id')) primary_label = db.relationship('Label', backref='artists', foreign_keys='Artist.primary_label_id') concerts = db.relationship('Concert', backref='artists', secondary='artist_concerts') releases = db.relationship('Release', backref='artists', secondary='artist_releases') awards = db.relationship('Award', backref='artists', secondary='artist_awards')
class User(UserMixin, db.Model): __tablename__ = "user" __table_args__ = {'extend_existing': True} id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(15), unique=True) email = db.Column(db.String(50), unique=True) password = db.Column(db.String(80)) authenticated = db.Column(db.SmallInteger, default=False) fiets_aangemeld = db.relationship('Fiets', backref='auteur', lazy='dynamic') fiets_verwijderd = db.relationship('Verwijderd', backref='auteur', lazy='dynamic') def is_active(self): return True def get_id(self): return self.id def is_authenticated(self): return self.authenticated def is_anonymous(self): return False
class Accueillant(db.Model): __tablename__ = 'accueillants' id = db.Column(db.Integer, primary_key=True) disponibilite = db.Column(db.String(120), unique=False, nullable=True) nom = db.Column(db.String(120), unique=True, nullable=False) tel = db.Column(db.String(120), unique=False, nullable=True) adresse = db.Column(db.String(120), unique=False, nullable=True) email = db.Column(db.String(120), unique=False, nullable=True) next_action = db.Column(db.Text, unique=False, nullable=True) remarques = db.Column(db.Text, unique=False, nullable=True) sejours = db.relationship('Sejour', backref='infos') accueillis = db.relationship("Accueilli", secondary='accueils', backref=db.backref('accueillants')) def __repr__(self): return f"Accueillant : {self.nom}, {self.email}" def __init__(self, disponibilite, nom, tel, adresse, email, next_action, remarques): self.disponibilite = disponibilite self.nom = nom self.tel = tel self.adresse = adresse self.email = email self.next_action = next_action self.remarques = remarques
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) rank = db.Column(db.Integer, nullable=False, default=9) application = db.relationship('Application', back_populates="user", uselist=False) messages = db.relationship('UserMessages', back_populates='user') notes = db.relationship('Notes', back_populates='user') def get_reset_token(self, expires_sec=18000): s = Serializer(app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}', '{self.rank}', '{self.application}', '{self.messages}')"
class Movement(db.Model): """A specific movement belongs to a set and has repetition time and number of movement.""" movement_id = db.Column(db.Integer, primary_key=True) set_id = db.Column( db.Integer, db.ForeignKey('movement_set.movement_set_id'), nullable=False ) name = db.Column(db.String, nullable=False) repetitions = db.relationship('Repetition', backref = 'movement', lazy=True) actions = db.relationship('MovementAction', backref = 'movement', lazy=True) @classmethod def find_for_set(cls, set_id): return cls.query.filter_by(set_id=set_id).all() @classmethod def create_movement(cls, name, set_id): movement = Movement(name=name, set_id=set_id) db.session.add(movement) db.session.commit() @classmethod def delete_movement(cls, movement_id): """.""" movement = cls.query.filter_by(movement_id=movement_id).first() for repetition in movement.repetitions: db.session.delete(repetition) for action in movement.actions: db.session.delete(action) db.session.delete(movement) db.session.commit()
class Batch(db.Model): id = db.Column(db.Integer,primary_key = True) name = db.Column(db.String(40)) classes = db.relationship('Period',backref='batch',lazy='dynamic') semester = db.Column(db.Integer) claims = db.relationship('Claim',backref='batch', lazy = 'dynamic') def __repr__(self): return "<batch {}>".format(self.name)
class Department(db.Model): id = db.Column(db.Integer,primary_key=True) name = db.Column(db.String(40)) classes = db.relationship('Period',backref='department',lazy='dynamic') username = db.Column(db.String(40)) password = db.Column(db.String(40)) claims = db.relationship('Claim',backref = 'department',lazy='dynamic') def __repr__(self): return "<department {}>".format(self.name)
class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(80), unique=True) username = db.Column(db.String(80), unique=True, nullable=False) password = db.Column(db.String(400)) post = db.relationship('Post', backref='user', lazy=True) comment = db.relationship('Comment', backref='user', lazy=True) def __repr__(self): return '<User %r>' % self.username
class User(UserMixin, db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(100), unique=True) password = db.Column(db.String(100)) controller_id = db.Column(db.String(100)) boler_temp = db.relationship('BoilerTemp', backref='user') mfb_temp = db.relationship('MfbTemp', backref='user')
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) about_me = db.Column(db.String(140)) last_seen = db.Column(db.DateTime, default=datetime.utcnow()) posts = db.relationship('Post', backref='author', lazy='dynamic') followed = db.relationship('User', secondary=followers, primaryjoin=(followers.columns.follower_id == id), secondaryjoin=(followers.columns.followed_id == id), backref=db.backref('followers', lazy='dynamic'), lazy='dynamic') def __repr__(self): return f"<User {self.username}>" def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password) def avatar(self, size): return f"https://www.gravatar.com/avatar/{md5(self.email.lower().encode('utf-8')).hexdigest()}?" \ f"{urlencode({'d': 'retro', 's': size})}" def is_following(self, user): return self.followed.filter(followers.columns.followed_id == user.id).count() > 0 def follow(self, user): if not self.is_following(user): self.followed.append(user) def unfollow(self, user): if self.is_following(user): self.followed.remove(user) def followed_posts(self): followed = Post.query.join(followers, (followers.columns.followed_id == Post.user_id))\ .filter(followers.columns.follower_id == self.id) own = Post.query.filter_by(user_id=self.id) return followed.union(own).order_by(Post.timestamp.desc()) def get_reset_password_token(self, expires_in=600): return jwt.encode({'reset_password': self.id, 'exp': time() + expires_in}, current_app.config['SECRET_KEY'], algorithm='HS256') @staticmethod def verify_reset_password_token(token): try: id = jwt.decode(token, current_app.config['SECRET_KEY'], algorithms=['HS256'])['reset_password'] except: return return User.query.get(id)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(30), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) posts = db.relationship("Post", backref="author", lazy=True) comments = db.relationship("Comment", backref="author", lazy=True) def __repr__(self): return "User('%s', '%s')" % (self.username, self.email)
class Warunki(db.Model): __tablename__ = "warunki" warunki_id = db.Column(db.Integer, primary_key=True) ilosc = db.Column(db.Integer) czas = db.Column(db.String, nullable=True) przerwy = db.Column(db.Integer, nullable=True) odleglosc = db.Column(db.String, nullable=True) oswietlenie = db.Column(db.Integer, nullable=True) krople = db.Column(db.Integer, nullable=True) mruganie = db.Column(db.Integer, nullable=True) respondent_id = db.Column(db.Integer, db.ForeignKey('respondent.respondent_id')) respondent = db.relationship("Respondent", back_populates="warunki") przerwa = db.relationship("Przerwa", uselist=False, back_populates="warunki")
class Scene(db.Model): id = db.Column(db.Integer, primary_key=True) sensor = db.Column(db.String(3), index=True) orbit = db.Column(db.String(10), index=True) date = db.Column(db.DateTime, index=True, unique=True) filepath = db.Column(db.String(1000), index=True, unique=True) time_added = db.Column(db.DateTime, index=True, default=datetime.utcnow) meta = db.relationship('Metadata', backref='s1_scene', lazy='dynamic') geo = db.relationship('Geometry', backref='s1_scene', lazy='dynamic') # grass_out = db.relationship('GrassOutput', backref='s1_scene', # lazy='dynamic') def __repr__(self): return '<Scene {}>'.format(self.filepath)
class Position(db.Model): __tablename__ = 'positions' id = db.Column(db.Integer, primary_key=True) portfolio_id = db.Column(db.Integer, db.ForeignKey('portfolios.id')) symbol = db.Column(db.String) cost = db.Column(db.Numeric) value = db.Column(db.Numeric) sharecount = db.Column(db.Integer) div_eligible_sharecount = db.Column(db.Integer) # taking out cascade="all, delete-orphan" from trades trades = db.relationship('Trade', backref='position', lazy='dynamic') def __init__(self, portfolio_id, symbol, cost, value, sharecount, div_eligible_sharecount): self.portfolio_id = portfolio_id self.symbol = symbol self.cost = cost self.value = value self.sharecount = sharecount self.div_eligible_sharecount = div_eligible_sharecount # self.trades = trades def __repr__(self): return 'id: {}, portfolio_id: {}, symbol: {}, cost: {}, value: {} sharecount: {}'.format( self.id, self.portfolio_id, self.symbol, self.cost, self.value, self.sharecount)
class Stock(db.Model): __tablename__ = 'stocks' id = db.Column(db.Integer, primary_key=True) symbol = db.Column(db.String(5), index=True, unique=True) name = db.Column(db.String(35), index=True, unique=True) exchange = db.Column(db.String(5), index=True) price = db.Column(db.Numeric) div_yield = db.Column(db.Numeric) ex_div = db.Column(db.Date) div_pay = db.Column(db.Date) market_cap = db.Column(db.String) view_count = db.Column(db.Integer) trades = db.relationship('Trade', backref='stock', lazy='dynamic') def __init__(self, symbol, name, exchange, price, div_yield, ex_div, div_pay, market_cap, view_count): self.symbol = symbol self.name = name self.exchange = exchange self.price = price self.div_yield = div_yield self.ex_div = ex_div self.div_pay = div_pay self.market_cap = market_cap self.view_count = view_count def __repr__(self): return '<id: {}, symbol: {}, exchange: {}>'.format( self.id, self.symbol, self.exchange)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(30), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) lastUpdated = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) interest1 = db.Column(db.String(60), nullable=False) interest2 = db.Column(db.String(60), nullable=False) interest3 = db.Column(db.String(60), nullable=False) otp_secret = db.Column(db.String(16), nullable=False) GIFs = db.relationship("UserGIF", backref="user", lazy=True) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # self.otp_secret = base64.b32encode(os.urandom(10)).decode() self.otp_secret = pyotp.random_base32() def get_auth_uri(self): servicer = 'CMSC388J-2FA' return ('otpauth://totp/{0}:{1}?secret={2}&issuer={0}'.format( servicer, self.username, self.otp_secret)) def verify_totp(self, token): totp_client = pyotp.TOTP(self.otp_secret) return totp_client.verify(token)
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(100), unique=True, nullable=False) # TODO: send email notifications (NOT MVP) email = db.Column(db.String(100), unique=True, nullable=False) password = db.Column(db.LargeBinary, nullable=False) credentials = db.relationship("Credential", backref="user", lazy=True) @staticmethod def create(username: str, password: bytes, email: str): try: user = User(username=username, password=password, email=email) db.session.add(user) db.session.commit() except IntegrityError as e: raise AuthenticationError("the {} is already in use".format( re.search(r"user\.(.+)", e.args[0])[1])) @staticmethod def validate(username, password) -> int: user: User = User.query.filter_by(username=username).first() if user and secrets.compare_digest(user.password, password): return user.id else: raise AuthenticationError("Incorrect username or password")
class CertificationGrade1(db.Model): __tablename__ = 'CertificationGrade1' gradeID = db.Column(db.String(100), primary_key=True) gradeName = db.Column(db.String(100)) certificationGrade2 = db.relationship('CertificationGrade2', backref='CertificationGrade1', lazy='dynamic') def __init__(self, gradeID=None, gradeName=None): self.gradeID = gradeID self.gradeName = gradeName @staticmethod def create(info): certificationGrade1 = CertificationGrade1(gradeID=info['gradeID'], gradeName=info['gradeName']) db.session.add(certificationGrade1) return (True, None) @staticmethod def generate(c): res = {} res['gradeID'] = c.gradeID res['gradeName'] = c.gradeName return res
class Match(db.Model): __tablename__ = "match" id = db.Column(db.String(128), primary_key=True) createdAt = db.Column(db.DateTime) duration = db.Column(db.Integer) gameMode = db.Column(db.String(128)) shardId = db.Column(db.String(128)) patchVersion = db.Column(db.String(128)) endGameReason = db.Column(db.String(128)) queue = db.Column(db.String(128)) rosters = db.relationship("Roster", backref="match") @hybrid_property def left(self): for roster in self.rosters: if roster.side == "left/blue": return roster @hybrid_property def right(self): for roster in self.rosters: if roster.side == "right/red": return roster def __init__(self, **kwargs): super(Match, self).__init__(**kwargs)
class CertificationGrade3(db.Model): __tablename__ = 'CertificationGrade3' gradeID = db.Column(db.String(100), primary_key=True) gradeName = db.Column(db.String(100)) superiorID = db.Column(db.String(100), db.ForeignKey('CertificationGrade2.gradeID')) certificationGrade4 = db.relationship('CertificationGrade4', backref='CertificationGrade3', lazy='dynamic') def __init__(self, gradeID=None, gradeName=None, superiorID=None): self.gradeID = gradeID self.gradeName = gradeName self.superiorID = superiorID @staticmethod def create(info): certificationGrade3 = CertificationGrade3( gradeID=info['gradeID'], gradeName=info['gradeName'], superiorID=info['superiorID']) db.session.add(certificationGrade3) return (True, None) @staticmethod def generate(c): res = {} res['gradeID'] = c.gradeID res['gradeName'] = c.gradeName return res
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(80)) subject = db.Column(db.String(50)) imgFile = db.Column(db.String(128)) date = db.Column(db.DateTime, default=datetime.today()) description = db.Column(db.Text,nullable=False) ownerId = db.Column(db.Integer,db.ForeignKey('user.id'),nullable=False) comment = db.relationship('Comment', backref='post', lazy=True) like = db.relationship('User', secondary=like, lazy='subquery', backref=db.backref('posts', lazy=True)) collect = db.relationship('User', secondary=collect, lazy='subquery', backref=db.backref('Post', lazy=True)) def __repr__(self): return '<Post %r>' % self.id
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) def get_reset_token(self, expires_sec=1800): s = serializer(app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = serializer(app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return Passport.query.get(user_id) passports = db.relationship('Passport', backref='author', lazy=True) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}', '{self.password}')"
class User(db.Model): __tablename__ = 'users' uid = db.Column(db.Integer, primary_key=True) firstname = db.Column(db.String(100)) lastname = db.Column(db.String(100)) email = db.Column(db.String(120), unique=True) pwdhash = db.Column(db.String(120)) admin = db.Column(db.Boolean) devices = db.relationship('Device', backref='users', lazy='dynamic') def __init__(self, firstname, lastname, email, password): self.firstname = firstname.title() self.lastname = lastname.title() self.admin = False self.email = email.lower() self.set_password(password) def set_password(self, password): self.pwdhash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.pwdhash, password) def is_admin(self): return self.admin
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(30), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) password = db.Column(db.String(60), nullable=False) otp_secret = db.Column(db.String(16), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # self.otp_secret = base64.b32encode(os.urandom(10)).decode() self.otp_secret = pyotp.random_base32() def get_auth_uri(self): servicer = 'CMSC388J-2FA' return ('otpauth://totp/{0}:{1}?secret={2}&issuer={0}'.format( servicer, self.username, self.otp_secret)) def verify_totp(self, token): totp_client = pyotp.TOTP(self.otp_secret) return totp_client.verify(token) def __repr__(self): return "User('%s', '%s')" % (self.username, self.email)
class Skill(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), unique=True, nullable=False) courses = db.relationship("Course", secondary=skill_to_courses) def __repr__(self): return '<Skill %r>' % self.name
class Author(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) posts = db.relationship('Post', lazy='dynamic', backref='author') def __repr__(self): return '<Author %s>' % self.username
class Expense(Base): __tablename__ = 'expense' user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) user = db.relationship('User', backref='expenses') timestamp = db.Column(db.DateTime(), index=True, nullable=False) amount = db.Column(db.Float(), nullable=False) description = db.Column(db.String(), nullable=False) def __init__(self, user_id, timestamp, description, amount): self.user_id = user_id self.timestamp = timestamp self.amount = amount self.description = description def __repr__(self): return '<Expense %r>' % self.id def to_dict(self): dt = datetime_to_pendulum(self.timestamp) timestamp = dt.to_iso8601_string() return { 'id': self.id, 'user_id': self.user_id, 'timestamp': timestamp, 'amount': self.amount, 'description': self.description }
class Profession2(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), unique=False, nullable=False) skills = db.relationship("Skill2", secondary=profession_to_skill2) def __repr__(self): return '<Profession2 %r>' % self.name