class Coach(UserMixin, db.Model): """TODO""" __tablename__ = "coach" id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(124), nullable=False, unique=True) email_confirmed = db.Column(db.Boolean, nullable=False, default=False) name_first = db.Column(db.String(64), nullable=False) name_last = db.Column(db.String(64), nullable=False) _password = db.Column(db.String(128)) is_admin = db.Column(db.Boolean, nullable=False, default=False) @hybrid_property def password(self): return self._password @password.setter def _set_password(self, plaintext): self._password = bcrypt.generate_password_hash(plaintext).decode( 'utf-8') # override UserMixin get_id method def get_id(self): return self.email def is_correct_password(self, plaintext): return bcrypt.check_password_hash(self._password, plaintext) def __repr__(self): """Provide helpful representation when printed.""" return "<Coach id={} email={}>".format(self.id, self.email)
class ScholarQuestion(db.Model): __tablename__ = 'scholar_questions' question_id = db.Column(db.Integer, primary_key=True) question = db.Column(db.String(1000), nullable=False) answer = db.Column(db.String(1000)) user_id = db.Column(db.Integer, db.ForeignKey('users.user_id'))
class User_score(db.Model): __tablename__ = 'user_score' user_id = db.Column(db.String(10), nullable=True, primary_key=True) score = db.Column(db.Integer, nullable=True) score_dt = db.Column(db.DateTime, nullable=True, primary_key=True) game_id = db.Column(db.String(10), nullable=True) #def __repr__(self): #return '<User_score %r>' % self.user_id def getUser_scoreList(user_id): # select * from karuta_desc user_score_list = db.session.query(User_score).all() if user_score_list == None: return [] else: return user_score_list def registUser_score(user_score): print("user_score") print(user_score) record = User_score(user_id=user_score['user_id'], score=user_score['score'], score_dt=user_score['score_dt'], game_id=user_score['game_id']) #insert db.session.add(record) db.session.commit() return user_score
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(24), unique=True, nullable=False) nickname = db.Column(db.String(24)) location = db.Column(db.String) password = db.Column(db.String(160), nullable=False) recovery_token = db.Column(db.String(160)) email = db.Column(db.String(64), nullable=False) notes = db.Column(db.Text) coins = db.Column(db.Integer) stardust = db.Column(db.Integer) buddy_pokemon_id = db.Column(db.Integer, db.ForeignKey('user_pokemon.id')) bag_size = db.Column(db.Integer) pokemon_storage_size = db.Column(db.Integer) team_id = db.Column(db.Integer, db.ForeignKey('team.id')) created = db.Column(db.TIMESTAMP(timezone=True), server_default=db.func.now()) last_modified = db.Column(db.TIMESTAMP(timezone=True), onupdate=db.func.now()) pokemon = db.relationship('UserPokemon', primaryjoin='User.id==UserPokemon.user_id') team = db.relationship('Team') def __repr__(self): return repr_gen(self, ['username', 'nickname', 'location', 'email', 'notes', 'coins', 'stardust', 'buddy_pokemon_id', 'bag_size', 'pokemon_storage_size', 'team_id', 'created', 'last_modified'])
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(50), nullable=False) address = db.Column(db.String(100), nullable=True) tel = db.Column(db.String(20), nullable=True) mail = db.Column(db.String(100), nullable=True) def __repr__(self): return '<User %r>' % self.name def getUserList(): # select * from users user_list = db.session.query(User).all() if user_list == None: return [] else: return user_list def registUser(user): record = User(name=user['name'], address=user['address'], tel=user['tel'], mail=user['mail']) # insert into users(name, address, tel, mail) values(...) db.session.add(record) db.session.commit() return user
class User(Model): """ This model holds information about a user registered """ __tablename__ = "user" id = Column(db.Integer, primary_key=True) name = Column(db.String(80), nullable=False) password = Column(db.String(128)) email = Column(db.String(100), nullable=False, unique=True) date = Column(db.DateTime, default=datetime.now()) votes = db.relationship("Vote", backref=db.backref("user")) type = Column(db.String(50), default="remote") def __init__(self, name, email, password, _type="remote"): """ Initializes the user instance """ self.name = name self.email = email if password: self.password = Bcrypt().generate_password_hash(password).decode() self.type = _type def __repr__(self): """ Returns the object reprensentation """ return "<User %r>" % self.name def to_json(self): """ Returns a JSON object :return: user JSON object """ user_json = {"name": self.name, "email": self.email, "date": self.date} return user_json @classmethod def find_by_email(cls, email): return cls.query.filter_by(email=email).first() def verify_password(self, password): """ Verify the password :param password: password for verification """ return Bcrypt().check_password_hash(self.password, password) def save(self): """ Save a user to the database. This includes creating a new user and editing one. """ db.session.add(self) db.session.commit()
class TraceNavigationUser(db.Model): __tablename__ = 'trace_navigation_users' trace_id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer) graph_ref = db.Column(db.String(100)) timestamp = db.Column(db.String(100), default='{0:%Y-%m-%d %H:%M:%S}'.format( datetime.datetime.now()))
class ContentModel(BaseModel): __abstract__ = True _tablename = None title = db.Column(db.String(140), index=True, unique=True) description = db.Column(db.String(140)) image_url = db.Column(db.String(140)) def serializable(self): return {'id': self.id, 'title': self.title}
class Team(db.Model): __tablename__ = 'team' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(24), unique=True, nullable=False) description = db.Column(db.Text, nullable=False) color = db.Column(db.String(24), nullable=False) def __repr__(self): return repr_gen(self, ['name', 'description', 'color'])
class UserModel(db.Model): __tablename__ = "users" __table_args__ = {'extend_existing': True} id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50), nullable=False) state = db.Column(db.String(200)) def __init__(self, name, state): self.name = name self.state = state
class Player(db.Model): __tablename__ = 'players' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), nullable=False) position = db.Column(db.String(30)) team_id = db.Column(db.Integer, db.ForeignKey('teams.id')) def __init__(self, name, position, team_id): self.name = name self.position = position self.team_id = team_id
class ChannelInfo(db.Model, Model): channel_name = db.Column(db.String(255)) subdomain = db.Column(db.String(255)) def getLatestRequest(self): latest = Latest.query.filter( Latest.channel_info_id == self.id).order_by(desc( Latest.updated)).first() return json.loads(latest.data) def new_request(self, data): string_data = json.dumps(data) self.latest.append(Latest.cache_new_request(string_data)) db.session.commit() def getManifest(self): ret = { "short_name": "Youtube channel Name", "name": "Youtube channel Name - long", "icons": [{ "src": "https://yt3.ggpht.com/a/AATXAJwTUV61MSj2X7gY4UkyRfDbQ1xgQf4mAZfLZA=s800-c-k-c0xffffffff-no-rj-mo", "type": "image/png", "sizes": "800x800" }, { "src": "https://yt3.ggpht.com/a/AATXAJwTUV61MSj2X7gY4UkyRfDbQ1xgQf4mAZfLZA=s800-c-k-c0xffffffff-no-rj-mo", "type": "image/png", "sizes": "192x192" }, { "src": "https://yt3.ggpht.com/a/AATXAJwTUV61MSj2X7gY4UkyRfDbQ1xgQf4mAZfLZA=s800-c-k-c0xffffffff-no-rj-mo", "type": "image/png", "sizes": "512x512" }], "start_url": "https://youtubeapp.nextcoder.es", "display": "standalone", "theme_color": "#000000", "background_color": "#ffffff" } return ret
class TemplateEntity(BaseEntity): """Template entity""" __tablename__ = "templates" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(20), nullable=False) memory = db.Column(db.Integer, nullable=False) cores = db.Column(db.Integer, nullable=False) olin_resource_tpl = db.Column(db.String(255), nullable=False) def set_id(self, template_id: int) -> "TemplateEntity": self.id = template_id return self def get_id(self) -> int: return self.id def set_name(self, template_name: str) -> "TemplateEntity": self.name = template_name return self def get_name(self) -> str: return self.name def set_memory(self, template_memory: int) -> "TemplateEntity": self.memory = template_memory return self def get_memory(self) -> int: return self.memory def set_cores(self, template_cores: int) -> "TemplateEntity": self.cores = template_cores return self def get_cores(self) -> int: return self.cores def set_olin_resource_tpl(self, template_olin_resource_tpl: str) -> "TemplateEntity": self.olin_resource_tpl = template_olin_resource_tpl return self def get_olin_resource_tpl(self) -> str: return self.olin_resource_tpl def to_dict(self) -> dict: return { "id": self.get_id(), "name": self.get_name(), "memory": self.get_memory(), "cores": self.get_cores(), "olin_resource_tpl": self.get_olin_resource_tpl() }
class CommunityQuestion(db.Model): __tablename__ = 'community_questions' question_id = db.Column(db.Integer, primary_key=True) question_title = db.Column(db.String(1000), nullable=False) question = db.Column(db.String(10000), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('users.user_id')) comments = db.relationship('CommunityComment', backref='community_comments') date = db.Column(db.DateTime, default=datetime.datetime.utcnow) def get_comments(self): return self.comments
class Statistic(db.Model): __tablename__ = 'stats' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(60), unique=True, nullable=False) stat_type = db.Column(db.String(60), nullable=False) position_type = db.Column(db.String(20)) positive = db.Column(db.Boolean()) def __init__(self, name, position_type, stat_type, positive): self.name = name self.position_type = position_type self.stat_type = stat_type self.positive = positive
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True, autoincrement=True) ft_id = db.Column(db.Integer, nullable=False, unique=True) username = db.Column(db.String(50), nullable=False, unique=True) password = db.Column(db.String(255), nullable=False) # current_identityの内容を定義 def __str__(self): strData = json.dumps({ 'id': self.id, 'ft_id': self.ft_id, 'username': self.username }) return strData # ユーザーの名前を使って、ユーザー情報を取る。ログイン認証用 def getUserListByName(): user_list = db.session.query(User).all() username_table = {u.username: u for u in user_list} if user_list == None: return [] else: return username_table # ユーザーのIDを使って、ユーザー情報を取る。ログイン認証用 def getUserListByID(): user_list = db.session.query(User).all() userid_table = {u.id: u for u in user_list} if user_list == None: return [] else: return userid_table def registUser(user): record = User(ft_id=user['ft_id'], username=user['username'], password=user['password']) db.session.add(record) try: db.session.commit() except IntegrityError: return { 'error': "{} is already exist on Database.".format(user['username']) } return user
class Student(db.Model): """TODO""" __tablename__ = "student" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name_first = db.Column(db.String(), nullable=True) name_last = db.Column(db.String(), nullable=True) rank_stripes = db.Column(db.Integer, nullable=True) rank_type = db.Column(db.String(), nullable=True) program = db.Column(db.String(), nullable=True) def __repr__(self): """<Student id=1 name=Bobby Fisher>""" return "<Student id={0} name={1}>".format(self.id, self.name_first + ' ' + self.name_last)
class User(db.Model): """ ユーザーモデル """ # テーブル名 __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(50), nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.today()) updated_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.today(), onupdate=datetime.datetime.today()) def __repr__(self): return '<User %r>' % self.name def getUserList(): # select * from users user_list = db.session.query(User).all() if user_list == None: return [] else: return user_list def registUser(user): record = User( name = user['name'], ) # insert into users(name, address, tel, mail) values(...) db.session.add(record) db.session.commit() return user
class Pokemon(db.Model): __tablename__ = 'pokemon' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(24), unique=True, nullable=False) description = db.Column(db.Text, nullable=False) height = db.Column(db.Numeric(5, 2)) weight = db.Column(db.Numeric(5, 2)) category_id = db.Column(db.Integer, db.ForeignKey('category.id'), nullable=False) stamina = db.Column(db.Integer, nullable=False) attack = db.Column(db.Integer, nullable=False) defense = db.Column(db.Integer, nullable=False) cp_gain = db.Column(db.Numeric(5, 2), nullable=False) cp_max = db.Column(db.Integer, nullable=False) buddy_distance = db.Column(db.Numeric(5, 2), nullable=False) fast_attacks = db.relationship('Attack', secondary='pokemon_attack', primaryjoin='and_(Pokemon.id==PokemonAttack.pokemon_id, ' 'Attack.attack_speed_id==1)') charge_attacks = db.relationship('Attack', secondary='pokemon_attack', primaryjoin='and_(Pokemon.id==PokemonAttack.pokemon_id, ' 'Attack.attack_speed_id==2)') category = db.relationship('Category') egg = db.relationship('Egg', secondary='pokemon_egg', back_populates='pokemon') evolves_to = db.relationship('Pokemon', secondary='pokemon_evolution', back_populates='evolves_from', primaryjoin='Pokemon.id==PokemonEvolution.from_pokemon_id', secondaryjoin='Pokemon.id==PokemonEvolution.to_pokemon_id') evolves_from = db.relationship('Pokemon', secondary='pokemon_evolution', back_populates='evolves_to', primaryjoin='Pokemon.id==PokemonEvolution.to_pokemon_id', secondaryjoin='Pokemon.id==PokemonEvolution.from_pokemon_id') types = db.relationship('Type', secondary='pokemon_type', back_populates='pokemon') def __repr__(self): return repr_gen(self, ['name', 'description', 'height', 'weight', 'category_id', 'stamina', 'attack', 'defense', 'cp_gain', 'cp_max', 'buddy_distance'])
class Item(ContentModel): section_id = db.Column(db.Integer, db.ForeignKey('section.id')) created_by = db.Column(db.Integer, db.ForeignKey('user.id')) modified_by = db.Column(db.Integer, db.ForeignKey('user.id')) restaurant_id = db.Column(db.Integer, db.ForeignKey('restaurant.id')) image_url = db.Column(db.String(140)) price = db.Column(db.Float, nullable=False) def __repr__(self): return '<Item {}>'.format(self.title) @classmethod def find_by_section_id(cls, section_id): result = cls.query.filter(cls.section_id == section_id) if result.count() > 0: return result return [] def serializable(self): return { 'id': self.id, 'title': self.title, 'price': self.price, 'image_url': self.image_url }
class Vote(Model): """ This model holds information about a votes casted by user on stories """ __tablename__ = "vote" id = Column(db.Integer, primary_key=True) story_id = Column(db.String(128)) user_id = Column(db.Integer, db.ForeignKey("user.id")) value = Column(db.Integer) def __init__(self, story_id, user_id, value): self.story_id = story_id self.user_id = user_id self.value = value @classmethod def fetch_user_votes(cls, user_id): return cls.query.filter_by(user_id=user_id).all() def save(self): """ Save a user to the database. This includes creating a new user and editing one. """ db.session.add(self) db.session.commit()
class Comment(Model): """ This model represents a comment on a given note """ __tablename__ = "comment" id = Column(db.Integer, primary_key=True) story_id = Column(db.String(128)) user_id = Column(db.Integer, db.ForeignKey("user.id")) content = Column(db.Integer) def __init__(self, story_id, user_id, content): self.story_id = story_id self.user_id = user_id self.content = content @classmethod def fetch_user_comments(cls, user_id): return cls.query.filter_by(user_id=user_id).all() @classmethod def fetch_post_comments(cls, post_id): return cls.query.filter_by(post_id=post_id).all() def save(self): """ Save a comment to the database. """ db.session.add(self) db.session.commit()
class User(db.Model): __tablename__ = 'users' id = db.Column(UUID(as_uuid=True), primary_key=True) username = db.Column(db.String()) password = db.Column(db.String()) api_key = db.Column(UUID(as_uuid=True)) is_active = db.Column(db.Boolean()) def __init__(self, username, password, api_key, is_active): self.username = username self.password = password self.api_key = api_key self.is_active = is_active def __repr__(self): return '<username {}>'.format(self.username)
class ResultModel(db.Model): __tablename__ = 'result' id = db.Column(UUIDType(binary=False), primary_key=True, default=uuid.uuid4) name = db.Column(db.String(255), nullable=False) state = db.Column(db.String(255), nullable=False) createTime = db.Column(db.DateTime, nullable=False, default=datetime.now) updateTime = db.Column(db.DateTime, nullable=False, default=datetime.now, onupdate=datetime.now) def __init__(self, name, state): self.name = name self.state = state def __repr__(self): return '<ResultModel {}:{}>'.format(self.id, self.name)
class Evaluation(db.Model): __tablename__ = 'evaluations' evaluation_id = db.Column(db.Integer, primary_key=True) comprehension_rating = db.Column(db.Integer) quality_rating = db.Column(db.Integer) user_id = db.Column(db.Integer, db.ForeignKey('users.user_id')) graph_ref = db.Column(db.String(100), db.ForeignKey('documents.graph_ref'))
class User(BaseModel): email = db.Column(db.String(140), index=True, unique=True) name = db.Column(db.String(140), index=True) phone = db.Column(db.String(140)) password_hash = db.Column(db.String(128)) activated_on = db.Column(db.DateTime) name = db.Column(db.String(140), nullable=True) profile_url = db.Column(db.String(220), nullable=True) reset_pw_token = db.Column(db.String(70), nullable=True) is_admin = db.Column(db.Boolean(), default=False) manages = db.relationship("Restaurant", secondary=restaurants_managers, back_populates='managers') def is_activated(self): return self.activated_on is not None def is_manager_of(self, restaurant): return restaurant.id in [rst.id for rst in self.manages] def activate(self, token): if self.is_activated(): return True try: user_email = jwt.decode(token, current_app.config['JWT_SECRET_KEY'], algorithms=current_app.config['JWT_ALG'] )['user_email'] if user_email == self.email: self.activated_on = datetime.utcnow() return True except jwt.ExpiredSignature: # TODO: log this return False except jwt.InvalidTokenError: # TODO: log this return False return False 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 serializable(self): return {'id': self.id, 'name': self.name, 'email': self.email} @classmethod def find_by_email(cls, email): result = cls.query.filter(cls.email == email) if result.count() == 1: return result.first() return None def __repr__(self): return '<User {}>'.format(self.email)
class Effectiveness(db.Model): __tablename__ = 'effectiveness' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(24), unique=True, nullable=False) description = db.Column(db.Text, nullable=False) def __repr__(self): return repr_gen(self, ['name', 'description'])
class MedalLevel(db.Model): __tablename__ = 'medal_level' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(24), unique=True, nullable=False) description = db.Column(db.Text, nullable=False) def __repr__(self): return repr_gen(self, ['name', 'description'])
class ClassSchedule(db.Model): """tbd""" __tablename__ = "class_schedule" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(100), nullable=True) day_of_week = db.Column(db.String(9), nullable=False) time = db.Column(db.Time, nullable=False) coach_id = db.Column(db.Integer, db.ForeignKey('coach.id'), nullable=True) coach = db.relationship("Coach", backref=db.backref("class_schedule", order_by=id)) def __repr__(self): """Provide helpful representation when printed.""" return "<ClassSchedule id={} day_of_week={} time={}>".format( self.id, self.day_of_week, self.time)
class Audit(BaseModel): """ Model for audit logs. Tracks all changes on different resources. """ resource_id = db.Column(db.Integer, index=True, nullable=False) resource_type = db.Column(db.String(60), index=True, nullable=False) action = db.Column(db.String(60), index=True, nullable=False) activity = db.Column(db.Text(), nullable=False) def get_child_relationships(self): """Method to get all child relationships of this model Returns: None """ return None def __repr__(self): return f'<Audit on {self.resource_type}>' @staticmethod def log_save(instance, resource_type, activity): return Audit.log('ADDED', instance, resource_type, activity) @staticmethod def log_update(instance, resource_type, activity): return Audit.log('UPDATED', instance, resource_type, activity) @staticmethod def log_delete(instance, resource_type, activity): return Audit.log('REMOVED', instance, resource_type, activity) @classmethod def log(cls, *args): action, instance, resource_type, activity = args params = { 'resource_id': instance.id, 'resource_type': resource_type.upper(), 'activity': activity, 'action': action } audit = cls(**params) return audit.save()