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 PurchaseHistory(db.Model):
    __tablename__ = 'puchase_history'
    id = db.Column(db.Integer, primary_key=True)
    userId = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    bookName = db.Column(db.String(200), nullable=False)
    storeName = db.Column(db.String(200), nullable=False)
    transactionAmount = db.Column(db.Float, nullable=False)
    transactionDate = db.Column(db.String(200), nullable=False)

    def __init__(self, userId, bookName, storeName, transactionAmount,
                 transactionDate):
        self.userId = userId
        self.bookName = bookName
        self.storeName = storeName
        self.transactionAmount = transactionAmount
        self.transactionDate = transactionDate

    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_user_id(cls, userId):
        return cls.query.filter_by(userId=userId).all()

    @classmethod
    def get_most_popular_store_name(cls):
        pass
Esempio n. 4
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. 5
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. 6
0
class Book(db.Model):
    __tablename__ = "book"
    id = db.Column(db.Integer, primary_key=True)
    bookStoreId = db.Column(db.Integer,
                            db.ForeignKey('book_store.id'),
                            nullable=False)
    bookName = db.Column(db.String(200), nullable=False)
    price = db.Column(db.Float, nullable=False)

    def __init__(self, bookStoreId, bookName, price):
        self.bookStoreId = bookStoreId
        self.bookName = bookName
        self.price = price

    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, bookName):
        return cls.query.filter_by(bookName=bookName).first()

    @classmethod
    def get_all(cls):
        return cls.query.all()

    @classmethod
    def get_by_price(cls, price):
        return cls.query.filter(cls.price <= price).order_by(
            cls.price, cls.bookName).all()

    @classmethod
    def get_by_key_word(cls, key_word):
        search = "%{}%".format(key_word)
        return cls.query.filter(cls.bookName.like(search)).order_by(
            cls.bookName).all()

    @classmethod
    def get_price_by_store_name_book_name(cls, store_name, book_name):
        return db.session.query(cls.price).join(book_store.BookStore, cls.bookStoreId == book_store.BookStore.id). \
            filter(book_store.BookStore.storeName == store_name, cls.bookName == book_name).first()
Esempio n. 7
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. 8
0
from werkzeug.security import generate_password_hash, check_password_hash
from sqlalchemy.exc import SQLAlchemyError
from common.database import db, CRUD
from common.schema import ma
from common.retmsg import ret_msg
from models.nodetree import NodeTree
import uuid
import datetime

admin_m2m_node = db.Table('admin_m2m_node',
                    db.Column('vip_uuid', db.String(36), db.ForeignKey('Admin.uuid')),
                    db.Column('node_uuid', db.String(36), db.ForeignKey('NodeTree.node_uuid')))

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
Esempio n. 9
0
from common.schema import ma
from common.database import db, basic_opt
from model.nodetree import NodeTree

node_m2m_msg = db.Table(
    't_relate_nodemsg',
    db.Column('msg_uuid', db.String(36), db.ForeignKey('NodeMsg.uuid')),
    db.Column('node_uuid', db.String(36), db.ForeignKey('NodeTree.node_uuid')))


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'))


class OutMsgSchema(ma.Schema):
    class Meta:
        fields = ('title', 'msg', 'uuid')
Esempio n. 10
0
from sqlalchemy.exc import SQLAlchemyError
from werkzeug.security import generate_password_hash, check_password_hash
import datetime

from common.database import db, basic_opt
from common.schema import ma
from common.ret_status import RetStatus
from model.nodetree import NodeTree

node_m2m_user = db.Table(
    't_relate_node2user',
    db.Column('user_uuid', db.String(36), db.ForeignKey('User.uuid')),
    db.Column('node_uuid', db.String(36), db.ForeignKey('NodeTree.node_uuid')))


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.")
Esempio n. 11
0
from sqlalchemy.exc import SQLAlchemyError

from common.schema import ma
from common.database import db, basic_opt
from common.ret_status import RetStatus
from model.nodetree import NodeTree

node_m2m_info = db.Table('t_relate_nodeinfo',
                         db.Column('info_uuid', db.String(36), db.ForeignKey('NodeInfo.uuid')),
                         db.Column('node_uuid', db.String(36), db.ForeignKey('NodeTree.node_uuid')))

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

class OutInfoSchema(ma.Schema):
    class Meta:
        fields = ('age', 'sex', 'campus_id', 'uuid')
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)