Esempio n. 1
0
class YearGroup(Group):
    __tablename__ = "year_group"
    __table_args__ = {"schema": "general"}
    year_group_id = db.Column("id",
                              db.Integer,
                              ForeignKey('general.group.id'),
                              primary_key=True,
                              nullable=False)
    parent_year_group_id = db.Column("parent_year_group_id",
                                     db.Integer,
                                     ForeignKey("general.year_group.id"),
                                     nullable=True)
    __mapper_args__ = {"polymorphic_identity": "year_group"}

    def mailing_list(self):
        return revue.models.mail.YearGroupMailingList.query.filter_by(
            year_group_id=self.year_group_id).one_or_none()

    def members(self, revue_year):
        year_participation_ids = [x.id for x in revue_year.participations()]
        year_group_participations = YearGroupParticipation.query.filter(
            and_(
                YearGroupParticipation.year_participation_id.in_(
                    year_participation_ids),
                YearGroupParticipation.year_group_id == self.id)).all()
        return [
            revue.models.general.User.query.get(
                ygp.year_participation().user_id)
            for ygp in year_group_participations
        ]
Esempio n. 2
0
class YearGroupMailingList(MailingAddressIntern):
    __tablename__ = 'year_group_list'
    __table_args__ = {'schema': 'mail'}
    __mapper_args__ = {"polymorphic_identity": "year_group_list"}
    id = db.Column(db.Integer,
                   db.ForeignKey('mail.intern.id'),
                   primary_key=True)
    year_group_id = db.Column(db.Integer,
                              db.ForeignKey('general.year_group.id'),
                              primary_key=True,
                              unique=True)

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

    def entries(self, revue_year):
        yg = YearGroup.query.get(self.year_group_id)
        return [u.email() for u in yg.members(revue_year)]

    def get_local_address_year(self, revue_year):
        return self.get_local_address() + revue_year.get_mail_affix()

    def get_entries_per_year(self):
        result = []
        for y in revue.models.general.RevueYear.query.all():
            result.append({"year": y, "entries": self.entries(y)})
        return result
Esempio n. 3
0
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
Esempio n. 4
0
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')
Esempio n. 5
0
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}
Esempio n. 6
0
class UserPermission(db.Model):
    __tablename__ = "user_permission"
    __table_args__ = (PrimaryKeyConstraint("user_id", "permission_id"), {
        "schema": "general"
    })
    user_id = db.Column(db.Integer, ForeignKey('general.user.id'))
    permission_id = db.Column(db.Integer, ForeignKey('general.permission.id'))

    def __init__(self, user_id, permission_id):
        self.user_id = user_id
        self.permission_id = permission_id
Esempio n. 7
0
class MailingAlias(MailingAddressIntern):
    __tablename__ = 'alias'
    __table_args__ = {'schema': 'mail'}
    __mapper_args__ = {"polymorphic_identity": "alias"}
    id = db.Column(db.Integer,
                   db.ForeignKey('mail.intern.id'),
                   primary_key=True)
    other_address_id = db.Column(db.Integer,
                                 db.ForeignKey('mail.address.id'),
                                 nullable=True)

    def other_address(self):
        return MailingAddress.query.get(self.other_address_id)
class YearGroupYearPage(Page):
    __tablename__ = "year_group_year_page"
    __table_args__ = (PrimaryKeyConstraint('year_group_id', 'year_id'), {"schema": "content"})

    year_group_id = db.Column("year_group_id", db.Integer, ForeignKey('general.year_group.id'),
                              nullable=False)
    year_id = db.Column("year_id", db.Integer, ForeignKey("general.revue_year.id"), nullable=False)
    page_id = db.Column("page_id", db.Integer, ForeignKey('content.page.id'), nullable=False)

    def __init__(self, year_group, revue_year):
        Page.__init__(self, "{} - {}".format(year_group.name, revue_year.year),
              "{}'s page for {}".format(year_group.name, revue_year.year))
        self.year_group_id = year_group.id
        self.year_id = revue_year.id
Esempio n. 9
0
class TextElement(ContentElement):
    __tablename__ = "text_element"
    __table_args__ = {"schema": "content"}

    text_element_id = db.Column("id",
                                db.Integer,
                                ForeignKey('content.content_element.id'),
                                primary_key=True,
                                nullable=False)
    content = db.Column("content", db.Text, nullable=False)

    __mapper_args__ = {"polymorphic_identity": "text"}

    def __init__(self, content):
        self.content = content
Esempio n. 10
0
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
Esempio n. 11
0
class MailingListEntry(db.Model):
    __tablename__ = 'list_entry'
    __table_args__ = {'schema': 'mail'}
    id = db.Column(db.Integer, primary_key=True, nullable=False)
    list_id = db.Column(db.Integer, ForeignKey('mail.list.id'), nullable=False)
    address_id = db.Column(db.Integer,
                           ForeignKey('mail.address.id'),
                           nullable=False)

    def get_address(self):
        return MailingAddress.query.get(self.address_id).get_address()

    def __init__(self, list_id, address_id):
        db.Model.__init__(self)
        self.list_id = list_id
        self.address_id = address_id
Esempio n. 12
0
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
Esempio n. 13
0
class GroupMenu(db.Model):
    __tablename__ = "group_menu"
    __table_args__ = {"schema": "content"}

    menu_entry_id = db.Column('menu_entry',
                              db.Integer,
                              ForeignKey('content.menu_entry.id'),
                              nullable=False)
    group_id = db.Column('group_id',
                         db.Integer,
                         ForeignKey('general.group.id'),
                         primary_key=True)

    def __init__(self, menu_entry_id, group_id):
        self.menu_entry_id = menu_entry_id
        self.group_id = group_id
Esempio n. 14
0
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)
Esempio n. 15
0
class MailingAddressLocal(MailingAddress):
    # TODO: let inherit from Internal!
    __tablename__ = 'local_address'
    __table_args__ = {'schema': 'mail'}
    __mapper_args__ = {"polymorphic_identity": "local"}
    id = db.Column(db.Integer,
                   db.ForeignKey('mail.address.id'),
                   primary_key=True)
Esempio n. 16
0
class PersistentGroupParticipation(db.Model):
    __tablename__ = "persistent_group_participation"
    __table_args__ = (PrimaryKeyConstraint("persistent_group_id", "user_id"), {
        "schema": "general"
    })
    group_id = db.Column("persistent_group_id",
                         db.Integer,
                         ForeignKey("general.group.id"),
                         nullable=False)
    user_id = db.Column("user_id",
                        db.Integer,
                        ForeignKey("general.user.id"),
                        nullable=False)

    def __init__(self, persistent_group_id, user_id):
        self.group_id = persistent_group_id
        self.user_id = user_id
Esempio n. 17
0
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
Esempio n. 18
0
class MenuEntryRelationship(db.Model):
    __tablename__ = "menu_entry_relationship"
    __table_args__ = (PrimaryKeyConstraint('parent_id', 'child_id'), {
        "schema": "content"
    })

    child_id = db.Column('child_id',
                         db.Integer,
                         ForeignKey('content.menu_entry.id'),
                         nullable=False)
    parent_id = db.Column('parent_id',
                          db.Integer,
                          ForeignKey('content.menu_entry.id'),
                          nullable=False)

    def __init__(self, parent_id, child_id):
        self.child_id = child_id
        self.parent_id = parent_id
Esempio n. 19
0
class YearParticipation(YearParticipationRequest):
    __tablename__ = "year_participation"
    __table_args__ = {"schema": "general"}
    participation_id = db.Column(
        "id",
        db.Integer,
        ForeignKey("general.year_participation_request.id"),
        nullable=False,
        primary_key=True)
Esempio n. 20
0
class MailingList(MailingAddressIntern):
    __tablename__ = 'list'
    __table_args__ = {'schema': 'mail'}
    __mapper_args__ = {"polymorphic_identity": "list"}
    id = db.Column(db.Integer,
                   db.ForeignKey('mail.intern.id'),
                   primary_key=True)
    entries = relationship("MailingListEntry", backref="list")

    def __init__(self, name):
        MailingAddressIntern.__init__(self, name)
Esempio n. 21
0
class PersistentGroupMailingList(MailingAddressIntern):
    __tablename__ = 'persistent_group_list'
    __table_args__ = {'schema': 'mail'}
    __mapper_args__ = {"polymorphic_identity": "persistent_group_list"}
    id = db.Column(db.Integer,
                   db.ForeignKey('mail.intern.id'),
                   primary_key=True)
    persistent_group_id = db.Column(
        db.Integer,
        db.ForeignKey('general.persistent_group.id'),
        nullable=False,
        unique=True)

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

    def entries(self):
        pg = PersistentGroup.query.get(self.persistent_group_id)
        return [u.email() for u in pg.members()]
Esempio n. 22
0
class YearParticipationRequest(db.Model):
    __tablename__ = "year_participation_request"
    __table_args__ = (db.UniqueConstraint('year_id', 'user_id'), {
        "schema": "general"
    })
    id = db.Column("id", db.Integer, primary_key=True, nullable=False)
    year_id = db.Column("year_id",
                        db.Integer,
                        ForeignKey("general.revue_year.id"),
                        nullable=False)
    user_id = db.Column("user_id",
                        db.Integer,
                        ForeignKey("general.user.id"),
                        nullable=False)

    def __init__(self, year_id, user_id):
        self.year_id = year_id
        self.user_id = user_id

    def user(self):
        return revue.models.general.User.query.get(self.user_id)
Esempio n. 23
0
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 = ""
Esempio n. 24
0
class YearGroupParticipation(db.Model):
    __tablename__ = "year_group_participation"
    __table_args__ = (PrimaryKeyConstraint("year_group_id",
                                           "year_participation_id"), {
                                               "schema": "general"
                                           })
    year_group_id = db.Column("year_group_id",
                              db.Integer,
                              ForeignKey("general.year_group.id"),
                              nullable=False)
    year_participation_id = db.Column(
        "year_participation_id",
        db.Integer,
        ForeignKey("general.year_participation.id"),
        nullable=False)

    def __init__(self, year_participation_id, year_group_id):
        self.year_participation_id = year_participation_id
        self.year_group_id = year_group_id

    def year_participation(self):
        return YearParticipation.query.get(self.year_participation_id)
Esempio n. 25
0
class PageContentElement(db.Model):
    __tablename__ = "page_content_element"
    __table_args__ = (PrimaryKeyConstraint('content_element_id', 'page_id'), {
        "schema": "content"
    })

    content_element_id = db.Column("content_element_id",
                                   db.Integer,
                                   ForeignKey('content.content_element.id'),
                                   nullable=False)
    page_id = db.Column("page_id",
                        db.Integer,
                        ForeignKey('content.page.id'),
                        nullable=False)
    order_index = db.Column("order_index",
                            db.Integer,
                            nullable=False,
                            default=0)

    def __init__(self, content_element_id, page_id, order_index):
        self.content_element_id = content_element_id
        self.page_id = page_id
        self.order_index = order_index
Esempio n. 26
0
class PageAccessRestriction(db.Model):
    __tablename__ = "page_access_restriction"
    __table_args__ = (PrimaryKeyConstraint("page_id", "year_group_id",
                                           "revue_year_id"), {
                                               "schema": "content"
                                           })
    page_id = db.Column("page_id",
                        db.Integer,
                        ForeignKey("content.page.id"),
                        nullable=False)
    year_group_id = db.Column("year_group_id",
                              db.Integer,
                              ForeignKey("general.year_group.id"),
                              nullable=False)
    revue_year_id = db.Column("revue_year_id",
                              db.Integer,
                              ForeignKey("general.revue_year.id"),
                              nullable=False)

    def __init__(self, page_id, year_group_id, revue_year_id):
        self.page_id = page_id
        self.year_group_id = year_group_id
        self.revue_year_id = revue_year_id
Esempio n. 27
0
class PersistentGroup(Group):
    __tablename__ = "persistent_group"
    __table_args__ = {"schema": "general"}
    persistent_group_id = db.Column("id",
                                    db.Integer,
                                    ForeignKey('general.group.id'),
                                    primary_key=True,
                                    nullable=False)
    parent_persistent_group_id = db.Column(
        db.Integer, ForeignKey("general.persistent_group.id"), nullable=True)
    listed = db.Column(db.Boolean, nullable=False, default=True)
    __mapper_args__ = {"polymorphic_identity": "persistent_group"}

    def mailing_list(self):
        return revue.models.mail.PersistentGroupMailingList.query.filter_by(
            persistent_group_id=self.persistent_group_id).one_or_none()

    def members(self):
        return [
            revue.models.general.User.query.get(pgp.user_id)
            for pgp in PersistentGroupParticipation.query.filter_by(
                group_id=self.id)
        ]
Esempio n. 28
0
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
Esempio n. 29
0
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)