class Wallet(db.Model): """ This class represents the wallet table. """ # Ensures table will be named in plural and not in singular as in # the name of the model __tablename__ = 'wallets' id = db.Column(db.Integer, primary_key=True) currency_code = db.Column(db.String(length=3)) open_exchange_price = db.Column(db.Float(precision=8)) requested_amount = db.Column(db.Float(precision=8)) final_amount = db.Column(db.Float(precision=8)) created_on = db.Column(db.DateTime, index=True, server_default=db.func.now()) updated_on = db.Column(db.DateTime, server_default=db.func.now(), onupdate=db.func.now()) def __repr__(self): return '<id: {}>'.format(self.id) def save(self): db.session.add(self) db.session.commit()
class OldCities(db.Model): __bind_key__ = 'old_cities' __tablename__ = 'old_cities' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String) x_rat_key = db.Column(db.Integer) # used to determine width of html5 canvas y_rat_key = db.Column(db.Integer) # used to determine width of html5 canvas x_rat = db.Column(db.Float(precision=2)) # used to position "city dot" on html5 canvas y_rat = db.Column(db.Float(precision=2)) # used to position "city dot" on html5 canvas color = db.Column(db.String) connections = db.Column(db.JSON()) def json(self): return { 'id': self.id, 'name': self.name, 'x_rat_key': self.x_rat_key, 'y_rat_key': self.y_rat_key, 'x_rat': self.x_rat, 'y_rat': self.y_rat, 'color': self.color, 'connections': self.connections } def simple_json(self): return { 'id': self.id, 'name': self.name, 'connections': self.connections }
class ItemModel(db.Model): __tablename__ = 'items' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) price = db.Column(db.Float(precision=2)) store_id = db.Column(db.Integer, db.ForeignKey('stores.id')) store = db.relationship('StoreModel') def __init__(self, name, price, store_id): self.name = name self.price = price self.store_id = store_id def json(self): return {'name': self.name, 'price': self.price} @classmethod def find_by_name(cls, name): return cls.query.filter_by(name=name).first() def save_to_db(self): db.session.add(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit()
class ItemModel(db.Model): __tablename__ = "items" id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) price = db.Column(db.Float(precision=2)) store_id = db.Column(db.Integer, db.ForeignKey("stores.id")) store = db.relationship("StoreModel") def __init__(self, name, price, store_id): self.name = name self.price = price self.store_id = store_id def json(self): return {"name": self.name, "price": self.price} def save(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit() @classmethod def find_item_by_name(cls, name): return cls.query.filter_by(name=name).first()
class Order(db.Model): __tablename__ = 'orders' id = db.Column(db.Integer, primary_key=True) customer_firstname = db.Column(db.String(80)) customer_lastname = db.Column(db.String(80)) customer_address = db.Column(db.String(80)) date = db.Column(db.DateTime(timezone=True), server_default=func.now()) total = db.Column(db.Float(precision=2)) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) user = db.relationship('User') products_ordered = db.relationship('ProductOrdered', lazy='dynamic') order_status_id = db.Column(db.Integer, db.ForeignKey('order_status.id')) order_status = db.relationship('OrderStatus') def __init__(self, customer_firstname, customer_lastname, customer_address, user_id): self.customer_firstname = customer_firstname self.customer_lastname = customer_lastname self.customer_address = customer_address self.total = 0 self.user_id = user_id self.order_status_id = 1 # the first state @classmethod def find_by_id(cls, id): return cls.query.filter_by(id=id).first() @classmethod def get_all(cls): return cls.query.order_by(cls.date.desc()).all() @classmethod def find_by_user_id(cls, user_id): return cls.query.filter_by(user_id=user_id).order_by(cls.date.desc()) def save_to_db(self): db.session.add(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit() def add_product(self, product_id, product_quantity): if (self.id == None): self.save_to_db() self.total += Product.find_by_id(product_id).price * product_quantity self.save_to_db() ProductOrdered(self.id, product_id, product_quantity).save_to_db() def promote_status(self): if self.order_status_id < 3: self.order_status_id += 1 self.save_to_db()
class Product(db.Model): __tablename__ = 'products' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) price = db.Column(db.Float(precision=2)) quantity = db.Column(db.Integer()) description = db.Column(db.String(200)) minutes_preparation = db.Column(db.Integer()) image_path = db.Column(db.String(80)) product_type_id = db.Column(db.Integer, db.ForeignKey('product_types.id')) product_type = db.relationship('ProductType') #orders = db.relationship('Order', lazy='dynamic') def __init__(self, product_type_id, name, price, quantity, description, minutes_preparation,image_path): self.name = name self.price = price self.quantity = quantity self.description = description self.minutes_preparation = minutes_preparation self.image_path=image_path self.product_type_id=product_type_id @classmethod def find_by_id(cls, _id): return cls.query.filter_by(id=_id).first() @classmethod def find_by_name(cls, name): return cls.query.filter_by(name=name).first() def save_to_db(self): db.session.add(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit() @classmethod def init_data(cls): cls(1, "Hamburger", 6, 10, "A 150Gr grilled meat hamburger. Comes with french fries and salad.", 15, "/images/hamburger.jpg").save_to_db() cls(1, "Chicken", 7, 10, "A 300Gr breaded chicken. comes with potatoes and salad", 15, "/images/chicken.jpg").save_to_db() cls(1, "Paella", 9, 10, "Perfect for the seafood lovers, it comes with oysters and mussels", 15, "/images/paella.jpg").save_to_db() cls(1, "Ribs", 12, 10, "300Gr Ribs. Comes with french fries.", 15, "/images/ribs.jpg").save_to_db() cls(1, "Salmon", 12, 10, "Chilean salmon. Comes with vegetables.", 15, "/images/salmon.jpg").save_to_db() cls(1, "Wrap", 7, 10, "Wrap with chicken and salad.", 15, "/images/wrap.jpg").save_to_db() cls(2, "Soda", 2, 7, "250cc soda. The soda comes with pieces of fruit.", 5, "/images/soda.jpg").save_to_db() cls(2, "Juice", 3, 7, "330cc juice. Made of tropical fruits.", 9, "/images/juice.jpg").save_to_db() cls(2, "Tee", 3, 7, "200cc Tee.", 12, "/images/tee.jpg").save_to_db() cls(2, "Beer", 2, 7, "500cc Beer.", 3, "/images/beer.jpg").save_to_db() cls(3, "Pancakes", 4, 7, "Baked pancakes with syrup or honey.", 12, "/images/pancakes.jpg").save_to_db() cls(3, "Macaroons", 3, 7, "Try our special macaroon recipe.", 3, "/images/macaroons.jpg").save_to_db() cls(3, "Forest fruit Cake", 3, 7, "This cake has a great variety of forest fruits, such as blackberries and raspberries.", 5, "/images/cake.jpg").save_to_db()
class Cities(db.Model): __tablename__ = 'cities' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String) x_rat_key = db.Column( db.Integer) # used to determine width of html5 canvas y_rat_key = db.Column( db.Integer) # used to determine width of html5 canvas x_rat = db.Column( db.Float(precision=2)) # used to position "city dot" on html5 canvas y_rat = db.Column( db.Float(precision=2)) # used to position "city dot" on html5 canvas color = db.Column(db.String) connections = db.Column(db.JSON) def json(self): return { 'id': self.id, 'name': self.name, 'x_rat_key': self.x_rat_key, 'y_rat_key': self.y_rat_key, 'x_rat': self.x_rat, 'y_rat': self.y_rat, 'color': self.color, 'connections': self.connections } def simple_json(self): return { 'id': self.id, 'name': self.name, 'connections': self.connections } @classmethod def find_by_id(cls, _id): return cls.query.filter_by(id=_id).first() def save_to_db(self): db.session.add(self) db.session.commit()
class Plan(db.Model): """ Represents a plan type """ id = db.Column(db.Integer, primary_key=True, autoincrement=False) name = db.Column(db.String(120), index=True, unique=True) description = db.Column(db.String(250), index=True) cost = db.Column(db.Float()) created_date = db.Column(db.DateTime, index=True, default=datetime.utcnow) updated_date = db.Column(db.DateTime, index=True, default=datetime.utcnow) def get_plan_cost(self): return "{:,.2f}".format(self.cost)