def get(self): for i in range(2, 200): add_data = pt_bs_msg( bednum=str(i), name=str(i), gender=str(i), age=i, contact=str(i), doctor=str(i), IDcard=str(i), ill=str(i), ) dbSession.add(add_data) dbSession.commit()
from config import settings from handlers.main.main_urls import handlers from models.account.account_user_model import User from models.files.upload_file_model import Files from models.article import article_model from libs.db import create_talbes from libs.db.dbsession import dbSession #定义一个默认的端口 define("port", default=8000, help="run port ", type=int) define("runserver", default=False, help="start server", type=bool) define("t", default=False, help="create table", type=bool) define("u", default=False, help="create user", type=bool) if __name__ == "__main__": options.parse_command_line() if options.t: create_talbes.run() if options.u: user = User() user.name = 'zhangsan' user.password = '******' dbSession.add(user) dbSession.commit() if options.runserver: app = tornado.web.Application(handlers, **settings) #创建应用实例 http_server = tornado.httpserver.HTTPServer(app) #通过应用实例创建服务器实例 http_server.listen(options.port) #监听9000端口 print 'start server...' tornado.ioloop.IOLoop.instance().start() #启动服务器
define("port", default=8000, help="run port ", type=int) # 定义端口号 define("runserver", default=False, help="start server", type=bool) # 启动服务 define("t", default=False, help="create table", type=bool) # 创建表 define("u", default=False, help="create user", type=bool) # 创建用户 if __name__ == "__main__": # option(所有已定义的选项都可以作为该对象的属性可用).解析在命令行上给出的所有选项 # 即在命令行输入命令时进行解析 options.parse_command_line() # 当是属性.t时,执行创建表函数 if options.t: create_talbes.run() # 调用创建数据库的映射函数生成数据库中的表 # 当是属性.u时,就是创建用户命令 # 定义如果执行-u时,为创建一个用户 if options.u: user = User() # 类的实例化 user.name = 'achjiang' # 属性的实例化 user.password = '******' # 属性的实例化 dbSession.add(user) # 在session中添加一个数据 dbSession.commit() # 将添加的数据提交到数据库执行 # 当是属性.runserver时,执行如下函数: if options.runserver: app = tornado.web.Application(handlers, **settings) #创建应用实例 http_server = tornado.httpserver.HTTPServer(app) #通过应用实例创建服务器实例 http_server.listen(options.port) #监听8000端口 print 'start server...' tornado.ioloop.IOLoop.instance().start() #启动服务器
def create_super_admin(): emp = Employee() emp.username = "******" emp.password = '******' dbSession.add(emp) dbSession.commit()
def init_data(): """往permission_role表中添加admin这个角色""" role = permission_model.Role() role.name = 'admin' dbSession.add(role) dbSession.commit() """添加权限""" for i in range(13): pa = permission_model.Permission() pa.name = pp[i][0] pa.strcode = pp[i][1] dbSession.add(pa) dbSession.commit() """添加管理员用户""" u = [ ('admin', '111111'), ] for i in xrange(1): user = User() user.name = u[i][0] user.password = u[i][1] dbSession.add(user) dbSession.commit() """为处理器添加权限""" for i in xrange(11): user = permission_model.Handler() user.name = h[i][0] user.p_id = h[i][1] dbSession.add(user) dbSession.commit() p = dbSession.query(permission_model.Permission).all() r = dbSession.query(permission_model.Role).filter_by(name='admin').first() for i in p: r.permissions.append(i) dbSession.add(r) dbSession.commit() """给admin用户赋予角色""" u_r = ["1", "1"] user_to_role = permission_model.UserToRole() user_to_role.u_id = u_r[0] user_to_role.r_id = u_r[1] dbSession.add(user_to_role) dbSession.commit() """给admin添加权限管理菜单显示""" p_r = ["adminmenu", "7"] menu = permission_model.Menu() menu.name = p_r[0] menu.p_id = p_r[1] dbSession.add(menu) dbSession.commit()