Example #1
0
class KeywordLinks(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.Integer,
                        db.ForeignKey('posts.id', ondelete="CASCADE"),
                        nullable=False)
    keyword_id = db.Column(db.Integer,
                           db.ForeignKey('keywords.id', ondelete="CASCADE"),
                           nullable=False)
Example #2
0
class Subscriptions(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    post_id = db.Column(db.Integer,
                        db.ForeignKey('posts.id', ondelete="CASCADE"),
                        nullable=False)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', ondelete="CASCADE"),
                        nullable=False)
    follows_since = db.Column(db.DateTime,
                              nullable=False,
                              default=datetime.utcnow)
Example #3
0
class Links(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    platform = db.Column(db.String(50), nullable=False)
    link = db.Column(db.String(50), nullable=False)
    post_id = db.Column(db.Integer,
                        db.ForeignKey('posts.id', ondelete="CASCADE"),
                        nullable=False)
Example #4
0
class Images(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    stage = db.Column(db.Integer, nullable=False, default=0)
    filename = db.Column(db.String(100), default='default.jpg')
    post_id = db.Column(db.Integer,
                        db.ForeignKey('posts.id', ondelete="CASCADE"),
                        nullable=False)
Example #5
0
class Waves(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text, nullable=True)
    post_id = db.Column(db.Integer,
                        db.ForeignKey('posts.id', ondelete="CASCADE"),
                        nullable=False)
    stage = db.Column(db.Integer, nullable=False, default=0)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', ondelete="CASCADE"),
                        nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    notifications = db.relationship('Notifications',
                                    backref='wave',
                                    lazy=True,
                                    cascade="all, delete",
                                    passive_deletes=True)
Example #6
0
class Replies(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text, nullable=False)
    comment_id = db.Column(db.Integer,
                           db.ForeignKey('comments.id', ondelete="CASCADE"),
                           nullable=False)
    post_id = db.Column(db.Integer,
                        db.ForeignKey('posts.id', ondelete="CASCADE"),
                        nullable=False)
    stage = db.Column(db.Integer, nullable=False, default=0)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', ondelete="CASCADE"),
                        nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    tag_id = db.Column(db.Integer,
                       db.ForeignKey('tags.id', ondelete="CASCADE"),
                       nullable=False)
Example #7
0
class Tides(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(250), nullable=False)
    content = db.Column(db.Text, nullable=False)
    banner_file = db.Column(db.String(100), nullable=True)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    post_id = db.Column(db.Integer,
                        db.ForeignKey('posts.id', ondelete="CASCADE"),
                        nullable=False)
    stage = db.Column(db.Integer, nullable=False, default=1)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', ondelete="CASCADE"),
                        nullable=False)
    tag_id = db.Column(db.Integer,
                       db.ForeignKey('tags.id', ondelete="CASCADE"),
                       nullable=False,
                       default=1)
Example #8
0
class Notifications(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', ondelete="CASCADE"),
                        nullable=False)
    post_id = db.Column(db.Integer,
                        db.ForeignKey('posts.id', ondelete="CASCADE"),
                        nullable=False)
    wave_id = db.Column(db.Integer,
                        db.ForeignKey('waves.id', ondelete="CASCADE"),
                        nullable=True)
    stage = db.Column(db.Integer, nullable=False, default=0)
    event = db.Column(db.String(15), nullable=False)
    content = db.Column(db.String(250), nullable=True)
    seen = db.Column(db.Integer, nullable=False, default=0)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)

    def __repr__(self):
        return f"Notification on('{self.post.title}', '{self.user.username}')"
Example #9
0
class Posts(db.Model):
    #msearch settings
    __tablename__ = 'posts'
    __searchable__ = ['title', 'description', 'content']
    __msearch_schema__ = {
        "title":
        TEXT(stored=True,
             analyzer=RegexTokenizer() | CaseSensitivizer(),
             sortable=False),
        "content":
        TEXT(
            stored=True,
            analyzer=RegexTokenizer(),
            sortable=False,
        )
    }

    id = db.Column(db.Integer, primary_key=True)
    stage = db.Column(db.Integer, nullable=False, default=0)
    title = db.Column(db.String(250), unique=True, nullable=False)
    description = db.Column(db.String(100), nullable=True)
    link = db.Column(db.String(100), nullable=True)
    logo_file = db.Column(db.String(100), default='default.jpg')
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', ondelete="CASCADE"),
                        nullable=False)
    tag_id = db.Column(db.Integer,
                       db.ForeignKey('tags.id', ondelete="CASCADE"),
                       nullable=False,
                       default=1)
    tides = db.relationship('Tides',
                            backref='post',
                            lazy=True,
                            cascade="all, delete",
                            passive_deletes=True)
    waves = db.relationship('Waves',
                            backref='post',
                            lazy=True,
                            cascade="all, delete",
                            passive_deletes=True)
    comments = db.relationship('Comments',
                               backref='post',
                               lazy=True,
                               cascade="all, delete",
                               passive_deletes=True)
    replies = db.relationship('Replies',
                              backref='post',
                              lazy=True,
                              cascade="all, delete",
                              passive_deletes=True)
    subscribers = db.relationship('Subscriptions',
                                  backref='post',
                                  lazy=True,
                                  cascade="all, delete",
                                  passive_deletes=True)
    notifications = db.relationship('Notifications',
                                    backref='post',
                                    lazy=True,
                                    cascade="all, delete",
                                    passive_deletes=True)
    images = db.relationship('Images',
                             backref='post',
                             lazy=True,
                             cascade="all, delete",
                             passive_deletes=True)
    links = db.relationship('Links',
                            backref='post',
                            lazy=True,
                            cascade="all, delete",
                            passive_deletes=True)
    keywords = db.relationship('KeywordLinks',
                               backref='post',
                               lazy=True,
                               cascade="all, delete",
                               passive_deletes=True)

    # extraction methods used in jinja rendering and the serializer below
    def follownum(self):  #subscribers
        followers = Subscriptions.query.filter_by(post_id=self.id).all()
        return len(followers)

    def commentnum(
            self
    ):  #combined number of comments and replies to all project stages
        comments = Comments.query.filter_by(post_id=self.id).all()
        replies = Replies.query.filter_by(post_id=self.id).all()
        return len(comments) + len(replies)

    def get_tag(self):
        tag = Tags.query.filter_by(id=self.tag_id).first()
        return tag.tag

    #custom JSON serializer, this one is used for the homepage infinite scrolling feed
    @property
    def serialize(self):
        return {
            'title': self.title,
            'content': self.description,
            'comments': self.commentnum(),
            'subs': self.follownum(),
            'stage': self.stage,
            'logo': self.logo_file,
            'tag': self.get_tag(),
            'date_posted': moment.create(self.date_posted).fromNow()
        }