class Page(db.Model): __tablename__ = 'page' __table_args__ = (UniqueConstraint('parent_page_id', 'url_identifier'), { 'schema': 'content' }) id = db.Column('id', db.Integer, primary_key=True, nullable=False) title = db.Column(db.String(50), nullable=False) parent_page_id = db.Column("parent_page_id", db.Integer, ForeignKey("content.page.id"), nullable=True) description = db.Column(db.Text, nullable=False) access_restricted = db.Column("access_restricted", db.Boolean, nullable=False) url_identifier = db.Column('url_identifier', db.String(50), nullable=False) page_content_elements = relationship("PageContentElement", backref="page") def __init__(self, title, description): self.title = title self.parent_page_id = None self.description = description self.access_restricted = False, self.url_identifier = ""
class Group(db.Model): __tablename__ = 'group' __table_args__ = {'schema': 'general'} id = db.Column('id', db.Integer, primary_key=True, nullable=False) name = db.Column(db.String(50), nullable=False) description = db.Column(db.Text, nullable=False) type = db.Column(db.String(50), nullable=True) sensitive = db.Column(db.Boolean(), nullable=False, default=False) __mapper_args__ = {'polymorphic_on': type}
class User(db.Model): __tablename__ = 'user' __table_args__ = {'schema': 'general'} id = db.Column('id', db.Integer, primary_key=True) firstName = db.Column(db.String(60)) lastName = db.Column(db.String(60)) email_address_id = db.Column(db.Integer, ForeignKey('mail.extern_address.id')) username = db.Column(db.String(20), unique=True) password = db.Column(db.String(60)) activated = db.Column(db.DateTime, default=None, nullable=True) content_elements = relationship("ContentElement", backref="author") def __init__(self, firstName, lastName, email_address_id, username, password=None, activated=None): self.firstName = firstName self.lastName = lastName self.email_address_id = email_address_id self.username = username if password is None: self.password = None else: self.password = bcrypt.generate_password_hash(password).decode( "utf-8") self.activated = activated def email(self): return MailingAddressExtern.query.get(self.email_address_id) def name(self): return self.firstName + " " + self.lastName @classmethod def from_registration(cls, r): u = cls(r.firstName, r.lastName, r.email, r.username) u.password = r.password return u
class Permission(db.Model): __tablename__ = "permission" __table_args__ = {"schema": "general"} id = db.Column('id', db.Integer, primary_key=True) name = db.Column(db.String(50)) def __init__(self, name): self.name = name
class MailingAddress(db.Model): __tablename__ = 'address' __table_args__ = {'schema': 'mail'} id = db.Column(db.Integer, primary_key=True) type = db.Column(db.String(50), nullable=True) __mapper_args__ = {'polymorphic_on': type} def get_address(self): raise Exception('get_address should be overridden')
class ContentElement(db.Model): __tablename__ = "content_element" __table_args__ = {"schema": "content"} id = db.Column("id", db.Integer, primary_key=True, nullable=False) type = db.Column("type", db.Enum("text", "container", "vuedle", "announcement", name="content_element_types"), nullable=False) sticky = db.Column("sticky", db.Boolean, nullable=False, default=False) title = db.Column('title', db.String(50), nullable=False, default="") identifier = db.Column("identifier", db.String(50), nullable=False, default=None) author_id = db.Column('author_id', db.Integer, ForeignKey('general.user.id'), nullable=False) page_content_elements = relationship("PageContentElement", backref="content_element") __mapper_args__ = {'polymorphic_on': type} def __init__(self, type, sticky, title, identifier, author_id): self.type = type self.sticky = sticky self.title = title self.identifier = identifier self.author_id = author_id def author(self): print("author id = {}".format(self.author_id)) if self.author_id is None: return None return users.get_user_by_id(self.author_id)
class MailingAddressExtern(MailingAddress): __tablename__ = 'extern_address' __table_args__ = {'schema': 'mail'} __mapper_args__ = {"polymorphic_identity": "extern"} id = db.Column(db.Integer, db.ForeignKey('mail.address.id'), primary_key=True) address = db.Column(db.String(150), nullable=False) def __init__(self, address): MailingAddress.__init__(self) self.address = address def get_address(self): return self.address
class MenuEntry(db.Model): __tablename__ = "menu_entry" __table_args__ = {"schema": "content"} id = db.Column("id", db.Integer, primary_key=True, nullable=False) title = db.Column("title", db.String(50), nullable=False) page_id = db.Column("page_id", db.Integer, ForeignKey('content.page.id'), nullable=False) description = db.Column("description", db.Text, nullable=False, default='') def __init__(self, title, page, description): self.title = title self.page = page self.description = description
class RevueYear(db.Model): __tablename__ = "revue_year" __table_args__ = {"schema": "general"} id = db.Column("id", db.Integer, primary_key=True, nullable=False) title = db.Column("title", db.String(50), nullable=False) year = db.Column("year", db.Integer, nullable=False) def __init__(self, title, year): self.title = title self.year = year def get_mail_affix(self): return "_{}".format(self.year) def participations(self): return YearParticipation.query.filter_by(year_id=self.id)
class MailingAddressIntern(MailingAddress): __tablename__ = 'intern' __table_args__ = {'schema': 'mail'} __mapper_args__ = {'polymorphic_identity': "intern"} id = db.Column(db.Integer, db.ForeignKey('mail.address.id'), primary_key=True) name = db.Column(db.String(50), nullable=True, unique=True) def __init__(self, name): self.name = name def get_address(self): return self.name + "@" + os.environ['EMAIL_SUFFIX'] def get_local_address(self): return self.name