Esempio n. 1
0
class EnderecoModel(db.Model):
    __tablename__ = 'tb_endereco'

    id = db.Column(db.Integer, primary_key=True)
    logradouro = db.Column(db.String(255))
    numero = db.Column(db.String(4))
    complemento = db.Column(db.String(45))
    estado = db.Column(db.String(45))
    cep = db.Column(db.String(8))
    ponto_referencia = db.Column(db.String(65))

    fk_id_cidade = db.Column(db.Integer, db.ForeignKey('tb_cidade.id'), nullable=False)
    cidade = db.relationship('CidadeModel', backref='cidade', primaryjoin="EnderecoModel.fk_id_cidade==CidadeModel.id", uselist=False)

    fk_id_estado = db.Column(db.Integer, db.ForeignKey('tb_estado.id'), nullable=False)
    estado = db.relationship('EstadoModel', backref='estado', primaryjoin="EnderecoModel.fk_id_estado==EstadoModel.id", uselist=False)

    def __init__(self, logradouro, numero, complemento, cidade, estado, cep, ponto_referencia):
        self.logradouro = logradouro
        self.numero = numero
        self.complemento = complemento
        self.cidade = cidade
        self.estado = estado
        self.cep = cep
        self.ponto_referencia = ponto_referencia

    def __str__(self):
        return '<Endereco %s>'%(self.logradouro)
Esempio n. 2
0
class ProdutoModel(db.Model):
    __tablename__ = 'tb_produto'
    id = db.Column(db.Integer, primary_key=True)
    nome = db.Column(db.String(255))
    descricao = db.Column(db.Text())
    preco = db.Column(db.Float(precision='3,2'))
    is_visivel = db.Column(db.Boolean, default=False)
    is_deleted = db.Column(db.Boolean, default=False)
    dt_insercao = db.Column(db.DateTime, default=func.current_timestamp())

    fk_id_empresa = db.Column(db.Integer,
                              db.ForeignKey('tb_empresa.id'),
                              nullable=False)
    empresa = db.relationship(
        'EmpresaModel',
        backref='empresa',
        primaryjoin="ProdutoModel.fk_id_empresa==EmpresaModel.id",
        uselist=False)

    def __init__(self, nome, descricao, preco, is_visivel, is_deleted,
                 empresa):
        self.nome = nome
        self.descricao = descricao
        self.preco = preco
        self.is_visivel = is_visivel
        self.is_deleted = is_deleted
        self.empresa = empresa

    def __str__(self):
        return '<Produto %r>' % (self.nome)
Esempio n. 3
0
class Admin(db.Model, CRUD):
    __tablename__   = "Admin"
    uuid            = db.Column(db.String(36), primary_key=True)
    phone_number    = db.Column(db.String(11), nullable=False)
    hash_password   = db.Column(db.String(128), nullable=False)
    open_id         = db.Column(db.String(30))
    expire          = db.Column(db.DateTime(), default=datetime.datetime.utcnow)
    role            = db.Column(db.Integer, default=False)
    is_active       = db.Column(db.Boolean, default=False)
    c_time          = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    l_time          = db.Column(db.DateTime)
    nodes           = db.relationship('NodeTree', secondary=admin_m2m_node, lazy="dynamic", backref=db.backref('users', lazy='joined'))

    @property
    def password(self):
        raise AttributeError('password cannot be read')

    @password.setter
    def password(self, password):
        self.hash_password = generate_password_hash(password)

    def confirm_password(self, password):
        return check_password_hash(self.hash_password, password)

    @classmethod
    def find_by_phone_number(cls, phone_number):
        return cls.query.filter(cls.phone_number==phone_number).first()

    @classmethod
    def find_by_uuid(cls, uuid):
        return cls.query.filter(cls.uuid==uuid).first()
Esempio n. 4
0
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(120), nullable=False)
    cashBalance = db.Column(db.Float, nullable=False)
    purchaseHistory = db.relationship('PurchaseHistory',
                                      backref='user',
                                      lazy=True)

    def __init__(self, name, cashBalance):
        self.name = name
        self.cashBalance = cashBalance

    def insert(self):
        db.session.add(self)
        db.session.commit()

    def update(self):
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    @classmethod
    def get_by_name(cls, name):
        return cls.query.filter_by(name=name).first()

    @classmethod
    def get_by_id(cls, id):
        return cls.query.filter_by(id=id).first()

    @classmethod
    def get_all(cls):
        return cls.query.all()
Esempio n. 5
0
class NodeMsg(db.Model, basic_opt):
    uuid = db.Column(db.Integer, primary_key=True, autoincress=True)
    title = db.Column(db.String(128), nullable=False)
    msg = db.Column(db.String(256), nullable=False)
    nodes = db.relationship('NodeTree',
                            secondary=node_m2m_msg,
                            lazy='dynamic',
                            backref=db.backref('msgs', lazy='joined'))
Esempio n. 6
0
class EmpresaModel(db.Model):
    __tablename__ = 'tb_empresa'

    id = db.Column(db.Integer, primary_key=True)
    nome = db.Column(db.String(255), nullable=False)
    email = db.Column(db.String(255), nullable=False)
    telefone = db.Column(db.String(13), nullable=False)
    instagram = db.Column(db.String(255), nullable=True)
    facebook = db.Column(db.String(255), nullable=True)
    is_delivery = db.Column(db.Boolean, default=False)
    is_deleted = db.Column(db.Boolean, default=False)
    dt_insercao = db.Column(db.DateTime, default=func.current_timestamp())

    fk_id_endereco = db.Column(db.Integer,
                               db.ForeignKey('tb_endereco.id'),
                               nullable=False)
    endereco = db.relationship(
        'EnderecoModel',
        backref='endereco',
        primaryjoin="EmpresaModel.fk_id_endereco==EnderecoModel.id",
        uselist=False)

    fk_id_natureza = db.Column(db.Integer,
                               db.ForeignKey('tb_natureza.id'),
                               nullable=False)
    natureza = db.relationship(
        'NaturezaModel',
        backref='natureza',
        primaryjoin="EmpresaModel.fk_id_natureza==NaturezaModel.id",
        uselist=False)

    def __init__(self, nome, natureza, endereco, email, telefone, instagram,
                 facebook, is_delivery):
        self.nome = nome
        self.natureza = natureza
        self.endereco = endereco
        self.email = email
        self.telefone = telefone
        self.instagram = instagram
        self.facebook = facebook
        self.is_delivery = is_delivery

    def __str__(self):
        return '<Empresa %r>' % (self.nome)
Esempio n. 7
0
class WpUserMeta(db.Model):
    __tablename__ = 'wp_usermeta'
    __bind_key__ = 'sideka'
    umeta_id = db.Column('umeta_id',
                         db.Integer,
                         primary_key=True,
                         nullable=False)
    meta_key = db.Column('meta_key', db.String(length=255))
    meta_value = db.Column('meta_value', db.Text(length=None))

    user_id = db.Column('user_id', db.Integer, db.ForeignKey('wp_users.ID'))
    user = db.relationship('WpUser')

    def __repr__(self):
        return '<WpUserMeta(%r, %r)>' % (self.meta_key, self.meta_value)
Esempio n. 8
0
class NodeInfo(db.Model, basic_opt):
    uuid            = db.Column(db.Integer, primary_key=True, autoincress=True)
    age             = db.Column(db.Integer)
    sex             = db.Column(db.Boolean, default=False)
    campuse_id      = db.Column(db.String(60), nullable=False)
    nodes           = db.relationship('NodeTree', secondary=node_m2m_info, lazy='dynamic', backref=db.backref('infos', lazy='joined'))

    @classmethod
    def find_by_uuid(cls, uuid):
        ret = RetStatus(True)
        try:
            ret.data = cls.query.filter(cls.uuid == uuid).first()
        except SQLAlchemyError as e:
            return RetStatus(False, e.message)
        return ret
Esempio n. 9
0
class Encoding(db.Model):
    __tablename__ = 'encodings'

    id = db.Column('id', db.Integer, primary_key=True, autoincrement=True)
    medidas = db.Column('medidas', db.ARRAY(db.Float, 128))

    pessoa_id = db.Column('pessoa_id', db.ForeignKey("pessoas.id"))

    pessoa = db.relationship("Pessoa")

    def __init__(self, pessoa_id, medidas, id=None):
        self.pessoa_id = pessoa_id
        self.medidas = medidas
        self.id = id

    def __repr__(self):
        return "<Encoding [pessoa_id = %s, medidas = %s]>" % (self.pessoa_id,
                                                              self.medidas)
Esempio n. 10
0
class User(db.Model, basic_opt):
    __tablename__ = "t_auth_user"
    uuid = db.Column(db.String(36), primary_key=True)
    username = db.Column(db.String(128), nullable=False)
    hash_password = db.Column(db.String(128), nullable=False)
    login_type = db.Column(db.Boolean, default=False)
    create_time = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    nodes = db.relationship('NodeTree',
                            secondary=node_m2m_user,
                            lazy='dynamic',
                            backref=db.backref('users', lazy='joined'))

    @property
    def password(self):
        raise AttributeError("password can't be read.")

    @password.setter
    def password(self, password):
        self.hash_password = generate_password_hash(password)

    def confirm_password(self, password):
        return check_password_hash(self.hash_password, password)

    @classmethod
    def find_by_username(cls, username):
        user = None
        try:
            user = cls.query.filter(cls.username == username).first()
        except SQLAlchemyError as e:
            return RetStatus(False, e.message)
        return RetStatus(status=True, data=user)

    @classmethod
    def find_by_uuid(cls, uuid):
        user = None
        try:
            user = cls.query.filter(cls.uuid == uuid).first()
        except SQLAlchemyError as e:
            return RetStatus(False, e.message)
        return RetStatus(True, data=user)
Esempio n. 11
0
class BookStore(db.Model):
    __tablename__ = 'book_store'
    id = db.Column(db.Integer, primary_key=True)
    cashBalance = db.Column(db.Float, nullable=False)
    openingHours = db.Column(db.String(200), nullable=False)
    storeName = db.Column(db.String(120), nullable=False)
    books = db.relationship('Book', backref='book_store', lazy=True)

    def __init__(self, storeName, cashBalance, openingHours):
        self.storeName = storeName
        self.cashBalance = cashBalance
        self.openingHours = openingHours

    def insert(self):
        db.session.add(self)
        db.session.commit()

    def update(self):
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()

    @classmethod
    def get(cls, storeName):
        return cls.query.filter_by(storeName=storeName).first()

    @classmethod
    def get_all_by_time(cls, time):
        return cls.query.filter_by(openingHours=time).all()

    @classmethod
    def get_all_by_count(cls, count, isGreater):
        book_count = (func.count(cls.id)).label("book_count")
        if (isGreater == True):
            return cls.query. \
                join(Book, cls.id == Book.bookStoreId).group_by(cls.id).having(book_count > count).all()
        else:
            return db.session.query(cls) \
            .join(Book, cls.id == Book.bookStoreId).group_by(cls.id).having(book_count < count).all()

    @classmethod
    def get_all_by_price_and_count(cls, price, count, isGreater):
        book_count = (func.count(cls.id)).label("book_count")
        if (isGreater == True):
            return cls.query.join(Book, cls.id == Book.bookStoreId). \
                filter(Book.price <= price).group_by(cls.id).having(book_count > count).all()
        else:
            return cls.query.join(Book, cls.id == Book.bookStoreId). \
                filter(Book.price <= price).group_by(cls.id).having(book_count < count).all()

    @classmethod
    def get_all_by_key_word(cls, keyword):
        search = "%{}%".format(keyword)
        return cls.query.filter(cls.storeName.like(search)).order_by(
            cls.storeName).all()

    @classmethod
    def get_all(cls):
        return cls.query.all()
Esempio n. 12
0
class EmpresaModel(db.Model):
    __tablename__ = 'tb_empresa'

    id = db.Column(db.Integer, primary_key=True)
    nome = db.Column(db.String(255), nullable=False)
    email = db.Column(db.String(255), nullable=False)
    telefone = db.Column(db.String(13), nullable=False)
    instagram = db.Column(db.String(255), nullable=True)
    user_photo_url_instagram = db.Column(db.Text(), nullable=True)
    facebook = db.Column(db.String(255), nullable=True)
    latitude = db.Column(db.Numeric(10, 8), nullable=True)
    longitude = db.Column(db.Numeric(11, 8), nullable=True)
    is_tempo_real_maps = db.Column(db.Boolean, default=False)
    is_delivery = db.Column(db.Boolean, default=False)
    is_prefeitura = db.Column(db.Boolean, default=False)
    is_visivel = db.Column(db.Boolean, default=False)
    is_deleted = db.Column(db.Boolean, default=False)
    dt_insercao = db.Column(db.DateTime, default=func.current_timestamp())

    fk_id_endereco = db.Column(db.Integer,
                               db.ForeignKey('tb_endereco.id'),
                               nullable=False)
    endereco = db.relationship(
        'EnderecoModel',
        backref='endereco',
        primaryjoin="EmpresaModel.fk_id_endereco==EnderecoModel.id",
        uselist=False)

    fk_id_natureza = db.Column(db.Integer,
                               db.ForeignKey('tb_natureza.id'),
                               nullable=False)
    natureza = db.relationship(
        'NaturezaModel',
        backref='natureza',
        primaryjoin="EmpresaModel.fk_id_natureza==NaturezaModel.id",
        uselist=False)

    fk_id_atividade = db.Column(db.Integer,
                                db.ForeignKey('tb_atividade.id'),
                                nullable=False)
    atividade = db.relationship(
        'AtividadeModel',
        backref='atividade',
        primaryjoin="EmpresaModel.fk_id_atividade==AtividadeModel.id",
        uselist=False)


    def __init__(self, nome, natureza, atividade, endereco, email, telefone, instagram, facebook,\
        latitude, longitude, is_tempo_real_maps, is_delivery, is_prefeitura, is_visivel):
        self.nome = nome
        self.natureza = natureza
        self.atividade = atividade
        self.endereco = endereco
        self.email = email
        self.telefone = telefone
        self.instagram = instagram
        self.facebook = facebook
        self.latitude = latitude
        self.longitude = longitude
        self.is_tempo_real_maps = is_tempo_real_maps
        self.is_delivery = is_delivery
        self.is_prefeitura = is_prefeitura
        self.is_visivel = is_visivel

    def __str__(self):
        return '<Empresa %r>' % (self.nome)