Exemplo n.º 1
0
class Trade(db.Model):
    __tablename__ = 'trades'

    id = db.Column(db.Integer, primary_key=True)
    symbol_id = db.Column(db.String,
                          db.ForeignKey('stocks.symbol'),
                          nullable=False,
                          index=True)
    position_id = db.Column(db.Integer, db.ForeignKey('positions.id'))
    portfolio_id = db.Column(db.Integer, db.ForeignKey('portfolios.id'))
    price = db.Column(db.Numeric, nullable=False)
    quantity = db.Column(db.Integer, nullable=False)
    date = db.Column(db.Date, nullable=False)
    div_yield = db.Column(db.Numeric, nullable=True)
    ex_div = db.Column(db.Date, nullable=True)
    div_pay = db.Column(db.Date, nullable=True)

    def __init__(self, symbol_id, position_id, portfolio_id, price, quantity,
                 date, div_yield, ex_div, div_pay):
        self.symbol_id = symbol_id
        self.position_id = position_id
        self.portfolio_id = portfolio_id
        self.price = price
        self.quantity = quantity
        self.date = date
        self.div_yield = div_yield
        self.ex_div = ex_div
        self.div_pay = div_pay

    def __repr__(self):
        return 'id: {}, symbol_id: {}, position_id: {}, portfolio_id {}'.format(
            self.id, self.symbol_id, self.position_id, self.portfolio_id)
Exemplo n.º 2
0
class Accueil(db.Model):
    __tablename__ = 'accueils'
    id = db.Column(db.Integer, primary_key=True)
    accueillant_id = db.Column(
        db.Integer, db.ForeignKey('accueillants.id', ondelete="cascade"))
    accueilli_id = db.Column(
        db.Integer, db.ForeignKey('accueillis.id', ondelete="cascade"))
Exemplo n.º 3
0
class ReleaseSong(db.Model):
    """
    Linking table for Releases and their songs
    """
    __tablename__ = 'release_songs'
    id = db.Column(db.Integer, primary_key=True)
    release_id = db.Column(db.Integer, db.ForeignKey('releases.id'))
    song_id = db.Column(db.Integer, db.ForeignKey('songs.id'))
Exemplo n.º 4
0
class ArtistAward(db.Model):
    """
    Linking table for Artists and their Awards
    """
    __tablename__ = 'artist_awards'
    id = db.Column(db.Integer, primary_key=True)
    artist_id = db.Column(db.Integer, db.ForeignKey('artists.id'))
    award_id = db.Column(db.Integer, db.ForeignKey('awards.id'))
Exemplo n.º 5
0
class ArtistConcert(db.Model):
    """
    Linking table for Artists and their Concerts
    """
    __tablename__ = 'artist_concerts'
    id = db.Column(db.Integer, primary_key=True)
    artist_id = db.Column(db.Integer, db.ForeignKey('artists.id'))
    concert_id = db.Column(db.Integer, db.ForeignKey('concerts.id'))
Exemplo n.º 6
0
class Elo(db.Model):
    __tablename__ = "elo"

    id = db.Column(db.String(128), primary_key=True)
    date = db.Column(db.DateTime)

    team_id = db.Column(db.String(128), db.ForeignKey("team.id"))
    guild_id = db.Column(db.String(128), db.ForeignKey("guild.id"))
Exemplo n.º 7
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    ownerId = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    date = db.Column(db.DateTime, default=datetime.today())
    content = db.Column(db.Text, nullable=False)
    postId = db.Column(db.Integer, db.ForeignKey('post.id'), nullable=False)

    def __repr__(self):
        return '<Comment %r>' % self.id
Exemplo n.º 8
0
class Message(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    sender_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    recipient_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    body = db.Column(db.String(140))
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)

    def __ref__(self):
        return '<Message {}>'.format(self.body)
Exemplo n.º 9
0
class ArtistRelease(db.Model):
    """
    Linking table for Artists and their Releases
    """
    __tablename__ = 'artist_releases'
    id = db.Column(db.Integer,
                   db.Sequence('artist_release_id_seq'),
                   primary_key=True)
    artist_id = db.Column(db.Integer, db.ForeignKey('artists.id'))
    release_id = db.Column(db.Integer, db.ForeignKey('releases.id'))
Exemplo n.º 10
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.String(140))
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    language = db.Column(db.String(5))

    def __repr__(self):
        return '<Comment {}>'.format(self.body)
Exemplo n.º 11
0
class Period(db.Model):
    id = db.Column(db.Integer,primary_key = True)
    batch_id = db.Column(db.Integer, db.ForeignKey('batch.id'))
    name = db.Column(db.String(40))
    start_time = db.Column(db.Time)
    end_time = db.Column(db.Time)
    department_id = db.Column(db.Integer, db.ForeignKey('department.id'))
    day = db.Column(db.Integer)
    def __repr__(self):
        return "<{name}  {start} to {end}>".format(name=self.name,start=self.start_time,end=self.end_time)
Exemplo n.º 12
0
class CommentPopup(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.String(140))
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    language = db.Column(db.String(5))
    payload_json = db.Column(db.Text)

    def get_data(self):
        return json.loads(str(self.payload_json))
Exemplo n.º 13
0
class Campanha(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    empresa = db.Column(db.Integer, db.ForeignKey('empresa.id'))
    produto = db.Column(db.Integer, db.ForeignKey('produto.id'))
    campanha = db.Column(db.String(150))
    valorcamp = db.Column(db.Float)
    descr = db.Column(db.String(250))
    condicoes = db.Column(db.String(250))
    ofertas = db.Column(db.String(250))
    fotos = db.Column(db.String(250))
    campuser = db.relationship('CampUser', cascade="all, delete-orphan")
    deleted = db.Column(db.Boolean(), default=False)
Exemplo n.º 14
0
class Answer(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    answer = db.Column(db.Text, nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.now)
    comments = db.relationship("Comment", backref="answer", lazy=True)

    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
    question_id = db.Column(db.Integer,
                            db.ForeignKey("question.id"),
                            nullable=False)

    def __repr__(self):
        return "Answer: '%s'" % self.answer
Exemplo n.º 15
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text, nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.now)

    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
    post_id = db.Column(db.Integer, db.ForeignKey("post.id"), nullable=False)

    def __repr__(self):
        return 'Comment created by "%s" for "%s"' % (
            self.author.username,
            self.post.title,
        )
Exemplo n.º 16
0
class Player(db.Model):
    __tablename__ = "player"

    id = db.Column(db.String(128), primary_key=True)
    team_id = db.Column(db.String(128), db.ForeignKey("team.id"))
    guild_id = db.Column(db.String(128), db.ForeignKey("guild.id"))

    shardId = db.Column(db.String(128))
    name = db.Column(db.String(128))
    lifetimeGold = db.Column(db.Integer)
    lossStreak = db.Column(db.Integer)
    winStreak = db.Column(db.Integer)
    played = db.Column(db.Integer)
    played_ranked = db.Column(db.Integer)
    wins = db.Column(db.Integer)
    xp = db.Column(db.Integer)

    participated = db.relationship("Participant",
                                   backref="player",
                                   order_by="desc(Participant.createdAt)")

    @hybrid_property
    def skillTier(self):
        if self.participated:
            return self.participated[0].skillTier
        else:
            return -1

    def __init__(self, **kwargs):
        super(Player, self).__init__(**kwargs)

    def __repr__(self):
        return self.name

    @property
    def is_authenticated(self):
        return True

    @property
    def is_active(self):
        return True

    @property
    def is_anonymous(self):
        return False

    def get_id(self):
        return self.id
Exemplo n.º 17
0
class Device(db.Model):
    __tablename__ = 'devices'
    uid = db.Column(db.Integer, primary_key=True)
    variant = db.Column(db.String(20), unique=False)
    name = db.Column(db.String(20), unique=False)
    security = db.Column(db.Boolean)
    part_number = db.Column(db.String(20), unique=False)
    imei_number = db.Column(db.String(40), unique=True, nullable=False)
    mfg_country = db.Column(db.String(30))
    vl_tag = db.Column(db.String(10), unique=True, nullable=False)
    purpose_group = db.Column(db.String(20))
    assigned_date = db.Column(db.DateTime, nullable=False, index=True)
    comments = db.Column(db.String(255))

    assignee_id = db.Column(db.Integer, db.ForeignKey('users.uid'), nullable=False, default=1)

    def __init__(self, variant, name, security, part_number, imei, country, vlid, pgrp, assigned_date, comments, assignee=1):
        self.variant = variant.title()
        self.name = name.title().upper()
        self.is_device_secure(str(security).lower())
        self.part_number = part_number.title().upper()
        self.imei_number = imei.title()
        self.mfg_country = country.title().upper()
        self.vl_tag = vlid.title().upper()
        self.purpose_group = pgrp.title()
        self.assigned_date = assigned_date
        self.comments = comments
        if not assignee:
            self.assigned_id = 1
        else:
            self.assignee_id = assignee

    def is_device_secure(self, security):
        self.security = (security == "true")
Exemplo n.º 18
0
class Download(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    cliente = db.Column(db.Integer, db.ForeignKey('user.id'))
    data = db.Column(db.DATETIME)
    qtd = db.Column(db.Integer, default=0)
    qtm = db.Column(db.Integer, default=0)
    desc = db.Column(db.Boolean, default=False)
Exemplo n.º 19
0
class Expense(Base):
    __tablename__ = 'expense'

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship('User', backref='expenses')

    timestamp = db.Column(db.DateTime(), index=True, nullable=False)
    amount = db.Column(db.Float(), nullable=False)
    description = db.Column(db.String(), nullable=False)

    def __init__(self, user_id, timestamp, description, amount):
        self.user_id = user_id
        self.timestamp = timestamp
        self.amount = amount
        self.description = description

    def __repr__(self):
        return '<Expense %r>' % self.id

    def to_dict(self):
        dt = datetime_to_pendulum(self.timestamp)
        timestamp = dt.to_iso8601_string()

        return {
            'id': self.id,
            'user_id': self.user_id,
            'timestamp': timestamp,
            'amount': self.amount,
            'description': self.description
        }
Exemplo n.º 20
0
class Favorite(db.Model):
    __tablename__ = 'Favorite'
    favoriteID = db.Column(db.String(100), primary_key=True)
    createTime = db.Column(db.DateTime)
    tenderID = db.Column(db.String(100))
    tag = db.Column(db.String(100))
    userID = db.Column(db.String(100), db.ForeignKey('UserInfo.userID'))

    def __init__(self,
                 favoriteID=None,
                 createTime=None,
                 tenderID=None,
                 userID=None,
                 tag='tender'):
        self.favoriteID = favoriteID
        self.createTime = createTime
        self.tenderID = tenderID
        self.userID = userID
        self.tag = tag

    def __repr__(self):
        return self.favoriteID

    @staticmethod
    def generate(f):
        res = {}
        res['favoriteID'] = f.favoriteID
        res['favoriteCreateTime'] = str(f.createTime)
        res['tag'] = f.tag
        return res
Exemplo n.º 21
0
class Artist(db.Model):
    """
    Model of Artists
    A Artist is a single person or collection of people that attempt to create music
    """
    __tablename__ = 'artists'
    id = db.Column(db.Integer, db.Sequence('artist_id_seq'), primary_key=True)
    name = db.Column(db.String(128))
    bio = db.Column(db.String)
    large_image = db.Column(db.String)
    medium_image = db.Column(db.String)
    small_image = db.Column(db.String)
    spotify_url = db.Column(db.String)
    uri = db.Column(db.String)

    primary_label_id = db.Column(
        db.Integer,
        db.ForeignKey('labels.id', use_alter=True, name='fk_primary_label_id'))
    primary_label = db.relationship('Label',
                                    backref='artists',
                                    foreign_keys='Artist.primary_label_id')

    concerts = db.relationship('Concert',
                               backref='artists',
                               secondary='artist_concerts')
    releases = db.relationship('Release',
                               backref='artists',
                               secondary='artist_releases')
    awards = db.relationship('Award',
                             backref='artists',
                             secondary='artist_awards')
class Movement(db.Model):
    """A specific movement belongs to a set and has repetition time and number of movement."""
    movement_id = db.Column(db.Integer, primary_key=True)
    set_id = db.Column(
        db.Integer,
        db.ForeignKey('movement_set.movement_set_id'),
        nullable=False
    )
    name = db.Column(db.String, nullable=False)
    repetitions = db.relationship('Repetition', backref = 'movement', lazy=True)
    actions = db.relationship('MovementAction', backref = 'movement', lazy=True)

    @classmethod
    def find_for_set(cls, set_id):
        return cls.query.filter_by(set_id=set_id).all()

    @classmethod
    def create_movement(cls, name, set_id):
        movement = Movement(name=name, set_id=set_id)
        db.session.add(movement)
        db.session.commit()

    @classmethod
    def delete_movement(cls, movement_id):
        """."""
        movement = cls.query.filter_by(movement_id=movement_id).first()

        for repetition in movement.repetitions:
            db.session.delete(repetition)
        for action in movement.actions:
            db.session.delete(action)
        db.session.delete(movement)
        db.session.commit()
Exemplo n.º 23
0
class DepartmentArea(db.Model):
    __tablename__ = 'DepartmentArea'
    areaID = db.Column(db.String(100), primary_key=True)
    areaName = db.Column(db.String(100))
    createTime = db.Column(db.DateTime)
    departmentID = db.Column(db.String(100),
                             db.ForeignKey('Department.departmentID'))

    def __init__(self,
                 areaID=None,
                 areaName=None,
                 createTime=None,
                 departmentID=None):
        self.areaID = areaID
        self.areaName = areaName
        self.createTime = createTime
        self.departmentID = departmentID

    def __repr__(self):
        return self.areaID

    @staticmethod
    def generate(o):
        res = {}
        res['areaID'] = o.areaID
        res['areaName'] = o.areaName
        res['createTime'] = str(o.createTime)
        res['departmentID'] = o.departmentID
        return res
Exemplo n.º 24
0
class LocationModel(db.Model):
    __tablename__ = 'location'
    location_id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer(), db.ForeignKey('user.user_id'))
    lon = db.Column(db.Float())
    lat = db.Column(db.Float())
    comments = db.Column(db.String())

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

    def update_to_db(self):
        db.session.merge(self)
        db.session.commit()

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

    @classmethod
    def read_from_db(cls, user_id):
        return cls.query.join(UserModel).filter(
            UserModel.user_id == user_id).all()

    @classmethod
    def get_by_location_id(cls, location_id):
        return cls.query.filter(cls.location_id == location_id).one_or_none()
Exemplo n.º 25
0
class CertificationGrade4(db.Model):
    __tablename__ = 'CertificationGrade4'
    gradeID = db.Column(db.String(100), primary_key=True)
    gradeName = db.Column(db.String(100))
    superiorID = db.Column(db.String(100), db.ForeignKey('CertificationGrade3.gradeID'))


    def __init__(self, gradeID=None, gradeName=None, superiorID=None):
        self.gradeID = gradeID
        self.gradeName = gradeName
        self.superiorID = superiorID


    @staticmethod
    def create(info):
        certificationGrade4 = CertificationGrade4(
            gradeID=info['gradeID'], gradeName=info['gradeName'],
            superiorID=info['superiorID']
        )
        db.session.add(certificationGrade4)
        return (True, None)

    @staticmethod
    def generate(c):
        res = {}
        res['gradeID'] = c.gradeID
        res['gradeName'] = c.gradeName
        return res
class PullRequests(db.Model):
    __tablename__ = 'pullrequests'
    id = db.Column(db.Integer, primary_key=True)
    number = db.Column(db.Integer, nullable=False)
    created_at = db.Column(db.TIMESTAMP, nullable=False)
    updated_at = db.Column(db.TIMESTAMP, nullable=False)
    merged_at = db.Column(db.TIMESTAMP)
    closed_at = db.Column(db.TIMESTAMP)
    title = db.Column(db.Text)
    body = db.Column(db.Text)
    repo_id = db.Column(db.Integer,
                        db.ForeignKey('repositories.id'),
                        nullable=False)
    url = db.Column(db.String(255), unique=True, nullable=False)
    patch_url = db.Column(db.String(255), unique=True, nullable=False)
    is_security = db.Column(db.Integer)
    is_probable_cve = db.Column(db.Integer)
    is_passed_through_model = db.Column(db.Integer)

    __table_args__ = (CheckConstraint('updated_at >= created_at'), )

    @validates('url')
    def validate_url(self, key, url):
        o = urlparse(url)
        assert o.geturl(), "Please provide valid url"
        return url

    @validates('is_security', 'is_probable_cve', 'is_passed_through_model')
    def validate_flags(self, key, flag):
        assert int(flag) in (0, 1), "Please provide flag as 0 or 1"
        return flag
Exemplo n.º 27
0
class Ocor_hd(db.Model):
    __tablename__ = 'tab_ocorHd'
    reg_id = db.Column(db.Integer, primary_key=True)
    ocor_id = db.Column(db.String(500), db.ForeignKey('tab_ocorBios.ocor_id'))
    hd_nome = db.Column(db.String(255))
    hd_tamanho = db.Column(db.Float)
    hd_livre = db.Column(db.Float)
Exemplo n.º 28
0
class Position(db.Model):
    __tablename__ = 'positions'

    id = db.Column(db.Integer, primary_key=True)
    portfolio_id = db.Column(db.Integer, db.ForeignKey('portfolios.id'))
    symbol = db.Column(db.String)
    cost = db.Column(db.Numeric)
    value = db.Column(db.Numeric)
    sharecount = db.Column(db.Integer)
    div_eligible_sharecount = db.Column(db.Integer)
    # taking out cascade="all, delete-orphan" from trades
    trades = db.relationship('Trade', backref='position', lazy='dynamic')

    def __init__(self, portfolio_id, symbol, cost, value, sharecount,
                 div_eligible_sharecount):
        self.portfolio_id = portfolio_id
        self.symbol = symbol
        self.cost = cost
        self.value = value
        self.sharecount = sharecount
        self.div_eligible_sharecount = div_eligible_sharecount
        # self.trades = trades

    def __repr__(self):
        return 'id: {}, portfolio_id: {}, symbol: {}, cost: {}, value: {} sharecount: {}'.format(
            self.id, self.portfolio_id, self.symbol, self.cost, self.value,
            self.sharecount)
class MovementAction(db.Model):
    """The movements which have been implemented by a body builder."""
    movement_action_id = db.Column(db.Integer, primary_key=True)
    movement_id = db.Column(db.Integer, db.ForeignKey('movement.movement_id'))
    repetition = db.Column(db.Integer, nullable=False)
    weight = db.Column(db.Integer, nullable=False)
    date = db.Column(db.Date, nullable=False)


    @classmethod
    def create_action(cls, movement_id, repetition, weight):
        """Creates an action."""
        db.session.add(
            cls(
                movement_id=movement_id,
                repetition=repetition,
                weight=weight,
                date=date.today()
            )
        )
        db.session.commit()


    @classmethod
    def get_by_movement(cls, movement_id):
        """Returns all the actions for a specific movement."""
        return cls.query.filter_by(movement_id=movement_id).all()
Exemplo n.º 30
0
class Message(db.Model):
    __tablename__ = 'Message'
    messageID = db.Column(db.String(100), primary_key=True)
    foreignID = db.Column(db.String(100))
    # merchandiseID = db.Column(db.String(100), db.ForeignKey('PostedMerchandise.merchandiseID'))
    # replyID = db.Column(db.String(100))
    fromUserID = db.Column(db.String(100), db.ForeignKey('UserInfo.userID'))
    toUserID = db.Column(db.String(100), db.ForeignKey('UserInfo.userID'))
    description = db.Column(db.Text)
    createTime = db.Column(db.DateTime)
    tag = db.Column(db.Integer)
    state = db.Column(db.Integer)

    fromUserID_FK = relationship("UserInfo", foreign_keys=[fromUserID])
    toUserID_FK = relationship("UserInfo", foreign_keys=[toUserID])

    def __init__(self,
                 messageID=None,
                 foreignID=None,
                 fromUserID=None,
                 toUserID=None,
                 description=None,
                 createTime=None,
                 tag=0,
                 state=False):
        self.messageID = messageID
        self.foreignID = foreignID
        self.fromUserID = fromUserID
        self.toUserID = toUserID
        self.description = description
        self.createTime = createTime
        self.tag = tag
        self.state = state

    def __repr__(self):
        return self.messageID

    @staticmethod
    def generate(o):
        res = {}
        res['messageID'] = o.messageID
        res['foreignID'] = o.foreignID
        res['fromUserID'] = o.fromUserID
        res['toUserID'] = o.toUserID
        res['description'] = o.description
        res['createTime'] = str(o.createTime)
        return res