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


Python DBSession.flush方法代码示例

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


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

示例1: deleteMailBox

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import flush [as 别名]
def deleteMailBox(request):
	loc = get_localizer(request)
	cfg = request.registry.settings
	sess = DBSession()
	errmess = None
	csrf = request.POST.get('csrf', '')
	access_user = sess.query(AccessEntity).filter_by(nick=str(request.user)).first()
	if csrf != request.get_csrf():
		request.session.flash({
				'text' : loc.translate(_('Error submitting form')),
				'class' : 'danger'
				})
		return HTTPSeeOther(location=request.route_url('postfix.cl.mail'), _query=(('error', 'asc'),))
	else:
		domainid = request.POST.get('domainid', None)
		mboxid = request.POST.get('mboxid', None)
		if mboxid:
			mbox = sess.query(PostfixMailbox).filter_by(id=int(mboxid)).first()
			if mbox.username == access_user.nick:
				sess.delete(mbox)
				sess.flush()
		elif domainid:
			domain = sess.query(PostfixDomain).filter_by(id=int(domainid)).first()
			domainadmins = sess.query(PostfixDomainAdmins).filter_by(domain=domain.domain)
			if access_user.nick in [adm.username for adm in domainadmins]:
				sess.delete(domain)
				sess.query(PostfixDomainAdmins).filter_by(domain=domain.domain).delete()
				sess.flush()

	return HTTPSeeOther(location=request.route_url('postfix.cl.mail'))
开发者ID:baloon11,项目名称:npui,代码行数:32,代码来源:views.py

示例2: delete

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import flush [as 别名]
	def delete(self, req, ctx, recurse=True, _flush=True):
		sess = DBSession()
		if recurse:
			for ch in self.children(ctx):
				self.delete(req, ch, recurse, False)
		sess.delete(ctx)
		if _flush:
			sess.flush()
开发者ID:baloon11,项目名称:npui,代码行数:10,代码来源:__init__.py

示例3: dyn_ticket_uwiz_update

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import flush [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

示例4: client_oauth_register

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import flush [as 别名]
def client_oauth_register(request, regdict):
	nxt = request.route_url('access.cl.home')
	loc = get_localizer(request)
	headers = None
	#if authenticated_userid(request):
	#	 return HTTPSeeOther(location=nxt)

	cfg = request.registry.settings
	rate_id = int(cfg.get('netprofile.client.registration.rate_id', 1))
	state_id = int(cfg.get('netprofile.client.registration.state_id', 1))

	errors = {}
	sess = DBSession()

	login = regdict.get('username', None)
	passwd = regdict.get('password', None)
	email = regdict.get('email', None)
	name_family = regdict.get('familyname', '')
	name_given = regdict.get('givenname', '')

	### !!!!! What if user changes his password in out database?!
	if login is not None and passwd is not None:
		q = sess.query(AccessEntity).filter(AccessEntity.nick == login, AccessEntity.access_state != AccessState.block_inactive.value)
		if q is not None:
			for user in q:
				if user.password == passwd:
					headers = remember(request, login)
					return headers

	if headers is None:
		ent = PhysicalEntity()
		ent.nick = login
		ent.email = email
		ent.name_family = name_family
		ent.name_given = name_given
		ent.state_id = state_id

		stash = Stash()
		stash.entity = ent
		stash.name = loc.translate(_('Primary Account'))

		acc = AccessEntity()
		acc.nick = login
		acc.password = passwd
		acc.stash = stash
		acc.rate_id = rate_id
		acc.state_id = state_id
		ent.children.append(acc)
		
		sess.add(ent)
		sess.add(stash)
		sess.add(acc)
		sess.flush()
		headers = remember(request, login)
		return headers

	else:
		return False
开发者ID:nikitos,项目名称:npui,代码行数:60,代码来源:views.py

示例5: make_collection

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import flush [as 别名]
	def make_collection(self, req, parent, name, rtype, props):
		sess = DBSession()
		creator = getattr(parent, 'dav_create', None)
		if (creator is None) or (not callable(creator)):
			raise DAVNotImplementedError('Unable to create child node.')
		obj = creator(req, name, rtype.types, props)
		if len(props) == 0:
			pset = set(dprops.DEFAULT_PROPS)
		else:
			pset = set(props.keys())
		sess.flush()
		obj.__parent__ = parent
		return (obj, self.get_node_props(req, obj, pset))
开发者ID:baloon11,项目名称:npui,代码行数:15,代码来源:__init__.py

示例6: ff_tree_create

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import flush [as 别名]
def ff_tree_create(params, request):
	recs = []
	sess = DBSession()
	user = request.user
	total = 0
	for rec in params.get('records', ()):
		ff_name = rec.get('text')
		ff_parent = rec.get('parentId')
		# TODO: support changing uid/gid and rights, maybe?
		if not ff_name:
			raise ValueError('Empty folder names are not supported')
		if ff_parent and (ff_parent != 'root'):
			ff_parent = int(ff_parent)
		else:
			ff_parent = None

		ff = FileFolder(user=user, group=user.group)
		ff.name = ff_name
		root_ff = user.group.effective_root_folder
		if root_ff and (ff_parent is None):
			raise ValueError('Folder access denied')
		if ff_parent:
			ffp = sess.query(FileFolder).get(ff_parent)
			if ffp is None:
				raise KeyError('Unknown parent folder ID %d' % ff_parent)
			if (not ffp.can_write(user)) or (not ffp.can_traverse_path(user)):
				raise ValueError('Folder access denied')
			if root_ff and (not ffp.is_inside(root_ff)):
				raise ValueError('Folder access denied')
			ff.parent = ffp
		elif not user.root_writable:
			raise ValueError('Folder access denied')

		sess.add(ff)
		sess.flush()
		recs.append({
			'id'             : str(ff.id),
			'parentId'       : str(ff.parent.id) if ff.parent else 'root',
			'text'           : ff.name,
			'xhandler'       : 'NetProfile.controller.FileBrowser',
			'allow_read'     : ff.can_read(user),
			'allow_write'    : ff.can_write(user),
			'allow_traverse' : ff.can_traverse(user),
			'parent_write'   : ff.parent.can_write(user) if ff.parent else user.root_writable
		})
		total += 1
	return {
		'success' : True,
		'records' : recs,
		'total'   : total
	}
开发者ID:hermes-jr,项目名称:npui,代码行数:53,代码来源:views.py

示例7: createMailBox

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import flush [as 别名]
def createMailBox(request):
	loc = get_localizer(request)
	cfg = request.registry.settings
	sess = DBSession()
	errmess = None
	csrf = request.POST.get('csrf', '')
	access_user = sess.query(AccessEntity).filter_by(nick=str(request.user)).first()
	admindomains = sess.query(PostfixDomainAdmins).filter_by(username=str(request.user))

	if csrf != request.get_csrf():
		request.session.flash({
				'text' : loc.translate(_('Error submitting form')),
				'class' : 'danger'
				})
		return HTTPSeeOther(location=request.route_url('postfix.cl.mail'))
	else:
		domain_name = request.POST.get('mbDomain', None)
		domain_descr = request.POST.get('mbDomainDescription', None)
		username = request.POST.get('mbUsername', None)
		mailbox_name = request.POST.get('mbName', None)
		mailbox_password = request.POST.get('mbPassword', None)
		if domain_name and username:
			if username == access_user.nick:
				if mailbox_name and mailbox_password:
					newmailbox = PostfixMailbox(
						username=username, 
						password=mailbox_password, 
						name=mailbox_name, 
						domain=domain_name
						)
					sess.add(newmailbox)
					sess.flush()
				else:
					if domain_name not in [ad.username for ad in admindomains]:
						newdomainadmin = PostfixDomainAdmins(username=username, domain=domain_name) 
						newdomain = PostfixDomain(domain=domain_name, description=domain_descr)
						sess.add(newdomainadmin)
						sess.add(newdomain)
						sess.flush()

	return HTTPSeeOther(location=request.route_url('postfix.cl.mail'))
开发者ID:baloon11,项目名称:npui,代码行数:43,代码来源:views.py

示例8: editMailBox

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import flush [as 别名]
def editMailBox(request):
	loc = get_localizer(request)
	cfg = request.registry.settings
	sess = DBSession()
	errmess = None
	csrf = request.POST.get('csrf', '')
	access_user = sess.query(AccessEntity).filter_by(nick=str(request.user)).first()
	
	if csrf != request.get_csrf():
		request.session.flash({
				'text' : loc.translate(_('Error submitting form')),
				'class' : 'danger'
				})
		return HTTPSeeOther(location=request.route_url('postfix.cl.mail'))
	else:
		#get vars
		domain_name = request.POST.get('mbDomain', None)
		domain_descr = request.POST.get('mbDomainDescription', None)
		username = request.POST.get('mbUsername', None)
		mailbox_name = request.POST.get('mbName', None)
		mailbox_id = request.POST.get('id', None)
		domain_id = request.POST.get('did', None)
		mailbox_password = request.POST.get('mbPassword', None)
		if username:
			if username == access_user.nick:
				if mailbox_name and mailbox_password:
					mailbox = sess.query(PostfixMailbox).filter_by(id=int(mailbox_id)).first()
					mailbox.name = mailbox_name
					mailbox.password = mailbox_password
					mailbox.domain = domain_name

				else:
					domain = sess.query(PostfixDomain).filter_by(id=domain_id).first()
					domain.description = domain_descr

				sess.flush()

	return HTTPSeeOther(location=request.route_url('postfix.cl.mail'))
开发者ID:baloon11,项目名称:npui,代码行数:40,代码来源:views.py

示例9: client_issue_new

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import flush [as 别名]
def client_issue_new(ctx, req):
	loc = req.localizer
	cfg = req.registry.settings
	if not asbool(cfg.get('netprofile.client.ticket.enabled', True)):
		raise HTTPForbidden(detail=_('Issues view is disabled'))
	origin_id = int(cfg.get('netprofile.client.ticket.origin_id', 0))
	user_id = int(cfg.get('netprofile.client.ticket.assign_uid', 0))
	group_id = int(cfg.get('netprofile.client.ticket.assign_gid', 0))
	errors = {}
	sess = DBSession()
	ent = req.user.parent
	states = sess.query(TicketState)\
		.filter(TicketState.is_start == True, TicketState.allow_client == True)
	if 'submit' in req.POST:
		csrf = req.POST.get('csrf', '')
		name = req.POST.get('name', '')
		descr = req.POST.get('descr', '')
		state = int(req.POST.get('state', 0))
		if csrf != req.get_csrf():
			errors['csrf'] = _a('Error submitting form')
		else:
			l = len(name)
			if (l == 0) or (l > 254):
				errors['name'] = _a('Invalid field length')
			for s in states:
				if s.id == state:
					state = s
					break
			else:
				errors['state'] = _('Invalid issue type')
		if len(errors) == 0:
			tkt = Ticket()
			tkt.name = name
			tkt.state = state
			tkt.entity = ent
			tkt.show_client = True
			if descr:
				tkt.description = descr
			if origin_id:
				tkt.origin_id = origin_id
			if user_id:
				tkt.assigned_user_id = user_id
			if group_id:
				tkt.assigned_group_id = group_id
			sess.add(tkt)
			sess.flush()

			req.session.flash({
				'text' : loc.translate(_('New issue successfully created'))
			})
			return HTTPSeeOther(location=req.route_url('tickets.cl.issues', traverse=(tkt.id, 'view')))
	tpldef = {
		'states' : states,
		'crumbs' : [{
			'text' : loc.translate(_('My Issues')),
			'url'  : req.route_url('tickets.cl.issues', traverse=())
		}, {
			'text' : loc.translate(_('New Issue'))
		}],
		'errors' : {err: loc.translate(errors[err]) for err in errors}
	}
	req.run_hook('access.cl.tpldef', tpldef, req)
	req.run_hook('access.cl.tpldef.issue.new', tpldef, req)
	return tpldef
开发者ID:annndrey,项目名称:npui,代码行数:66,代码来源:views.py

示例10: create_record

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import flush [as 别名]
def create_record(request):
	loc = get_localizer(request)
	cfg = request.registry.settings
	sess = DBSession()
	csrf = request.POST.get('csrf', '')
	if csrf != request.get_csrf():
		request.session.flash({
				'text' : loc.translate(_('Error submitting form')),
				'class' : 'danger'
				})
		return HTTPSeeOther(location=request.route_url('pdns.cl.domains'))
	else:
		rectype = request.POST.get('type', None)
		if rectype == "domain":
			name = request.POST.get('hostName', None)
			domain_clash = sess.query(func.count('*'))\
					.select_from(PDNSDomain)\
					.filter(PDNSDomain.name == name)\
					.scalar()
			if domain_clash > 0:
				request.session.flash({
					'text' : loc.translate(_('Domain already exists')),
					'class' : 'danger'
					})
				return HTTPSeeOther(location=request.route_url('pdns.cl.domains'))
			ns1 = cfg.get('netprofile.client.pdns.ns1')
			ns2 = cfg.get('netprofile.client.pdns.ns2')
			newdomain = PDNSDomain(name=name, master='', dtype='NATIVE', account=request.POST.get('user', None))

			newsoa = PDNSRecord()
			newsoa.domain = newdomain
			newsoa.name = name
			newsoa.rtype = 'SOA'
			newsoa.content = ns1
			newsoa.ttl = 86400

			newns1 = PDNSRecord()
			newns1.domain = newdomain
			newns1.name = name
			newns1.rtype = 'NS'
			newns1.content = ns1
			newns1.ttl = 86400

			newns2 = PDNSRecord()
			newns2.domain = newdomain
			newns2.name = name
			newns2.rtype = 'NS'
			newns2.content = ns2
			newns2.ttl = 86400

			sess.add(newdomain)
			sess.add(newsoa)
			sess.add(newns1)
			sess.add(newns2)

			sess.flush()
		elif rectype == "record":
			ttl = None if request.POST.get('ttl', None) == '' else request.POST.get('ttl', None);
			prio = None if request.POST.get('prio', None) == '' else request.POST.get('prio', None);
			newrecord = PDNSRecord(domain_id=int(request.POST.get('domainid', None)), name=request.POST.get('name', None), rtype=request.POST.get('rtype', None), content=request.POST.get('content', None), ttl=ttl, prio=prio)
			sess.add(newrecord)
			sess.flush()
		
	return HTTPSeeOther(location=request.route_url('pdns.cl.domains', _query=(('created', 1),)))
开发者ID:baloon11,项目名称:npui,代码行数:66,代码来源:views.py

示例11: _wizcb_submit_hdl

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import flush [as 别名]
	def _wizcb_submit_hdl(wiz, em, step, act, val, req):
		xcls = cls
		if isinstance(xcls, str):
			xcls = _name_to_class(xcls)

		sess = DBSession()
		cfg = get_current_registry().settings
		mailer = get_mailer(req)

		userIDs = json.loads(val['userid'])
		userlist = val['user']
		templateName = val['template']
		templId = val['templid']
		receiver = None
		sender = cfg.get('netprofile.mailing.sender', '[email protected]mysite.com')
		sendername = cfg.get('sender.name', 'localadmin')
		mailhost = cfg.get('mail.host', 'localhost')

		for userid in userIDs:
			resvalue = {'userid' : userid}
			user = sess.query(AccessEntity).filter(AccessEntity.id==userid).first()
			subscr = sess.query(MailingSubscription).filter(MailingSubscription.userid==userid).first()
		
    		#a long try-except statement to check if user is in mailing list
			try:
				if subscr.issubscribed is True:
					templateBody = sess.query(MailingTemplate).filter(MailingTemplate.id==templId).first().body
					resvalue['user'] = user
					resvalue['template'] = templateBody
					resvalue['templid'] = templId
		
					if user.parent:
						try:
							receiver = user.parent.email
						except AttributeError:
							#raise error here
							print("################### USER'S PARENT HAVE NO EMAIL ATTRIBUTE #######################")
	
					if receiver is not None:
						msg_text = Attachment(data=templateBody,
											  content_type='text/plain; charset=\'utf-8\'',
											  disposition='inline',
											  transfer_encoding='quoted-printable'
											  )
						msg_html = Attachment(data=templateBody,
											  content_type='text/html; charset=\'utf-8\'',
											  disposition='inline',
											  transfer_encoding='quoted-printable'
											  )
						message = Message(
							subject=(templateName),
							sender=sender,
							recipients=(receiver,),
							body=msg_text,
							html=msg_html
							)

						mailer.send(message)
						resvalue['letteruid'] = hashlib.md5((templateBody + user.nick + str(datetime.datetime.now())).encode()).hexdigest()
						em = ExtModel(xcls)
						obj = xcls()
						em.set_values(obj, resvalue, req, True)
						sess.add(obj)
						sess.flush()
					else:
						print("################### USER HAVE NO EMAIL #######################")

			except AttributeError:
				print("########################## USER NOT IN SUBSCR LIST ###########################")

		return {
			'do'     : 'close',
			'reload' : True
			}
开发者ID:nikitos,项目名称:npui,代码行数:76,代码来源:models.py


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