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 Stationery(db.Model): __tablename__ = "stationery" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False, unique=True) description = db.Column(db.String, nullable=True) def format_long(self): return { 'id': self.id, 'name': self.name, 'description': self.description } def add(self): db.session.add(self) db.session.commit() return self def update(self): db.session.commit() return self def delete(self): db.session.delete(self) db.session.commit()
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__ = '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 Order(BaseModel): state = db.Column(db.Integer, default=ORDER_PENDING) expected_time_arrival = db.Column(db.DateTime) orderitems = db.relationship("OrderItem", backref="order") def total_price(self): if not self.orderitems: return 0 return sum([ orderitem.item.price * orderitem.quantity for orderitem in self.orderitems ]) def serializable(self): return { 'id': self.id, 'state': self.state, 'total_price': self.total_price() } @classmethod def find_by_restaurant_id(cls, restaurant_id): result = cls.query.filter(cls.restaurant_id == restaurant_id) if result.count() > 0: return [order.serializable() for order in result] return []
class AppraisalSize(db.Model): __tablename__ = 'appraisal_size' id = db.Column(db.Integer, primary_key=True) description = db.Column(db.Text, nullable=False) def __repr__(self): return repr_gen(self, ['description'])
class PokemonAttack(db.Model): __tablename__ = 'pokemon_attack' pokemon_id = db.Column(db.Integer, db.ForeignKey('pokemon.id'), primary_key=True) attack_id = db.Column(db.Integer, db.ForeignKey('attack.id'), primary_key=True) def __repr__(self): return repr_gen(self, ['pokemon_id', 'attack_id'])
class UserPokemonAppraisalIv(db.Model): __tablename__ = 'user_pokemon_appraisal_iv' user_pokemon_id = db.Column(db.Integer, db.ForeignKey('user_pokemon.id'), primary_key=True) appraisal_iv_id = db.Column(db.Integer, db.ForeignKey('appraisal_iv.id'), primary_key=True) def __repr__(self): return repr_gen(self, ['user_pokemon_id', 'appraisal_iv_id'])
class UserLike(db.Model): __tablename__ = 'user_like' like_id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.user_id')) comment_id = db.Column(db.Integer, db.ForeignKey('community_comments.comment_id')) like_value = db.Column(db.Integer)
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 PokemonEgg(db.Model): __tablename__ = 'pokemon_egg' pokemon_id = db.Column(db.Integer, db.ForeignKey('pokemon.id'), primary_key=True) egg_id = db.Column(db.Integer, db.ForeignKey('egg.id'), primary_key=True) def __repr__(self): return repr_gen(self, ['pokemon_id', 'egg_id'])
class PokemonType(db.Model): __tablename__ = 'pokemon_type' pokemon_id = db.Column(db.Integer, db.ForeignKey('pokemon.id'), primary_key=True) type_id = db.Column(db.Integer, db.ForeignKey('type.id'), primary_key=True) def __repr__(self): return repr_gen(self, ['pokemon_id', 'type_id'])
class PokemonEvolution(db.Model): __tablename__ = 'pokemon_evolution' from_pokemon_id = db.Column(db.Integer, db.ForeignKey('pokemon.id'), primary_key=True) to_pokemon_id = db.Column(db.Integer, db.ForeignKey('pokemon.id'), primary_key=True) candy = db.Column(db.Integer, nullable=False) def __repr__(self): return repr_gen(self, ['from_pokemon_id', 'to_pokemon_id', 'candy'])
class TypeEffectiveness(db.Model): __tablename__ = 'type_effectiveness' from_type_id = db.Column(db.Integer, db.ForeignKey('type.id'), primary_key=True) to_type_id = db.Column(db.Integer, db.ForeignKey('type.id'), primary_key=True) effectiveness_id = db.Column(db.Integer, db.ForeignKey('effectiveness.id'), primary_key=True) def __repr__(self): return repr_gen(self, ['from_type_id', 'to_type_id', 'effectiveness_id'])
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 UserCandy(db.Model): __tablename__ = 'user_candy' user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True) pokemon_id = db.Column(db.Integer, db.ForeignKey('pokemon.id'), primary_key=True) count = db.Column(db.Integer) def __repr__(self): return repr_gen(self, ['user_id', 'pokemon_id', 'count'])
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 UserItem(db.Model): __tablename__ = 'user_item' user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True) item_id = db.Column(db.Integer, db.ForeignKey('item.id'), primary_key=True) count = db.Column(db.Integer, nullable=False) def __repr__(self): return repr_gen(self, ['user_id', 'item_id', 'count'])
class UserEgg(db.Model): __tablename__ = 'user_egg' user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True) egg_id = db.Column(db.Integer, db.ForeignKey('egg.id'), primary_key=True) count = db.Column(db.Integer) def __repr__(self): return repr_gen(self, ['user_id', 'egg_id'])
class MedalLevelRequirement(db.Model): __tablename__ = 'medal_level_requirement' medal_id = db.Column(db.Integer, db.ForeignKey('medal.id'), primary_key=True) medal_level_id = db.Column(db.Integer, db.ForeignKey('medal_level.id'), primary_key=True) count = db.Column(db.Integer, nullable=False) def __repr__(self): return repr_gen(self, ['medal_id', 'medal_level_id', 'count'])
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 TeamAppraisalSize(db.Model): __tablename__ = 'team_appraisal_size' team_id = db.Column(db.Integer, db.ForeignKey('team.id'), primary_key=True) appraisal_size_id = db.Column(db.Integer, db.ForeignKey('appraisal_size.id'), primary_key=True) dialog = db.Column(db.Text, nullable=False) def __repr__(self): return repr_gen(self, ['team_id', 'appraisal_size_id', 'dialog'])
class StationeryRequisitionDetails(db.Model): __tablename__ = "stationery_requisition_details" id = db.Column(db.Integer, primary_key=True, nullable=False) order_id = db.Column(db.Integer, db.ForeignKey("stationery_requisitions.id")) item = db.Column(db.Integer, db.ForeignKey("stationery.id")) quantity = db.Column(db.Float, nullable=False) purpose = db.Column(db.String, nullable=True)
class UserMedal(db.Model): __tablename__ = 'user_medal' user_id = db.Column(db.Integer, db.ForeignKey('user.id'), primary_key=True) medal_id = db.Column(db.Integer, db.ForeignKey('medal.id'), primary_key=True) medal_level_id = db.Column(db.Integer, db.ForeignKey('medal_level.id'), nullable=False) count = db.Column(db.Integer, nullable=False) def __repr__(self): return repr_gen(self, ['user_id', 'medal_id', 'medal_level_id', 'count'])
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 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 Egg(db.Model): __tablename__ = 'egg' 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) pokemon = db.relationship('Pokemon', secondary='pokemon_egg', back_populates='egg') def __repr__(self): return repr_gen(self, ['name', 'description'])
class UserLog(db.Model): __tablename__ = 'user_log' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) notes = db.Column(db.Text, nullable=False) created = db.Column(db.TIMESTAMP(timezone=True), server_default=db.func.now()) last_modified = db.Column(db.TIMESTAMP(timezone=True), onupdate=db.func.now()) def __repr__(self): return repr_gen(self, ['user_id', 'notes', 'date', 'created', 'last_modified'])