Пример #1
0
class Menu(db.Model):
    __tablename__='menus'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True, nullable=False)
    html_class = db.Column(db.String(255), nullable=False, default='')
    html_style = db.Column(db.String(255), nullable=False, default='')

    items = db.relationship('MenuItem', back_populates='menu') 
Пример #2
0
class Role(db.Model, RestrictionsMixin, PhotoricMixin):
    __tablename__ = 'roles'

    __restrictions__ = {}

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False, unique=True)

    _users = db.relationship('User', secondary=UserRole)

    @hybrid_property
    def users(self):
        return self._users

    @users.setter
    def users(self, users):
        for user in users:
            existing_user = User.get_by_name(name=user["name"])
            if existing_user:
                self._users.append(existing_user)
            else:
                return {
                    "message":
                    "User is not exists. Role can be assigned to existing user(-s) only"
                }, 404

    def __repr__(self):
        return '<Role %r>' % self.name
Пример #3
0
class Group(db.Model, AllowancesMixin, PhotoricMixin):
    __tablename__ = 'groups'

    __allowances__ = {}

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False, unique=True)

    _users = db.relationship('User', secondary=UserGroup)

    @hybrid_property
    def users(self):
        return self._users

    @users.setter
    def users(self, users):
        for user in users:
            existing_user = User.get_by_name(name=user["name"])
            if existing_user:
                self._users.append(existing_user)
            else:
                return {
                    "message":
                    "User does not exist. Only existing user(-s) can be included in a group"
                }, 404

    def __repr__(self):
        return '<Group %r>' % self.name
Пример #4
0
class Album(db.Model, PermissionsMixin):
    __tablename__ = "albums"

    __user_model__ = User
    __permissions__ = dict(
        owner=['create', 'read', 'update', 'delete', 'revoke'],
        group=['read', 'update', 'revoke'],
        other=['read']
    )

    id = db.Column(db.Integer, primary_key=True)
    parent_id = db.Column(db.Integer, db.ForeignKey('albums.id'))
    name = db.Column(db.String(100), unique=True, nullable=False)
    description = db.Column(db.String(500), nullable=True)
    keywords = db.Column(db.String(255), nullable=True)
    icon_id = db.Column(db.Integer, nullable=True)
    created_on = db.Column(db.DateTime, nullable=False, default=datetime.now)
    is_published = db.Column(db.Boolean(), nullable=False, default=False)
    published_on = db.Column(db.DateTime, nullable=True, index=True)
    children_images = db.relationship(
        'Image',
        secondary=AlbumImage,
        back_populates='parent_albums'
    )
    children_albums = db.relationship(
        'Album', backref=backref('parent',
        remote_side=[id])
    )

    def publish(self):
        # mark gallery item as published, i.e. accessible for both registered and anonymous users
        self.is_published = True
        self.published_on = datetime.utcnow

    def unpublish(self):
        # mark gallery item as not published, i.e. accessible for both registered and anonymous users
        self.is_published = False

    def __repr__(self):
        return '<Album %r>' % self.name
Пример #5
0
class MenuItem(db.Model):
    __tablename__='menu_items'
    
    id = db.Column(db.Integer, primary_key=True)
    menu_id = db.Column(db.Integer, db.ForeignKey('menus.id'))
    parent_id = db.Column(db.Integer, db.ForeignKey('menu_items.id'))
    item_type = db.Column(db.String(20), default='plain')
    name = db.Column(db.String(100), nullable=False, unique=True)
    desc = db.Column(db.String(255), nullable=False)
    item_target = db.Column(db.String(255), nullable=True)
    icon_type = db.Column(db.String(50), nullable=True)
    icon_src = db.Column(db.String(255), nullable=True)
    visible = db.Column(db.Boolean, nullable=False, default=True)
    anonym_only = db.Column(db.Boolean, nullable=False, default=False)
    auth_req = db.Column(db.Boolean, nullable=False, default=False)
    group_req = db.Column(db.String(100), nullable=True)
    role_req = db.Column(db.String(100), nullable=True)

    menu = db.relationship('Menu', back_populates='items')
    children = db.relationship('MenuItem')
Пример #6
0
class NavbarItem(db.Model):
    __tablename__='navbar_items'

    id = db.Column(db.Integer, primary_key=True)
    navbar_id = db.Column(db.Integer, db.ForeignKey('navbars.id'))
    name = db.Column(db.String(100), unique=True, nullable=False)
    item_type = db.Column(db.String(100), nullable=False)
    item_target = db.Column(db.String(255), nullable=True)
    icon_type = db.Column(db.String(50), nullable=True)
    icon_src = db.Column(db.String(255), nullable=True)
    visible = db.Column(db.Boolean, nullable=False, default=True)
    anonym_only = db.Column(db.Boolean, nullable=False, default=False)
    auth_req = db.Column(db.Boolean, nullable=False, default=False)
    group_req = db.Column(db.String(100), nullable=True)
    role_req = db.Column(db.String(100), nullable=True)

    item_src = db.column_property('/' + item_type + '/' + name + '.html')
    
    navbar = db.relationship('Navbar', back_populates='items')