Example #1
0
class Comment(TimestampMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.String(1000))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))

    def __repr__(self):
        return f'<Comment {self.body}>'
Example #2
0
class Comment(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    create_at = db.Column(db.DateTime, default=datetime.now)
    body = db.Column(db.Text, nullable=False)
    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 f'<Comment body>'
Example #3
0
class Comment(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text, nullable=False)
    time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Post( '{self.mainpost.id}','{self.time}' )"
Example #4
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    preview = db.Column(db.UnicodeText, nullable=False)
    content = db.Column(db.UnicodeText, nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    image_id = db.Column(db.Integer, db.ForeignKey('image.id'), nullable=True)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
Example #5
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255), nullable=False)
    body = db.Column(db.Text, nullable=False)
    slug = db.Column(db.String(255), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.now)
    last_modified = db.Column(db.DateTime,
                              default=datetime.now,
                              onupdate=datetime.now)
    tags = db.relationship("Tag",
                           secondary=posts_tags,
                           backref="posts",
                           lazy="dynamic")

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

    def generate_slug(self):
        self.slug = ''
        if self.title:
            self.slug = slugtify(self.title)

    def __init__(self, *args, **kwargs):
        super(Post, self).__init__(*args, **kwargs)
        self.generate_slug()

    def __repr__(self):
        return f'<Post {self.title}>'
Example #6
0
class posts(db.Model):
    date=date.today()
    id=db.Column(db.Integer,primary_key=True)
    title=db.Column(db.Text,nullable=False)
    content=db.Column(db.Text,nullable=False)
    date_posted=db.Column(db.DateTime,nullable=False,default=date)
    picture=db.Column(db.String(120),nullable=False,default='default.jpg')
    user_id=db.Column(db.Integer,db.ForeignKey('user.id'),nullable=True)
    def __repr__(self):
        return f"user('{self.title}','{self.date_posted}'),{self.picture}')"
Example #7
0
class Article(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    data_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('user.id'), nullable=False)

    def __repr__(self):
        return f"Article('{self.title}','{self.data_posted}')"
Example #8
0
class Post(TimestampMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(120))
    body = db.Column(db.String(1000))
    private = db.Column(db.Boolean, default=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    comments = db.relationship('Comment',
                               backref='original_post',
                               lazy='dynamic')

    def __repr__(self):
        return f'<Post {self.body}>'
Example #9
0
class Tore(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    date_posted = db.Column(db.DATETIME,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    username = db.Column(db.String(20), nullable=False)
    reply_id = db.Column(db.Integer, db.ForeignKey('reply.id'), nullable=False)

    def __repr__(self):
        return f"ReplyTo('{self.content}','{self.date_posted}','{self.reply_id}')"
Example #10
0
class Post(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.Text, nullable=False)
    smallcontent = db.Column(db.Text, nullable=False)
    title = db.Column(db.String(100), nullable=False)
    time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    likes = db.Column(db.Integer, nullable=False,default=0)

    comments = db.relationship('Comment', backref='mainpost', lazy=True)

    def __repr__(self):
        return f"Post( '{self.title}','{self.time}' )"
Example #11
0
class Project(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    data_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('user.id'), nullable=False)
    replies = db.relationship('Reply', backref='project', lazy=True)

    def __repr__(self):
        return f"Project('{self.title}','{self.data_posted},,'{self.user_id}')"
Example #12
0
class Reply(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    date_posted = db.Column(db.DATETIME,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    username = db.Column(db.String(20), nullable=False)
    project_id = db.Column(db.Integer,
                           db.ForeignKey('project.id'),
                           nullable=False)
    repliesto = db.relationship('Tore', backref='replies', lazy=True)

    def __repr__(self):
        return f"Reply('{self.content}','{self.date_posted}','{self.project_id},{self.username}')"
Example #13
0
class BlogEntry(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), unique=True, nullable=False)
    # url friendly version of title
    slug = db.Column(db.String(200), unique=True, nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    date_updated = db.Column(db.DateTime,
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    is_published = db.Column(db.Boolean, nullable=False, default=True)
    tags = db.relationship('Tag',
                           secondary=entry_tag,
                           backref='entries',
                           lazy=True)

    def __init__(self, *args, **kargs):
        super().__init__(*args, **kargs)
        self.slug = slugify(self.title)

    def __repr__(self):
        return f"BlogEntry('{self.title}', '{self.date_posted}')"

    @property
    def markdown_content(self):
        '''
        Convert markdown content into html
        '''

        hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
        extras = ExtraExtension()

        markdown_content = markdown(self.content, extensions=[hilite, extras])

        return Markup(markdown_content)

    @property
    def preview_content(self):
        '''
        grab the first image and first two paragraphs of a markdown content 
        '''
        soup = BeautifulSoup(self.markdown_content, 'html.parser')
        return [Markup(p) for p in soup.find_all('p')[:2]]
Example #14
0
class BlogPost(db.Model):

    users = db.relationship(User)

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)

    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    title = db.Column(db.String(140), nullable=False)
    text = db.Column(db.Text, nullable=False)

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

    def __repr__(self):
        return f"Post ID: {self.id} -- Date: {self.date} --- {self.title}"
Example #15
0
# -*- coding: utf-8 -*-
# Copyright (c) 2013 Juha Kellokoski

from datetime import datetime
from flask.ext.login import UserMixin
from myblog import db, app

tags = db.Table('tags', db.Column('tag_id', db.Integer,
                                  db.ForeignKey('tag.id')),
                db.Column('post_id', db.Integer, db.ForeignKey('post.id')))


class User(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, unique=True)
    password = db.Column(db.String(16))

    def __init__(self, username, password):
        self.username = username
        self.password = password

    def is_active(self):
        return True

    def is_authenticated(self):
        return True

    def is_anonymous(self):
        return False
Example #16
0
from markdown.extensions.codehilite import CodeHiliteExtension
from markdown.extensions.extra import ExtraExtension
from bs4 import BeautifulSoup


@login_manager.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))


def slugify(entry_title):
    return entry_title.replace(' ', '-').lower()


entry_tag = db.Table(
    'entry_tag', db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')),
    db.Column('entry_id', db.Integer, db.ForeignKey('blog_entry.id')))


class BlogEntry(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(200), unique=True, nullable=False)
    # url friendly version of title
    slug = db.Column(db.String(200), unique=True, nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    date_updated = db.Column(db.DateTime,
                             default=datetime.utcnow,
                             onupdate=datetime.utcnow)