old gnuviechadmin web interface code that is not developed anymore
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

64 lines
2.1 KiB

# -*- python -*-
# -*- coding: utf-8 -*-
import sqlalchemy as sa
from sqlalchemy import orm
from gnuviechadminweb.model import meta
t_menu = \
sa.Table("menu", meta.metadata,
sa.Column("id", sa.types.Integer, primary_key=True),
sa.Column("title", sa.types.String(40), nullable=False),
sa.Column("controller", sa.types.String(40), nullable=False),
sa.Column("action", sa.types.String(40), nullable=False)
)
t_user = \
sa.Table("user", meta.metadata,
sa.Column("id", sa.types.Integer, primary_key=True),
sa.Column("name", sa.types.String(40), nullable=False),
sa.Column("password", sa.types.String(128), nullable=False)
)
t_role = \
sa.Table("role", meta.metadata,
sa.Column("id", sa.types.Integer, primary_key=True),
sa.Column("name", sa.types.String(40), nullable=False)
)
t_menu_role = \
sa.Table("menu_role", meta.metadata,
sa.Column("id", sa.types.Integer, primary_key=True),
sa.Column("menu_id", sa.types.Integer, sa.ForeignKey(t_menu.c.id)),
sa.Column("role_id", sa.types.Integer, sa.ForeignKey(t_role.c.id))
)
t_user_role = \
sa.Table("user_role", meta.metadata,
sa.Column("id", sa.types.Integer, primary_key=True),
sa.Column("user_id", sa.types.Integer, sa.ForeignKey(t_user.c.id)),
sa.Column("role_id", sa.types.Integer, sa.ForeignKey(t_role.c.id))
)
class Menu(object):
@classmethod
def allowed(cls, user=None):
menu_q = meta.Session.query(cls)
return menu_q.all()
class User(object):
pass
class Role(object):
pass
orm.mapper(Menu, t_menu, {
'roles' : orm.relation(Role, secondary = t_menu_role),
})
orm.mapper(Role, t_role, properties = {
'users' : orm.relation(User, secondary = t_user_role),
'menus' : orm.relation(Menu, secondary = t_menu_role),
})
orm.mapper(User, t_role, properties = {
'roles' : orm.relation(User, secondary = t_user_role)
})