Example #1
0
class TrustedReview(db.Model):
    __tablename__ = 'trusted_reviews'

    id = db.Column(db.Integer, primary_key=True)
    reviewer_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    app_id = db.Column(db.Integer, db.ForeignKey('trusted_applications.id'), nullable=False)
    created_time = db.Column(db.DateTime(timezone=False), default=datetime.utcnow)
    comment = db.Column(db.String(length=4000), nullable=False)
    recommendation = db.Column(ChoiceType(TrustedRecommendation, impl=db.Integer()),
                               nullable=False)
    reviewer = db.relationship('User', uselist=False, lazy='joined', foreign_keys=[reviewer_id])
    application = db.relationship('TrustedApplication', uselist=False, lazy='joined',
                                  foreign_keys=[app_id])
Example #2
0
class Ban(db.Model):
    __tablename__ = 'bans'

    id = db.Column(db.Integer, primary_key=True)
    created_time = db.Column(db.DateTime(timezone=False),
                             default=datetime.utcnow)
    admin_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True)
    user_ip = db.Column(db.Binary(length=16), nullable=True)
    reason = db.Column(db.String(length=2048), nullable=False)

    admin = db.relationship('User',
                            uselist=False,
                            lazy='joined',
                            foreign_keys=[admin_id])
    user = db.relationship('User',
                           uselist=False,
                           lazy='joined',
                           foreign_keys=[user_id])

    __table_args__ = (
        Index('user_ip_4', 'user_ip', mysql_length=4, unique=True),
        Index('user_ip_16', 'user_ip', mysql_length=16, unique=True),
    )

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

    @property
    def ip_string(self):
        if self.user_ip:
            return str(ip_address(self.user_ip))

    @classmethod
    def all_bans(cls):
        return cls.query

    @classmethod
    def by_id(cls, id):
        return cls.query.get(id)

    @classmethod
    def banned(cls, user_id, user_ip):
        if user_id:
            if user_ip:
                return cls.query.filter((cls.user_id == user_id)
                                        | (cls.user_ip == user_ip))
            return cls.query.filter(cls.user_id == user_id)
        if user_ip:
            return cls.query.filter(cls.user_ip == user_ip)
        return None
Example #3
0
class UserPreferences(db.Model):
    __tablename__ = 'user_preferences'

    user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE'), primary_key=True)

    def __init__(self, user_id):
        self.user_id = user_id

    def __repr__(self):
        return '<UserPreferences %r>' % self.user_id

    user = db.relationship('User', back_populates='preferences')
    hide_comments = db.Column(db.Boolean, nullable=False, default=False)
Example #4
0
class TrustedApplication(db.Model):
    __tablename__ = 'trusted_applications'

    id = db.Column(db.Integer, primary_key=True)
    submitter_id = db.Column(db.Integer,
                             db.ForeignKey('users.id'),
                             nullable=False,
                             index=True)
    created_time = db.Column(db.DateTime(timezone=False),
                             default=datetime.utcnow)
    closed_time = db.Column(db.DateTime(timezone=False))
    why_want = db.Column(db.String(length=4000), nullable=False)
    why_give = db.Column(db.String(length=4000), nullable=False)
    status = db.Column(ChoiceType(TrustedApplicationStatus, impl=db.Integer()),
                       nullable=False,
                       default=TrustedApplicationStatus.NEW)
    reviews = db.relationship('TrustedReview', backref='trusted_applications')
    submitter = db.relationship('User',
                                uselist=False,
                                lazy='joined',
                                foreign_keys=[submitter_id])

    @hybrid_property
    def is_closed(self):
        # We can't use the attribute names from TrustedApplicationStatus in an or here because of
        # SQLAlchemy jank. It'll generate the wrong query.
        return self.status > 1

    @hybrid_property
    def is_new(self):
        return self.status == TrustedApplicationStatus.NEW

    @hybrid_property
    def is_reviewed(self):
        return self.status == TrustedApplicationStatus.REVIEWED

    @hybrid_property
    def is_rejected(self):
        return self.status == TrustedApplicationStatus.REJECTED

    @property
    def created_utc_timestamp(self):
        ''' Returns a UTC POSIX timestamp, as seconds '''
        return (self.created_time - UTC_EPOCH).total_seconds()

    @classmethod
    def by_id(cls, id):
        return cls.query.get(id)
Example #5
0
 def user_id(cls):
     return db.Column(db.Integer, db.ForeignKey('users.id'))
Example #6
0
 def torrent_id(cls):
     return db.Column(db.Integer,
                      db.ForeignKey(cls._table_prefix('torrents.id'),
                                    ondelete='CASCADE'),
                      nullable=False)
Example #7
0
 def admin_id(cls):
     return db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
Example #8
0
 def user_id(cls):
     return db.Column(db.Integer,
                      db.ForeignKey('users.id', ondelete='CASCADE'))
Example #9
0
 def main_category_id(cls):
     fk = db.ForeignKey(cls._table_prefix('main_categories.id'))
     return db.Column(db.Integer, fk, primary_key=True)
Example #10
0
 def tracker_id(cls):
     fk = db.ForeignKey('trackers.id', ondelete="CASCADE")
     return db.Column(db.Integer, fk, primary_key=True)
Example #11
0
 def torrent_id(cls):
     fk = db.ForeignKey(cls._table_prefix('torrents.id'),
                        ondelete="CASCADE")
     return db.Column(db.Integer, fk, primary_key=True)
Example #12
0
 def redirect(cls):
     fk = db.ForeignKey(cls._table_prefix('torrents.id'))
     return db.Column(db.Integer, fk, nullable=True)
Example #13
0
 def main_category_id(cls):
     fk = db.ForeignKey(cls._table_prefix('main_categories.id'))
     return db.Column(db.Integer, fk, nullable=False)
Example #14
0
 def uploader_id(cls):
     # Even though this is same for both tables, declarative requires this
     return db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True)