class Galleries(db.Model): __tablename__ = 'galleries' index_id = db.Column(db.Integer, primary_key=True) info_id = db.Column(db.Integer, db.ForeignKey('gallery_info.gallery_id', ondelete="CASCADE"), nullable=False) image_id = db.Column(db.Integer, db.ForeignKey('images.image_id', ondelete="CASCADE"), nullable=True) gallery_image = db.relationship('Image', backref=db.backref('galleries', passive_deletes=True), foreign_keys=[image_id], lazy=True, uselist=False) gallery_info = db.relationship('Gallery_Info', passive_deletes=True, lazy=True, uselist=False) # cascade="all, delete" on gallery_info conflicts with update func def __init__(self): pass
class Client_Resources(db.Model): __tablename__ = 'client_resources' resource_id = db.Column(db.Integer, primary_key=True) content_id = db.Column(db.Integer, db.ForeignKey('headers.header_id'), nullable=True) gallery_id = db.Column(db.Integer, db.ForeignKey('gallery_info.gallery_id'), nullable=True) linked_content = db.relationship('Header', passive_deletes=True, foreign_keys=[content_id], lazy=True, uselist=False) linked_gallery = db.relationship('Gallery_Info', passive_deletes=True, foreign_keys=[gallery_id], lazy=True, uselist=False) # cascade="all, delete" on gallery_info conflicts with update func def __init__(self): pass
class Header(db.Model): __tablename__ = 'headers' header_id = db.Column(db.Integer, primary_key=True) header_text = db.Column(db.Text, nullable=False) image_id = db.Column(db.Integer, db.ForeignKey('images.image_id', ondelete="SET NULL"), nullable=True) paragraph_id = db.Column(db.Integer, db.ForeignKey('paragraphs.paragraph_id'), nullable=False) h_image = db.relationship('Image', backref=db.backref('headers', passive_deletes=True), foreign_keys=[image_id], lazy=True, uselist=False) h_paragraph = db.relationship('Paragraph', backref='header', foreign_keys=[paragraph_id], lazy=True, cascade="all, delete", uselist=False) def __init__(self, header_text): self.header_text = header_text def __repr__(self): return f'<Header {self.header_id}, {self.header_text}><Paragraph {self.h_paragraph.paragraph_id}, {self.h_paragraph.paragraph_text}><Image {self.h_image.image_id}, {self.h_image.image_name}, {self.h_image.image_link}>'
class Project(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(250), unique=True) button = db.Column(db.String(36), unique=True) background_images = db.relationship('BackgroundImage', backref='project', lazy='dynamic') fonts = db.relationship('Font', backref='project') headers = db.relationship('Header', backref='project') banners = db.relationship('Banner', backref='project')
class User(db.Model): class Gender(enum.Enum): male = 0 female = 1 class UserRole(enum.Enum): user = 0 designer = 1 admin = 2 class SocialNetwork(enum.Enum): google = 0 facebook = 1 __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) social_id = db.Column(db.String(255)) social_type = db.Column(Enum(SocialNetwork), nullable=False) first_name = db.Column(db.String(255)) last_name = db.Column(db.String(255)) gender = db.Column(Enum(Gender)) email = db.Column(db.String(255), unique=True) role = db.Column(Enum(UserRole), nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) active = db.Column(db.BOOLEAN, default=True, nullable=False) banners = db.relationship('Banner', backref='user') __table_args__ = (Index('ix_user_id_social_type', "social_type", "id"), ) def is_authenticated(self): return True def is_active(self): return self.active def is_anonymous(self): return False def is_user(self): return self.role == User.UserRole.user def is_designer(self): return self.role == User.UserRole.designer def is_admin(self): return self.role == User.UserRole.admin def get_id(self): return unicode(self.id) def __repr__(self): return '<User %r>' % self.first_name
class BannerReview(db.Model): class Status(enum.Enum): accepted = 0 not_accepted = 1 id = db.Column(db.Integer, primary_key=True) banner_id = db.Column(db.Integer, db.ForeignKey('banner.id')) comment = db.Column(db.Text, nullable=True) reviewed = db.Column(db.Boolean, default=False) status = db.Column(Enum(Status)) created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow) designer_comment = db.Column(db.Text, nullable=True) changed_at = db.Column(db.DateTime, nullable=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) designer_id = db.Column(db.Integer, db.ForeignKey('user.id')) designer_imagename = db.Column(db.String(64), unique=True) designer_previewname = db.Column(db.String(64), unique=True) active = db.Column(db.BOOLEAN, default=True, nullable=False) comment_clouds = db.Column(JSON, nullable=True) user = db.relationship("User", foreign_keys=[user_id]) designer = db.relationship("User", foreign_keys=[designer_id])
class Font(db.Model): __tablename__ = 'font' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255)) filename = db.Column(db.String(255)) project_id = db.Column(db.Integer, db.ForeignKey('project.id')) headers = db.relationship('Header', backref='font', cascade="delete") __table_args__ = (UniqueConstraint('project_id', 'name', name='project_font'), ) def url(self): return url_for('uploaded_file', filename=self.filename)
class Banner(BaseImage): user_id = db.Column(db.Integer, db.ForeignKey('user.id')) project_id = db.Column(db.Integer, db.ForeignKey('project.id')) review = db.relationship('BannerReview', backref='banner', uselist=False) history = db.relationship('ImageHistory', backref="parent")