class UserModel(db.Model): __tablename__= "user" token = db.Column(db.String(65536), primary_key=True) goodId = db.Column(db.String(1024)) stylesId = db.Column(db.String(1024)) quantity = db.Column(db.String(1024)) def __init__(self, token, goodId, stylesId="", quantity=1): self.token = token self.goodId = goodId self.stylesId = stylesId self.quantity = quantity def __repr__(self): return '<UserModel | UserModel %r>' % self.token def save_to_db(self): db.session.add(self) db.session.commit() def find_by_id(self, token): return self.query.filter_by(token=token).first() @property def data(self): return { "token": self.token, "goodId": self.goodId, "stylesId": self.stylesId, "quantity": self.quantity }
class FBSendModel(db.Model): __tablename__ = "fbsend" userId = db.Column(db.String(1024), primary_key=True) pageLink = db.Column(db.String(65535)) message = db.Column(db.String(65535)) is_sent = db.Column(db.Boolean, unique=False, default=False) def __init__(self, userId, pageLink="", message=""): self.userId = userId self.pageLink = pageLink self.message = message def __repr__(self): return '<FBSendModel | FBSendModel %r>' % self.token def save_to_db(self): db.session.add(self) db.session.commit() def get_without_sent(self): return self.query.filter_by(is_sent=False).all() @property def data(self): return {"userId": self.userId, "pageLink": self.pageLink}
class StyleInfoDisplayModel(db.Model): __tablename__= "styleInfo" styleId = db.Column(db.String(80), primary_key=True) title = db.Column(db.String(80)) quantity = db.Column(db.Integer) def __init__(self, styleId, title, quantity): self.styleId = styleId self.title = title self.quantity = quantity def __repr__(self): return '<ProductModel | StyleInfoDisplayModel %r>' % self.title def save_to_db(self): db.session.add(self) db.session.commit() def find_by_id(self, styleId): return self.query.filter_by(styleId=styleId).first() @property def data(self): return { "value": self.styleId, "title": self.title, "quantity": self.quantity }
class CategoryDisplayModel(db.Model): __tablename__= "category" cateId = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(80)) product_display = db.relationship('ProductDisplayModel', backref='category', lazy='dynamic') def __init__(self, cateId, title): self.cateId = cateId self.title = title def __repr__(self): return '<ProductModel | CategoryDisplayModel %r>' % self.title def save_to_db(self): db.session.add(self) db.session.commit() def find_by_id(self, cateId): return self.query.filter_by(cateId=cateId).first() @property def data(self): return { "cateId": self.cateId, "title": self.title }
class OrderhasProductsModel(db.Model): pid = db.Column(db.Integer, primary_key=True) orderId = db.Column(db.Integer, db.ForeignKey('order.orderId')) productId = db.Column(db.Integer, db.ForeignKey('product.goodId')) quantity = db.Column(db.Integer) def __init__(self, orderId, productId, quantity): self.pid = uuid.uuid1().int >> 100 self.orderId = orderId self.productId = productId self.quantity = quantity def __repr__(self): return '<OrderModel | OrderhasProducts %r>' % self.orderId def save_to_db(self): db.session.add(self) db.session.commit() @property def data(self): return { "orderId": self.orderId, "productId": self.productId, "quantity": self.quantity }
class UserBuyModel(db.Model): __tablename__ = "userbuy" pid = db.Column(db.Integer, primary_key=True) token = db.Column(db.String(65536), db.ForeignKey('user.token')) goodId = db.Column(db.Integer, db.ForeignKey('product.goodId')) styleId = db.Column(db.String(80), db.ForeignKey('styleInfo.styleId')) quantity = db.Column(db.Integer) def __init__(self, token, goodId, styleId, quantity=1): self.pid = uuid.uuid1().int >> 100 self.token = token self.goodId = goodId self.styleId = styleId self.quantity = quantity def __repr__(self): return '<UserModel | UserModel %r>' % self.token def save_to_db(self): db.session.add(self) db.session.commit() def find_by_id(self, token): return self.query.filter_by(token=token).first() @property def data(self): return { "token": self.token, "goodId": self.goodId, "styleId": self.styleId, "quantity": self.quantity }
class ProductDisplayModel(db.Model): __tablename__= "product" goodId = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) price = db.Column(db.Integer) promoMsg = db.Column(db.String(80)) image = db.Column(db.String(1024)) url = db.Column(db.String(1024)) description = db.Column(db.String(1024)) cateId = db.Column(db.Integer, db.ForeignKey('category.cateId'), nullable=True) def __init__(self, goodId, name, cateId=None, price=0, promoMsg="30% OFF", image="", url="", description="This is description", styles=[], app=None): self.goodId = goodId self.name = name self.price = price self.promoMsg = promoMsg self.image = image self.url = url self.description = description self.cateId = cateId for index in range(len(styles)): try: psr = ProductStyleInfoRelationModel(styles[index], goodId) if app is not None: with app.app_context(): psr.save_to_db() except: pass def __repr__(self): return '<ProductModel | ProductDisplayModel %r>' % self.name def save_to_db(self): db.session.add(self) db.session.commit() def find_by_id(self, goodId): return db.session.query.filter_by(goodId=goodId).first() def get_cate_name_by_id(self, cateId): elem_list = db.session.query(CategoryDisplayModel.title).filter_by(cateId=cateId).first() return elem_list[0] if len(elem_list) > 0 else None @property def data(self): prodStyles = ProductStyleInfoRelationModel.query.filter_by(goodId=self.goodId).all() stylesIds = [] for item in prodStyles: data = item.data stylesIds.append(data['styleId']) return { "goodId": self.goodId, "name": self.name, "price": self.price, "promoMsg": self.promoMsg, "image": self.image, "url": self.url, "description": self.description, "stylesId": ','.join(stylesIds) }
class OrderDisplayModel(db.Model): __tablename__ = "order" orderId = db.Column(db.Integer, primary_key=True) token = db.Column(db.String(65536)) amount = db.Column(db.Integer) receiver_name = db.Column(db.String(65536)) receiver_phone = db.Column(db.String(65536)) receiver_addr1 = db.Column(db.String(65536)) receiver_addr2 = db.Column(db.String(65536)) payment = db.Column(db.Integer) invoice = db.Column(db.Integer) timestamp = db.Column(db.String(65536)) def __init__(self, token, products, quantity, amount, payment, invoice, receiver): self.orderId = uuid.uuid1().int >> 100 self.token = token productsList = list(products.split(",")) quantityList = list(quantity.split(",")) for index in range(len(productsList)): op = OrderhasProductsModel(self.orderId, productsList[index], quantityList[index]) op.save_to_db() self.amount = amount self.payment = payment self.invoice = invoice self.receiver_name = receiver['name'] self.receiver_phone = receiver['phone'] self.receiver_addr1 = receiver['addr1'] self.receiver_addr2 = receiver['addr2'] self.timestamp = time.time() def __repr__(self): return '<OrderModel | OrderDisplayModel %r>' % self.orderId def save_to_db(self): db.session.add(self) db.session.commit() def find_by_id(self, orderId): return self.query.filter_by(orderId=orderId).first() @property def data(self): return { "orderId": self.orderId, "amount": self.amount, "payment": self.payment, "timestamp": self.timestamp }
class CheckoutProductDisplayModel(db.Model): goodId = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) def __init__(self, goodId, name): self.goodId = goodId self.name = name def __repr__(self): return '<CheckoutModel | CheckoutProductDisplayModel %r>' % self.name def save_to_db(self): db.session.add(self) db.session.commit() def find_by_id(self, goodId): return self.query.filter_by(goodId=goodId).first() @property def data(self): return {"goodId": self.goodId, "name": self.name}
class ProductDisplayModel(db.Model): __tablename__= "product" goodId = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) price = db.Column(db.Integer) promoMsg = db.Column(db.String(80)) image = db.Column(db.String(1024)) url = db.Column(db.String(1024)) description = db.Column(db.String(1024)) cateId = db.Column(db.Integer,nullable=True) stylesId = db.Column(db.String(80), nullable=True) def __init__(self, goodId, name, cateId=None, price=0, promoMsg="30% OFF", image="", url="", description="This is description", styles=[], app=None): self.goodId = goodId self.name = name self.price = price self.promoMsg = promoMsg self.image = image self.url = url self.description = description self.cateId = cateId self.stylesId = ','.join(styles) def __repr__(self): return '<ProductModel | ProductDisplayModel %r>' % self.name def save_to_db(self): db.session.add(self) db.session.commit() @property def data(self): return { "goodId": self.goodId, "name": self.name, "price": self.price, "promoMsg": self.promoMsg, "image": self.image, "url": self.url, "description": self.description, "stylesId": self.stylesId }
class ProductStyleInfoRelationModel(db.Model): styleId = db.Column(db.String(80), db.ForeignKey('styleInfo.styleId'), primary_key=True) goodId = db.Column(db.Integer, primary_key=True) def __init__(self, styleId, goodId): self.styleId = styleId self.goodId = goodId def __repr__(self): return '<ProductModel | ProductStyleInfoRelationModel>' def save_to_db(self): db.session.add(self) db.session.commit() def find_by_id(self, styleId): return self.query.filter_by(styleId=styleId).first() @property def data(self): return { "styleId": self.styleId, "goodId": self.goodId }
class UserModel(db.Model): __tablename__ = "user" token = db.Column(db.String(65536), primary_key=True) def __init__(self, token, goodId, stylesId="", quantity=1, app=None): self.token = token goodIdList = list(goodId.split(",")) styleIdList = list(stylesId.split(",")) quantityIdList = list(quantity.split(",")) for index in range(len(goodIdList)): op = UserBuyModel(token, goodIdList[index], styleIdList[index], quantityIdList[index]) if app is not None: with app.app_context(): op.save_to_db() def __repr__(self): return '<UserModel | UserModel %r>' % self.token def save_to_db(self): db.session.add(self) db.session.commit() def find_by_id(self, token): return self.query.filter_by(token=token).first() @property def data(self): userbuy = db.session.query(UserBuyModel).filter_by( token=self.token).all() goodIdList = [] styleIdList = [] quantityIdList = [] for item in userbuy: data = item.data goodIdList.append(data['goodId']) styleIdList.append(data['styleId']) quantityIdList.append(data['quantity']) return { "token": self.token, "goodId": ','.join(goodIdList), "stylesId": ','.join(styleIdList), "quantity": ','.join(quantityIdList) }
class OrderDisplayModel(db.Model): orderId = db.Column(db.Integer, primary_key=True) token = db.Column(db.String(65536)) products = db.Column(db.String(65536)) quantity = db.Column(db.String(65536)) amount = db.Column(db.Integer) receiver_name = db.Column(db.String(65536)) receiver_phone = db.Column(db.String(65536)) receiver_addr1 = db.Column(db.String(65536)) receiver_addr2 = db.Column(db.String(65536)) payment = db.Column(db.Integer) invoice = db.Column(db.Integer) timestamp = db.Column(db.String(65536)) def __init__(self, token, products, quantity, amount, payment, invoice, receiver): self.orderId = uuid.uuid1().int >> 100 self.token = token self.products = products self.quantity = quantity self.amount = amount self.payment = payment self.invoice = invoice self.receiver_name = receiver['name'] self.receiver_phone = receiver['phone'] self.receiver_addr1 = receiver['addr1'] self.receiver_addr2 = receiver['addr2'] self.timestamp = time.time() def __repr__(self): return '<OrderModel | OrderDisplayModel %r>' % self.orderId def save_to_db(self): db.session.add(self) db.session.commit() def find_by_id(self, orderId): return self.query.filter_by(orderId=orderId).first() @property def data(self): return { "orderId": self.orderId, "amount": self.amount, "payment": self.payment, "timestamp": self.timestamp }