当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.execute方法代码示例

本文整理汇总了Python中netprofile.db.connection.DBSession.execute方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.execute方法的具体用法?Python DBSession.execute怎么用?Python DBSession.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在netprofile.db.connection.DBSession的用法示例。


在下文中一共展示了DBSession.execute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import execute [as 别名]
def main(argv=sys.argv):
	if len(argv) != 2:
		usage(argv)
	config_uri = argv[1]
	setup_logging(config_uri)
	settings = get_appsettings(config_uri)
	config = setup_config(settings)

	reg = threadlocal.get_current_registry()

	factory = pyramid_mako.MakoRendererFactory()

	name_resolver = DottedNameResolver()
	lookup_opts = pyramid_mako.parse_options_from_settings(settings, 'mako.', name_resolver.maybe_resolve)
	lookup_opts.update({
		'default_filters' : ['context[\'self\'].ddl.ddl_fmt']
	})
	factory.lookup = pyramid_mako.PkgResourceTemplateLookup(**lookup_opts)

	reg.registerUtility(factory, IRendererFactory, name='.mak')

	sess = DBSession()
	mm = ModuleManager(config)

	sess.execute(SetVariable('accessuid', 0))
	sess.execute(SetVariable('accessgid', 0))
	sess.execute(SetVariable('accesslogin', '[CREATEDB]'))

	mm.scan()
	mm.install('core', sess)
	for moddef in mm.modules:
		if moddef != 'core':
			mm.install(moddef, sess)
开发者ID:baloon11,项目名称:npui,代码行数:35,代码来源:createdb.py

示例2: _cal_events_update

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import execute [as 别名]
def _cal_events_update(params, req):
	cal_id = params.get('CalendarId', '')
	if cal_id != _cal['id']:
		return
	if 'EventId' not in params:
		return
	evtype, evid = params['EventId'].split('-')
	if evtype != 'ticket':
		return
	evid = int(evid)
	if not has_permission('TICKETS_UPDATE', req.context, req):
		return
	sess = DBSession()
	tkt = sess.query(Ticket).get(evid)
	if tkt is None:
		return
	sess.execute(SetVariable('ticketid', tkt.id))
	if 'StartDate' in params:
		new_ts = dparse(params['StartDate']).replace(tzinfo=None, microsecond=0)
		if new_ts:
			tkt.assigned_time = new_ts
	if ('EndDate' in params) and tkt.assigned_time:
		new_ts = dparse(params['EndDate']).replace(tzinfo=None, microsecond=0)
		if new_ts:
			delta = new_ts - tkt.assigned_time
			tkt.duration = delta.seconds
开发者ID:baloon11,项目名称:npui,代码行数:28,代码来源:views.py

示例3: _auth_to_db

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import execute [as 别名]
def _auth_to_db(event):
	request = event.request

	if not request.matched_route:
		return
	rname = request.matched_route.name
	if rname[0] == '_':
		return

	sess = DBSession()
	user = request.user

	db_vars = {
		'accessuid'   : 0,
		'accessgid'   : 0,
		'accesslogin' : '[XOP:%s]' % (user.name,) if user else '[XOP:GUEST]'
	}
	try:
		sess.execute(SetVariables(**db_vars))
	except NotImplementedError:
		for vname in db_vars:
			sess.execute(SetVariable(vname, db_vars[vname]))
开发者ID:annndrey,项目名称:npui,代码行数:24,代码来源:auth.py

示例4: _auth_to_db

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import execute [as 别名]
def _auth_to_db(event):
	request = event.request

	if not request.matched_route:
		return
	rname = request.matched_route.name
	if rname[0] == '_':
		return
	if request.method == 'OPTIONS':
		return

	sess = DBSession()
	user = request.user

	if user:
		sess.execute(SetVariable('accessuid', user.id))
		sess.execute(SetVariable('accessgid', user.group_id))
		sess.execute(SetVariable('accesslogin', user.login))

		skey = request.registry.settings.get('redis.sessions.cookie_name')
		if not skey:
			skey = request.registry.settings.get('session.key')
		assert skey is not None, 'Session cookie name does not exist'
		sname = request.cookies.get(skey)
		if sname:
			try:
				npsess = sess.query(NPSession).filter(NPSession.session_name == sname).one()
				npsess.update_time()
			except NoResultFound:
				npsess = user.generate_session(request, sname)
				sess.add(npsess)
			request.np_session = npsess
	else:
		sess.execute(SetVariable('accessuid', 0))
		sess.execute(SetVariable('accessgid', 0))
		sess.execute(SetVariable('accesslogin', '[GUEST]'))
开发者ID:baloon11,项目名称:npui,代码行数:38,代码来源:auth.py

示例5: _auth_to_db

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import execute [as 别名]
def _auth_to_db(event):
	request = event.request

	if not request.matched_route:
		return
	rname = request.matched_route.name
	if rname[0] == '_':
		return

	sess = DBSession()
	user = request.user

	sess.execute(SetVariable('accessuid', 0))
	sess.execute(SetVariable('accessgid', 0))
	if user:
		sess.execute(SetVariable('accesslogin', '[ACCESS:%s]' % user.nick))
	else:
		sess.execute(SetVariable('accesslogin', '[ACCESS:GUEST]'))
开发者ID:baloon11,项目名称:npui,代码行数:20,代码来源:auth.py

示例6: db_session

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import execute [as 别名]
	def db_session(self):
		sess = DBSession()
		sess.execute(SetVariable('accessuid', 0))
		sess.execute(SetVariable('accessgid', 0))
		sess.execute(SetVariable('accesslogin', '[NPCTL]'))
		return sess
开发者ID:hermes-jr,项目名称:npui,代码行数:8,代码来源:ctl.py

示例7: _auth_to_db

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import execute [as 别名]
def _auth_to_db(event):
    request = event.request

    if not request.matched_route:
        return
    rname = request.matched_route.name
    if rname[0] == '_':
        return
    if request.method == 'OPTIONS':
        return

    sess = DBSession()
    user = request.user

    if user:
        try:
            sess.execute(SetVariables(accessuid=user.id,
                                      accessgid=user.group_id,
                                      accesslogin=user.login))
        except NotImplementedError:
            sess.execute(SetVariable('accessuid', user.id))
            sess.execute(SetVariable('accessgid', user.group_id))
            sess.execute(SetVariable('accesslogin', user.login))
    else:
        try:
            sess.execute(SetVariables(accessuid=0,
                                      accessgid=0,
                                      accesslogin='[GUEST]'))
        except NotImplementedError:
            sess.execute(SetVariable('accessuid', 0))
            sess.execute(SetVariable('accessgid', 0))
            sess.execute(SetVariable('accesslogin', '[GUEST]'))
开发者ID:unikmhz,项目名称:npui,代码行数:34,代码来源:auth.py

示例8: dyn_ticket_uwiz_update

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import execute [as 别名]
def dyn_ticket_uwiz_update(params, request):
	tid = int(params['ticketid'])
	del params['ticketid']
	sess = DBSession()
	model = ExtModel(Ticket)
	ticket = sess.query(Ticket).get(tid)
	if ticket is None:
		raise KeyError('Invalid ticket ID')

	for param in ('tstid', 'toid', 'name', 'descr'):
		if param in params:
			del params[param]

#	TODO: ENTITIES_LIST
	if not request.has_permission('TICKETS_CHANGE_STATE'):
		if 'ttrid' in params:
			del params['ttrid']
	if not request.has_permission('TICKETS_CHANGE_FLAGS'):
		if 'flags' in params:
			del params['flags']
#	TODO: USERS_LIST
#	TODO: GROUPS_LIST

	sess.execute(SetVariable('ticketid', ticket.id))
	if 'ttrid' in params:
		ttr_id = params['ttrid']
		if ttr_id:
			ttr_id = int(ttr_id)
			trans = sess.query(TicketStateTransition).get(ttr_id)
			if trans:
				sess.execute(SetVariable('ttrid', trans.id))
				trans.apply(ticket)
		del params['ttrid']
	if 'show_client' in params:
		show_cl = params['show_client'].lower()
		if show_cl in {'true', '1', 'on'}:
			show_cl = True
		else:
			show_cl = False
		del params['show_client']
	else:
		show_cl = False
	sess.execute(SetVariable('show_client', npbool(show_cl)))
	if ('comments' in params) and request.has_permission('TICKETS_COMMENT', request.context, request):
		sess.execute(SetVariable('comments', params['comments']))
		del params['comments']
	else:
		sess.execute(SetVariable('comments', None))
	model.set_values(ticket, params, request)
	sess.flush()
	sess.execute(SetVariable('tcid', None))
	return {
		'success' : True,
		'action'  : {
			'do'     : 'close',
			'redraw' : []
		}
	}
开发者ID:annndrey,项目名称:npui,代码行数:60,代码来源:views.py


注:本文中的netprofile.db.connection.DBSession.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。