Esempio n. 1
0
class meteor_comments(db.Model):
    # comment number is according to article api "commentLength" field
    __tablename__ = 'meteor_comments'

    id = db.Column(db.Integer, primary_key=True)
    art_id = db.Column(db.String())
    art_shortid = db.Column(db.String())
    comment_author = db.Column(db.String())
    author_gender = db.Column(db.Integer())
    comment_floor = db.Column(db.Integer())
    comment_time = db.Column(db.DateTime())
    comment_likes = db.Column(db.Integer())
    comment_content = db.Column(db.Text())
    comment_response = db.Column(db.Text())

    def __init__(self,
                 id,
                 shortid,
                 author,
                 gender,
                 floor,
                 time,
                 likes,
                 content,
                 response=""):
        self.art_id = id
        self.art_shortid = shortid
        self.comment_author = author
        self.author_gender = gender
        self.comment_floor = floor
        self.comment_time = time
        self.comment_likes = likes
        self.comment_content = content
        self.comment_response = response

    def __repr__(self):
        return str({
            'art_id': self.art_id,
            'art_shortid': self.art_shortid,
            'comment_author': self.comment_author,
            'author_gender': self.author_gender,
            'comment_floor': self.comment_floor,
            'comment_time': self.comment_time,
            'comment_likes': self.comment_likes,
            'comment_content': self.comment_content,
            'comment_response': self.comment_response
        })

    def serialize(self):
        return {
            'art_id': self.art_id,
            'art_shortid': self.art_shortid,
            'comment_author': self.comment_author,
            'author_gender': self.author_gender,
            'comment_floor': self.comment_floor,
            'comment_time': self.comment_time,
            'comment_likes': self.comment_likes,
            'comment_content': self.comment_content,
            'comment_response': self.comment_response
        }
Esempio n. 2
0
class Subscribers(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(30), nullable=False)
    date_sub = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)

    def __repr__(self):
        return f"Subscribers('{self.email}')"
Esempio n. 3
0
class Todo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    comment = db.Column(db.Text, nullable=False)
    date_created = db.Column(db.DateTime, nullable=False, default=datetime.now)
    priority = db.Column(db.String, nullable=False)
    todo_mail = db.Column(db.String, db.ForeignKey('users.mail'))

    def __repr__(self):
        return f"Todo('{self.comment}', '{self.priority}')"
Esempio n. 4
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    content = db.Column(db.Text, nullable=False)
    date_posted = db.Column(db.DateTime, nullable=False, default=datetime.now)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}'"
Esempio n. 5
0
class User(UserMixin, db.Model):
    __tablename__ = "User"
    id = db.Column('id', db.Integer, primary_key=True, nullable=False)
    login = db.Column('login', db.Unicode, nullable=False)
    password = db.Column('password', db.Unicode, nullable=False)
    name = db.Column('name', db.Unicode, nullable=False)
    lastname = db.Column('lastname', db.Unicode, nullable=False)

    def __repr__(self):
        return f"User('{self.id}','{self.login}','{self.password}','{self.name}','{self.lastname}')"
class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    email = db.Column(db.String(120), index=True, unique=True)
    password_hash = db.Column(db.String(128))
    posts = db.relationship('Post', backref='author')

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)
Esempio n. 7
0
class meteor_articles(db.Model):
    __tablename__ = 'meteor_articles'

    id = db.Column(db.Integer, primary_key=True)
    art_id = db.Column(db.String())  # <= id
    art_shortid = db.Column(db.String())  # <= shortId, also url
    author_gender = db.Column(
        db.Integer())  # <= (authorGender=='female')? 0 : 1
    art_author = db.Column(db.String())  # <= authorAlias
    art_school = db.Column(db.String())  # <= authorSchoolName
    art_time = db.Column(db.DateTime())  # <= createdAt
    art_likes = db.Column(db.Integer())  # <= starLength
    art_title = db.Column(db.String())  # <= title
    art_content = db.Column(db.Text())  # <= content

    def __init__(self, id, shortid, gender, author, school, time, likes, title,
                 content):
        self.art_id = id
        self.art_shortid = shortid
        self.author_gender = gender
        self.art_author = author
        self.art_school = school
        self.art_time = time
        self.art_likes = likes
        self.art_title = title
        self.art_content = content

    def __repr__(self):
        return str({
            'art_id': self.art_id,
            'art_shortid': self.art_shortid,
            'author_gender': self.author_gender,
            'art_author': self.art_author,
            'art_school': self.art_school,
            'art_time': self.art_time,
            'art_likes': self.art_likes,
            'art_title': self.art_title,
            'art_content': self.art_content
        })

    def serialize(self):
        return {
            'art_id': self.art_id,
            'art_shortid': self.art_shortid,
            'author_gender': self.author_gender,
            'art_author': self.art_author,
            'art_school': self.art_school,
            'art_time': self.art_time,
            'art_likes': self.art_likes,
            'art_title': self.art_title,
            'art_content': self.art_content
        }
Esempio n. 8
0
class Song(db.Model):
    __tablename__ = 'songs'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(50), nullable=False)
    album_id = db.Column(db.Integer,
                         db.ForeignKey('albums.id'),
                         nullable=False)
    artist_id = db.Column(db.Integer,
                          db.ForeignKey('artists.id'),
                          nullable=False)
    file = db.relationship('File', backref='song', lazy=True)

    def __repr__(self):
        return f"Song('{self.title}','{self.album}', '{self.artist}', '{self.file}')"
Esempio n. 9
0
class Keyword(db.Model):
    __tablename__ = 'keyword'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), nullable=False)

    images = relationship('Image',
                          secondary=image_keyword_association_table,
                          back_populates='keywords')

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

    def toJSON(self):
        return {'name': self.name}