Exemple #1
0
class Art(db.Model):
    """Art table.

    Required fields:
        title(String, 128)
    Optional fields:
        image(String, 128)      -> relative to static/uploads/
        thumbnail(String, 128)  -> relative to static/thumbnail/
        user_id(Integer)
        pubdate(DateTime)
        description(Text)       -> indexable
        tags(String, 256)       -> space separated
        category(Integer)       -> must point to a valid category
        nsfw(Integer)           -> must be between 0:none, 1:mild, 2:explicit
        license(Integer)
    """
    __searchable__ = ['title', 'description', 'tags']
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(128), nullable=False)
    # image is a static image link
    image = db.Column(db.String(128), nullable=False, default='art.jpg')
    # thumbnail is a static image link, default='default.jpg'
    thumbnail = db.Column(db.String(128), nullable=False, default='thumb.jpg')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    pubdate = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    description = db.Column(db.Text, nullable=False, default='')
    tags = db.Column(db.String(256), nullable=False, default='')
    category = db.Column(db.Integer, nullable=False, default=0)
    nsfw = db.Column(db.Integer, nullable=False, default=0)
    license = db.Column(db.Integer, nullable=False, default=0)

    def __repr__(self):
        return f"Art('{self.title}', '{self.image}', cat:{self.category})"
Exemple #2
0
class CollectionData(db.Model):
    """Collections data table.

    This contains art IDs and the collections they belong to.
    The `collection_id` points to collection info located in
    CollectionMeta. The favorites table is also a collection.

    Required fields:
        art_id(Integer)
        collection_id(Integer)
    """
    id = db.Column(db.Integer, primary_key=True)
    art_id = db.Column(db.Integer, db.ForeignKey('art.id'), nullable=False)
    collection_id = db.Column(db.Integer,
                              db.ForeignKey('collection_meta.id'),
                              nullable=False)

    def __repr__(self):
        return f"CollectionData({self.art_id} in {self.collection_id})"
Exemple #3
0
class Comment(db.Model):
    """Comment table.

    Required fields:
        user_id(Integer)
        reply_to(Integer)
        text(Text)
        depth(Integer)
        art_id(Integer)
    Automatic fields:
        id(Integer)
        time(DateTime)
    """
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    art_id = db.Column(db.Integer, db.ForeignKey('art.id'), nullable=False)
    reply_to = db.Column(db.Integer, nullable=False, default=0)
    depth = db.Column(db.Integer, default=0)
    text = db.Column(db.Text, nullable=False, default='')
    time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

    def __repr__(self):
        return f"Comment({self.id}, by: '{self.user_id}')"
Exemple #4
0
class View(db.Model):
    """Post view table.

    Although there's a dedicated view column on the art table and this is
    bound to be a disaster pretty quickly, it tracks date and time at least.

    Required fields:
        art_id(Integer)
    """
    id = db.Column(db.Integer, primary_key=True)
    art_id = db.Column(db.Integer, db.ForeignKey('art.id'), nullable=False)
    time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

    def __repr__(self):
        return f"View({self.art_id} at {self.time})"
Exemple #5
0
class CollectionMeta(db.Model):
    """Collections meta/info table.

    This contains the information for a collection, like the
    title and description of the collection. This also contains
    who owns the collection.

    Required fields:
        title(String, 128)
        user_id(Integer)
        use_as_favorites(Boolean) -> whether or not to use as the collection
                                    used when the user favorites something
    Optional fields:
        description(Text)
    """
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(128), nullable=False, default='')
    description = db.Column(db.Text, nullable=False, default='')
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    use_as_favorites = db.Column(db.Boolean, default=0)

    def __repr__(self):
        return f"CollectionMeta({self.id}, '{self.title}' belongs to {self.user_id})"