示例#1
0
class Profile(db.Model):
    """ Model for profile """
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    birthday = db.Column(db.Date)
    political_spectrum = db.Column(db.String(256))
    political_party = db.Column(db.String(256))
    # accepted as array -> convert in init
    favourite_news_websites = db.Column(db.Text())
    allow_location_detection = db.Column(db.Boolean)
    location = db.Column(db.String(256))
    lat = db.Column(db.Float)
    lon = db.Column(db.Float)

    def __init__(self, user_id, birthday, political_spectrum, political_party,
                 favourite_news_websites, allow_location_detection, location,
                 lat, lon):
        self.user_id = user_id
        self.birthday = birthday
        self.political_spectrum = political_spectrum
        self.political_party = political_party
        # convert list to comma-separated string
        self.favourite_news_websites = ",".join(favourite_news_websites)
        self.allow_location_detection = allow_location_detection
        self.location = location
        self.lat = lat
        self.lon = lon

    def __repr__(self):
        return '<Profile %r>' % self.user_id
示例#2
0
class Category(db.Model):
    """ Model for bookmark category """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))

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

    def __repr__(self):
        return self.name
示例#3
0
class FriendRequest(db.Model):
    """ Model for profile friend requests """
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    friend_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user_accepted = db.Column(db.Boolean)
    friend_accepted = db.Column(db.Boolean)
    user_ignored = db.Column(db.Boolean)
    friend_ignored = db.Column(db.Boolean)
    created_on = db.Column(db.Date)
    accepted_on = db.Column(db.Date)

    def __init__(self, user_id, friend_id, user_accepted, friend_accepted,
                 user_ignored, friend_ignored, created_on, accepted_on):
        self.user_id = user_id
        self.friend_id = friend_id
        self.user_accepted = user_accepted
        self.friend_accepted = friend_accepted
        self.user_ignored = user_ignored
        self.friend_ignored = friend_ignored
        self.created_on = created_on
        self.accepted_on = accepted_on

    def __repr__(self):
        return '<FriendRequest %r>' % self.user_id
示例#4
0
class User(UserMixin, db.Model):
    """ Model for user """
    # id is autoincrementing number, that increases with each new record
    id = db.Column(db.Integer, primary_key=True)
    fullname = db.Column(db.String(80))
    email = db.Column(
        db.String(50),
        unique=True)  # want only one user with same email per table
    username = db.Column(
        db.String(25),
        unique=True)  # want only one user with same username per table
    password = db.Column(db.String(80))
    profile_picture = db.Column(db.String(256))
    profile_picture_upload = db.Column(db.String(256))
    cover_photo = db.Column(db.String(256))
    cover_photo_upload = db.Column(db.String(256))
    # create flag for permissions
    is_admin = db.Column(db.Boolean)

    # bookmarks relationship with user -> so that we can do bookmarks.user and get the bookmarks' user
    bookmarks = db.relationship('Bookmark', backref='user', lazy='dynamic')
    post = db.relationship('Post', backref='user', lazy='dynamic')
    comments = db.relationship('Comment', backref='user', lazy='dynamic')
    live_comments = db.relationship('LiveComment',
                                    backref='user',
                                    lazy='dynamic')

    # constructor called when class is instantiated for first time
    def __init__(self,
                 fullname,
                 email,
                 username,
                 password,
                 profile_picture,
                 profile_picture_upload,
                 cover_photo,
                 cover_photo_upload,
                 is_admin=False):
        self.fullname = fullname
        self.email = email
        self.username = username
        self.password = password
        self.profile_picture = profile_picture
        self.profile_picture_upload = profile_picture_upload
        self.cover_photo = cover_photo
        self.cover_photo_upload = cover_photo_upload
        self.is_admin = is_admin

    # representation - how do you want to display this when interacting with it in, say, the terminal?
    def __repr__(self):
        return '<User %r>' % self.username
示例#5
0
class Comment(db.Model):
    """ Model for post comment """
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    posted_on = db.Column(db.Date)
    comment = db.Column(db.Text())

    def __init__(self, post_id, user_id, posted_on, comment):
        self.post_id = post_id
        self.user_id = user_id
        self.posted_on = posted_on
        self.comment = comment

    def __repr__(self):
        return '<Comment %r>' % self.comment
示例#6
0
class LiveComment(db.Model):
    """ Model for ArticlePool comments """
    id = db.Column(db.Integer, primary_key=True)
    article_pool_id = db.Column(db.Integer, db.ForeignKey('article_pool.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    posted_on = db.Column(db.Date)
    comment = db.Column(db.Text())

    def __init__(self, article_pool_id, user_id, posted_on, comment):
        self.article_pool_id = article_pool_id
        self.user_id = user_id
        self.posted_on = posted_on
        self.comment = comment

    def __repr__(self):
        return '<Comment %r>' % self.comment
示例#7
0
class Friends(db.Model):
    """ Model for profile friends """
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    friend_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    created_on = db.Column(db.String(256))
    accepted_on = db.Column(db.Date)

    def __init__(self, user_id, friend_id, created_on, accepted_on):
        self.user_id = user_id
        self.friend_id = friend_id
        self.created_on = created_on
        self.accepted_on = accepted_on

    def __repr__(self):
        return '<Friends %r>' % self.user_id
示例#8
0
class Collection(db.Model):
    """ Model for collection of bookmarks """
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    name = db.Column(db.String(80))
    image = db.Column(db.Text(256))
    image_upload = db.Column(db.Text(256))
    category = db.Column(db.String(80))
    num_bookmarks = db.Column(db.Integer)

    # bookmark relationship
    bookmarks = db.relationship('Bookmark',
                                backref='collection',
                                lazy='dynamic')

    def __init__(self, name, user_id, num_bookmarks, image, image_upload,
                 category):
        self.name = name
        self.user_id = user_id
        self.num_bookmarks = num_bookmarks
        self.image = image
        self.image_upload = image_upload
        self.category = category

    def __repr__(self):
        return '<Library %r>' % self.name
示例#9
0
class Post(db.Model):
    """ Model for post """
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    collection_id = db.Column(db.Integer, db.ForeignKey('collection.id'))
    bookmark_id = db.Column(db.Integer, db.ForeignKey('bookmark.id'))
    url = db.Column(db.String(256))
    title = db.Column(db.String(256))
    description = db.Column(db.Text(256))
    text = db.Column(db.Text())
    image = db.Column(db.Text(256))
    tags = db.Column(db.String(256))
    published_on = db.Column(db.String(256))
    source = db.Column(db.String(256))
    post = db.Column(db.Text())
    posted_on = db.Column(db.Date)
    num_comments = db.Column(db.Integer)
    num_likes = db.Column(db.Integer)
    num_dislikes = db.Column(db.Integer)

    comments = db.relationship('Comment', backref='post', lazy='dynamic')

    def __init__(self, user_id, collection_id, bookmark_id, url, title,
                 description, text, image, tags, published_on, source, post,
                 posted_on, num_comments, num_likes, num_dislikes):
        self.user_id = user_id
        self.collection_id = collection_id
        self.bookmark_id = bookmark_id
        self.url = url
        self.title = title
        self.description = description
        self.text = text
        self.image = image
        self.tags = tags
        self.published_on = published_on
        self.source = source
        self.post = post
        self.posted_on = posted_on
        self.num_comments = num_comments
        self.num_likes = num_likes
        self.num_dislikes = num_dislikes

    def __repr__(self):
        return '<Post %r>' % self.post
示例#10
0
class ArticlePool(db.Model):
    """ Model for Browse Headlines articles"""
    id = db.Column(db.Integer, primary_key=True)
    url = db.Column(db.String(256))
    title = db.Column(db.String(256))
    description = db.Column(db.Text(256))
    text = db.Column(db.Text())
    image = db.Column(db.Text(256))
    tags = db.Column(db.String(256))
    published_on = db.Column(db.String(256))
    likes = db.Column(db.Integer)
    dislikes = db.Column(db.Integer)
    source = db.Column(db.String(256))
    slug = db.Column(db.String(256)) # slug should be unique

    live_comment = db.relationship('LiveComment', backref='article_pool', lazy='dynamic')

    def __init__(self, url, title, description, text, image, tags, published_on, likes, dislikes, source, slug):
        self.url = url
        self.title = title
        self.description = description
        self.text = text
        self.image = image
        self.tags = tags
        self.published_on = published_on
        self.likes = likes
        self.dislikes = dislikes
        self.source = source
        self.slug = slug

    def __repr__(self):
        return '<ArticlePool %r>' % self.title
示例#11
0
class Bookmark(db.Model):
    """ Model for bookmark """
    id = db.Column(db.Integer, primary_key=True)
    collection_id = db.Column(db.Integer, db.ForeignKey('collection.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    url = db.Column(db.String(256))
    title = db.Column(db.String(256))
    description = db.Column(db.Text(256))
    text = db.Column(db.Text())
    image = db.Column(db.Text(256))
    tags = db.Column(db.String(256))
    published_on = db.Column(db.String(256))
    likes = db.Column(db.Integer)
    dislikes = db.Column(db.Integer)
    source = db.Column(db.String(256))
    slug = db.Column(db.String(256), unique=True)  # slug should be unique
    created_at = db.Column(db.Date)
    category_id = db.Column(db.Integer, db.ForeignKey('category.id'))

    # category relationship
    category = db.relationship('Category',
                               backref=db.backref('bookmark', lazy='dynamic'))

    def __init__(self,
                 collection,
                 user,
                 category,
                 slug,
                 url,
                 title,
                 source,
                 published_on,
                 description=None,
                 image=None,
                 text=None,
                 tags=None):
        self.collection_id = collection.id
        self.user_id = user.id
        self.url = url
        self.title = title
        self.description = description
        self.image = image
        self.tags = tags
        self.published_on = published_on
        self.likes = 0
        self.dislikes = 0
        self.source = source
        self.slug = slug
        self.created_at = datetime.utcnow()
        self.category_id = category.id

    def __repr__(self):
        return '<Bookmark %r>' % self.title