Ejemplo n.º 1
0
class Comment(db.Model):
    __tablename__ = 'comments'
    id = db.Column(db.Integer, primary_key=True)
    text = db.Column(db.String(COMMENT.COMMENT_LENGTH))
    rating = db.Column(db.Integer)
    created_at = db.Column(db.DateTime)
    updated_at = db.Column(db.DateTime)
    post_id = db.Column(db.Integer, db.ForeignKey('posts.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
Ejemplo n.º 2
0
 def setUp(self):
     self.db_fd, self.db_path = tempfile.mkstemp()
     APP.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + self.db_path
     APP.config['TESTING'] = True
     APP.config['WTF_CSRF_ENABLED'] = False
     self.app = APP.test_client()
     with APP.app_context():
         #print('Initializing database...')
         DB.create_all()
Ejemplo n.º 3
0
class Channel(db.Model):
    __tablename__ = 'channels'
    id = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.DateTime)
    updated_at = db.Column(db.DateTime)
    name = db.Column(db.String(50), unique=True)
    description = db.Column(db.String(250))
    subscribers = db.relationship('Subscription', backref='channel')
    posts = db.relationship('Post', backref='channel')
Ejemplo n.º 4
0
class Subscription(db.Model):
    __tablename__ = 'subscriptions'
    id = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.DateTime)
    updated_at = db.Column(db.DateTime)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    channel_id = db.Column(db.Integer, db.ForeignKey('channels.id'))
Ejemplo n.º 5
0
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.DateTime)
    updated_at = db.Column(db.DateTime)
    name = db.Column(db.String(50), unique=True)
    email = db.Column(db.String(120), unique=True)
    password = db.Column(db.String(120))
    _role = db.Column(db.SmallInteger, default=USER.USER)
    status = db.Column(db.SmallInteger, default=USER.NEW)
    # clients = db.relationship('Client', backref='user')
    # grants = db.relationship('Grant', backref='user')
    # tokens = db.relationship('Token', backref='user')
    subscriptions = db.relationship('Subscription', backref='user')
    posts = db.relationship('Post', backref='user')
    comments = db.relationship('Comment', backref='user')
    friends = db.relationship('User',
                              secondary=friends,
                              primaryjoin=(id == friends.c.user_id),
                              secondaryjoin=(id == friends.c.friend_id))

    def get_status(self):
        return USER.STATUS[self.status]

    def get_role(self):
        return USER.ROLE[self._role]

    def check_password(self, password):
        return self.password == password
Ejemplo n.º 6
0
from bump import DB as db
from bump.users import constants as USER

friends = db.Table(
    'friends',
    db.Column('user_id', db.Integer, db.ForeignKey('users.id'), index=True),
    db.Column('friend_id', db.Integer, db.ForeignKey('users.id')))


class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.DateTime)
    updated_at = db.Column(db.DateTime)
    name = db.Column(db.String(50), unique=True)
    email = db.Column(db.String(120), unique=True)
    password = db.Column(db.String(120))
    _role = db.Column(db.SmallInteger, default=USER.USER)
    status = db.Column(db.SmallInteger, default=USER.NEW)
    # clients = db.relationship('Client', backref='user')
    # grants = db.relationship('Grant', backref='user')
    # tokens = db.relationship('Token', backref='user')
    subscriptions = db.relationship('Subscription', backref='user')
    posts = db.relationship('Post', backref='user')
    comments = db.relationship('Comment', backref='user')
    friends = db.relationship('User',
                              secondary=friends,
                              primaryjoin=(id == friends.c.user_id),
                              secondaryjoin=(id == friends.c.friend_id))

    def get_status(self):
Ejemplo n.º 7
0
class Client(db.Model):
    __tablename__ = 'clients'
    id = db.Column(db.String(40), primary_key=True)
    secret = db.Column(db.String(55), unique=True, index=True, nullable=False)
    name = db.Column(db.String(40))
    is_confidential = db.Column(db.Boolean)
    _redirect_uris = db.Column(db.Text)
    _default_scopes = db.Column(db.Text)
    user_id = db.Column(db.ForeignKey('users.id'))
    grants = db.relationship('Grant', backref='client')
    tokens = db.relationship('Token', backref='client')

    @property
    def client_type(self):
        if self.is_confidential:
            return 'confidential'
        return 'public'

    @property
    def redirect_uris(self):
        if self._redirect_uris:
            return self._redirect_uris.split()
        return []

    @property
    def default_redirect_uri(self):
        return self.redirect_uris[0]

    @property
    def default_scopes(self):
        if self._default_scopes:
            return self._default_scopes.split()
        return []

    @property
    def allowed_grant_types(self):
        return [
            'authorization_code', 'password', 'client_credentials',
            'refresh_token'
        ]
Ejemplo n.º 8
0
class Post(db.Model):
    __tablename__ = 'posts'
    id = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.DateTime)
    updated_at = db.Column(db.DateTime)
    link = db.Column(db.String)
    text = db.Column(db.String(POST.TEXT_LENGTH))
    rating = db.Column(db.Integer)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    channel_id = db.Column(db.Integer, db.ForeignKey('channels.id'))
    comments = db.relationship('Comment', backref='post')
Ejemplo n.º 9
0
def initdb():
    print('Initializing database...')
    DB.create_all()
    print('Initialized the database.')
    print('Location: {path}'.format(
        path=APP.config['SQLALCHEMY_DATABASE_URI']))
Ejemplo n.º 10
0
class Grant(db.Model):
    __tablename__ = 'grants'
    id = db.Column(db.Integer, primary_key=True)
    code = db.Column(db.String(255), index=True, nullable=False)
    redirect_uri = db.Column(db.String(255))
    expires = db.Column(db.DateTime)
    _scopes = db.Column(db.Text)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', ondelete='CASCADE'))
    client_id = db.Column(db.String(40),
                          db.ForeignKey('clients.id'),
                          nullable=False)

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

    @property
    def scopes(self):
        if self._scopes:
            return self._scopes.split()
        return []