class User(UserMixin, db.Model): __tablename__ = 'Users' id = db.Column('id', db.Integer(), primary_key=True) is_seller = db.Column('is_seller', db.Integer()) password = db.Column('password', db.String(256)) email = db.Column('email', db.String(256)) question = db.Column('question', db.String(256)) answer = db.Column('answer', db.String(256)) address = db.Column('address', db.String(256)) @staticmethod def updateUser(password, email, question, answer, address, id): db.session.execute('UPDATE Users SET password = :password, email = :email, question = :question, answer = ' ':answer, address = :address WHERE id = :id', {'password': password, 'email': email, 'question': question, 'answer': answer, 'address': address, 'id': id}) print("User updated") db.session.commit() def __init__(self, id=None, is_seller=None, password=None, email=None, question=None, answer=None, address=None): self.id = id self.is_seller = is_seller self.password = password self.email = email self.question = question self.answer = answer self.address = address def __repr__(self): return '<User %r>' % self.model
class EthContact(db.Model): __tablename__ = 'eth_contact' address = db.Column(db.String(42), primary_key=True) name = db.Column(db.String(255), index=True) desc = db.Column(db.String(255)) email = db.Column(db.String(255), index=True) phone = db.Column(db.String(255), index=True) eth_balance = db.Column(db.Float(), default=0) ogn_balance = db.Column(db.Float(), default=0) dai_balance = db.Column(db.Float(), default=0) investor = db.Column(db.Boolean()) presale_interest = db.Column(db.Boolean()) dapp_user = db.Column(db.Boolean()) employee = db.Column(db.Boolean()) exchange = db.Column(db.Boolean()) company_wallet = db.Column(db.Boolean()) investor_airdrop = db.Column(db.Boolean()) token_count = db.Column(db.Integer()) transaction_count = db.Column(db.Integer()) tokens = db.Column(JSONB) last_updated = db.Column(db.DateTime(), server_default=db.func.now(), onupdate=db.func.now()) created_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) country_code = db.Column(db.String(2)) def __str__(self): return '%s' % (self.name)
class Item(db.Model): __tablename__ = 'Items' sku = db.Column('SKU', db.Integer(), primary_key=True) title = db.Column('title', db.String(256)) description = db.Column('description', db.String(256)) category = db.Column('category', db.String(256)) quantity = db.Column('quantity', db.Integer()) price = db.Column('price', db.Float()) rating = db.Column('rating', db.Float()) seller = db.Column('seller', db.Integer(), ForeignKey('Sellers.id')) image = db.Column('image', db.String(256)) @staticmethod def updateItem(title, description, category, quantity, price, image, sku): db.session.execute('UPDATE Items SET title = :title, description = :description, category = :category, quantity = ' ':quantity, price = :price, image = :image WHERE sku = :sku', {'title': title, 'description': description, 'category': category, 'quantity': quantity, 'price': price, 'image': image, 'sku': sku}) print("Item updated") db.session.commit() def __init__(self, sku=None, title=None, description=None, category=None, quantity=None, price=None, rating=None, seller=None, image=None): self.sku = sku self.title = title self.description = description self.category = category self.quantity = quantity self.price = price self.rating = rating self.seller = seller self.image = image def __repr__(self): return '<Item %r>' % self.model
class Recharge(db.Model): __tablename__ = 'recharge' id = db.Column(db.Integer(), primary_key=True, unique=True, nullable=False) created_at = db.Column(db.DateTime, default=datetime.utcnow) company = db.Column(db.Integer(), db.ForeignKey('company.id')) product = db.Column(db.Integer(), db.ForeignKey('product.id')) phone_number = db.Column(db.String(13))
class Like(db.Model): id = db.Column(db.Integer(), primary_key=True) user = db.Column(db.String(8), db.ForeignKey('user.login')) ecocup = db.Column(db.Integer(1)) valeur = db.Column(db.Integer(1)) def __repr__(self): return '<Like %r>' % self.id
class ItemInCategory(db.Model): sku = db.Column('SKU', db.Integer(), ForeignKey('Items.SKU'), primary_key=True) name = db.Column('name', db.Integer(), ForeignKey('Categories.name')) def __init__(self, sku=None, name=None): self.sku = sku self.name = name def __repr__(self): return '<ItemsInCategory %r>' % self.model
class PaysWith(db.Model): __tablename__ = 'PaysWith' credit_card = db.Column('credit_card', db.Integer(), primary_key=True) buyer_id = db.Column('buyer_id', db.Integer(), ForeignKey('Users.id')) def __init__(self, credit_card=None, buyer_id=None): self.credit_card = credit_card self.buyer_id = buyer_id def __repr__(self): return '<PaysWith %r>' % self.model
class Sells(db.Model): __tablename__ = 'Sells' seller_id = db.Column('seller_id', db.Integer(), ForeignKey('Sellers.id'), primary_key=True) sku = db.Column('SKU', db.Integer(), ForeignKey('Items.SKU'), primary_key=True) def __init__(self, seller_id=None, sku=None): self.seller_id = seller_id self.sku = sku def __repr__(self): return '<Sells %r>' % self.model
class TokenInfo(db.Model): __tablename__ = 'token_info' id = db.Column(db.Integer, primary_key=True) total_supply = db.Column(db.String(255)) holders = db.Column(db.Integer()) transfers_count = db.Column(db.Integer()) created_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) def __str__(self): return '%s' % (self.name)
class RequiresPayment(db.Model): __tablename__ = 'RequiresPayment' order_id = db.Column('order_id', db.Integer(), ForeignKey('Orders.order_id'), primary_key=True) credit_card_number = db.Column('credit_card_number', db.Integer(), ForeignKey('Payment.credit_card')) def __init__(self, order_id=None, credit_card_number=None): self.order_id = order_id self.credit_card_number = credit_card_number def __repr__(self): return '<RequiresPayment %r>' % self.model
class Places(db.Model): __tablename__ = 'Places' order_id = db.Column('order_id', db.Integer(), ForeignKey('Orders.order_id'), primary_key=True) buyer_id = db.Column('buyer_id', db.Integer(), ForeignKey('Users.id')) def __init__(self, order_id=None, buyer_id=None): self.order_id = order_id self.buyer_id = buyer_id def __repr__(self): return '<Places %r>' % self.model
class Photo(db.Model): __tablename__ = 'photos' id = db.Column(db.Integer(), primary_key=True, autoincrement=True) user_id = db.Column(db.Integer(), db.ForeignKey('users.id')) user = db.relationship('User', backref='users.id') thumbnail_link = db.Column(db.String(100)) photo_link = db.Column(db.String(100)) processed_link = db.Column(db.String(100)) def __repr__(self): return '<Photo %r>' % self.id
class Listing(db.Model): contract_address = db.Column(db.String(255), primary_key=True) owner_address = db.Column(db.String(255), index=True) registry_id = db.Column(db.Integer()) price = db.Column(db.Integer()) units = db.Column(db.Integer()) expired = db.Column(db.Boolean()) ipfs_hash = db.Column(db.String(255)) ipfs_data = db.Column(db.JSON()) created_at = db.Column(db.DateTime(timezone=True)) expires_at = db.Column(db.DateTime(timezone=True))
class Collection(db.Model): id = db.Column(db.Integer(), primary_key=True) login_user = db.Column(db.String(8), db.ForeignKey('user.login'), index=True) ecocup = db.Column(db.Integer(), db.ForeignKey('ecocup.id'), index=True) in_collection = db.Column(db.Integer()) accepte_echange = db.Column(db.Integer()) souhaite = db.Column(db.Integer()) date_mise_a_jour = db.Column(db.DateTime(), default=datetime.datetime.utcnow()) def __repr__(self): return '<Collection %r %r>' % (self.id, self.nom_ecocup, self.in_collection, self.login_user)
class OrdersContain(db.Model): __tablename__ = 'OrdersContain' order_id = db.Column('order_id', db.Integer(), ForeignKey('Orders.order_id'), primary_key=True) sku = db.Column('SKU', db.Integer(), ForeignKey('Items.SKU'), primary_key=True) quantity_ordered = db.Column('quantity_ordered', db.Integer()) price_at_order = db.Column('price_at_order', db.Float()) def __init__(self, order_id=None, sku=None, quantity_ordered=None, price_at_order=None): self.order_id = order_id self.sku = sku self.quantity_ordered = quantity_ordered self.price_at_order = price_at_order def __repr__(self): return '<OrdersContain %r>' % self.model
class VotedTest(db.Model): __tablename__ = "votedtest" event_id = db.Column(db.Integer, ForeignKey('event.id'), primary_key=True) user_id = db.Column(db.Integer, ForeignKey('user.id'), primary_key=True) stars = db.Column(db.Integer()) votes = db.relationship("Event", back_populates="votes") voted = db.relationship("User", back_populates="voted")
class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) def __str__(self): return self.name
class Order(db.Model): __tablename__ = 'Orders' order_id = db.Column('order_id', db.Integer(), primary_key=True) total_price = db.Column('total_price', db.Float()) time_stamp = db.Column('time_stamp', db.DateTime()) buyer_id = db.Column('buyer_id', db.Integer()) def __init__(self, order_id=None, total_price=None, time_stamp=None, buyer_id=None): self.order_id = order_id self.total_price = total_price self.time_stamp = time_stamp self.buyer_id = buyer_id def __repr__(self): return '<Order %r>' % self.model
class ExchangeData(db.Model): id = db.Column(db.Integer(), primary_key=True) exchange_id = db.Column(db.Integer(), db.ForeignKey('exchange_metadata.id')) good_id = db.Column(db.Integer(), db.ForeignKey('good.id')) giver = db.Column(db.String(8), db.ForeignKey('user.login')) good = db.relationship("Good") def __init__(self, exchange, good, giver): self.exchange_id = exchange self.good_id = good self.giver = giver def __repr__(self): return '<EchangeData %r>' % self.id
class Dungeon(db.Model): # Autoincrementing, unique primary key id = db.Column(db.Integer(), primary_key=True) level = db.Column(db.Integer) rooms = db.Column(db.Integer) treasures = db.Column(db.Integer) traps = db.Column(db.Integer) boss_level = db.Column(db.Boolean) xp_drop = db.Column(db.Integer) monsters = db.relationship( "Monster", secondary=monsters, lazy="subquery", backref=db.backref("dungeons", lazy=True), ) def __repr__(self): return json.dumps(self.short()) """ short() short form representation of the Dungeon model """ def short(self) -> dict: return { "id": self.id, "level": self.level, "rooms": self.rooms, "monsters": [m.short() for m in self.monsters], } """ long() long form representation of the Dungeon model """ def long(self) -> dict: return { "id": self.id, "level": self.level, "rooms": self.rooms, "treasures": self.treasures, "traps": self.traps, "boss_level": self.boss_level, "xp_drop": self.xp_drop, "monsters": [m.short() for m in self.monsters], } """ all() returns all monsters """ @classmethod def all(cls, detail=False) -> list: if query := cls.query.all(): return [d.long() if detail else d.short() for d in query] else:
class Good(db.Model): id = db.Column(db.Integer(), primary_key=True) nom = db.Column(db.String(50)) semestre = db.Column(db.String(3)) asso = db.Column(db.String(50)) nb_exemplaires = db.Column(db.Integer()) contenance = db.Column(db.Integer()) appreciation = db.Column(db.Integer(), default=0) commentaires = db.Column(db.String(140)) image_url = db.Column(db.String(100), server_default="default.gif") collections = db.relationship('Collection', backref='good_ref', lazy='dynamic') def __repr__(self): return '<Good %r>' % self.id
class Profile(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) gender = db.Column(db.String(1)) age = db.Column(db.Integer()) email = db.Column(db.String(50), unique=True) description = db.Column(db.String(300)) date = db.Column(db.DateTime, default=datetime.utcnow)
class Role(db.Model, RoleMixin): """Allows for distinguishing castes of users. Currently access control is only based on whether a person is a registered user (see accessible) but this would let you get fancy in the future.""" id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255))
class Echange(db.Model): id = db.Column(db.Integer(), primary_key=True) user1 = db.Column(db.String(8), db.ForeignKey('user.login')) user2 = db.Column(db.String(8), db.ForeignKey('user.login')) #User1 donne ecocup1 ecocup1 = db.Column(db.Integer(), db.ForeignKey('ecocup.id')) ecocup2 = db.Column(db.Integer(), db.ForeignKey('ecocup.id')) date_execution = db.Column(db.DateTime(), default=None) date_conf1 = db.Column(db.DateTime(), default=None) date_conf2 = db.Column(db.DateTime(), default=None) date_cancelled = db.Column(db.DateTime(), default=None) canceller = db.Column(db.String(8), default=None) date_creation = db.Column(db.DateTime(), default=datetime.datetime.utcnow()) def __repr__(self): return '<Echange %r>' % self.id
class Producto(db.Model): id=db.Column(db.Integer,primary_key= True) nombre = db.Column(db.String(80)) precio = db.Column(db.String(15)) peso = db.Column(db.String(15)) categoria_id = db.Column(db.Integer(),db.ForeignKey('categoria.id')) categoria = db.relationship('Categoria', backref = db.backref('productos',lazy=True))
class Cart(db.Model): __tablename__ = 'Cart' buyer_id = db.Column('buyer_id', db.Integer(), primary_key=True) sku = db.Column('SKU', db.Integer(), primary_key=True) @staticmethod def delete_from_cart(sku, buyer_id): db.session.execute('DELETE FROM Cart WHERE sku = :sku AND buyer_id = :buyer_id', {'sku': sku, 'buyer_id': buyer_id}) print("Deleted from cart") db.session.commit() def __init__(self, buyer_id=None, sku=None): self.buyer_id = buyer_id self.sku = sku def __repr__(self): return '<Cart %r>' % self.model
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer(), primary_key=True, autoincrement=True) username = db.Column(db.String(100)) password = db.Column(db.String(100)) def __repr__(self): return '<User %r>' % self.id
class Purchase(db.Model): contract_address = db.Column(db.String(255), primary_key=True) buyer_address = db.Column(db.String(255), index=True) listing_address = db.Column(db.String(255), db.ForeignKey('listing.contract_address'), nullable=False) stage = db.Column(db.Integer()) created_at = db.Column(db.DateTime(timezone=True)) buyer_timeout = db.Column(db.DateTime(timezone=True))
class SocialStat(db.Model): __tablename__ = 'social_stat' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(255), index=True) timestamp = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) subscribed_count = db.Column(db.Integer()) def __str__(self): return '%s' % (self.name)
class Contributor(db.Model): __tablename__ = 'contributor' username = db.Column(db.String(255), primary_key=True, autoincrement=False) commits = db.Column(db.Integer()) avatar = db.Column(db.String(255)) created_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) def __str__(self): return '%s' % (self.username)