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


Python DBSession.delete方法代码示例

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


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

示例1: client_activate

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import delete [as 别名]
def client_activate(request):
	if authenticated_userid(request):
		return HTTPSeeOther(location=request.route_url('access.cl.home'))
	did_fail = True
	cur_locale = locale_neg(request)
	cfg = request.registry.settings
	comb_js = asbool(cfg.get('netprofile.client.combine_js', False))
	can_reg = asbool(cfg.get('netprofile.client.registration.enabled', False))
	must_verify = asbool(cfg.get('netprofile.client.registration.verify_email', True))
	link_id = int(cfg.get('netprofile.client.registration.link_id', 1))
	rand_len = int(cfg.get('netprofile.client.registration.code_length', 20))
	if (not can_reg) or (not must_verify):
		return HTTPSeeOther(location=request.route_url('access.cl.login'))
	code = request.GET.get('code', '').strip().upper()
	login = request.GET.get('for', '')
	if code and login and (len(code) == rand_len):
		sess = DBSession()
		for link in sess.query(AccessEntityLink)\
				.options(joinedload(AccessEntityLink.entity))\
				.filter(AccessEntityLink.type_id == link_id, AccessEntityLink.value == code):
			# TODO: implement code timeouts
			ent = link.entity
			if (ent.access_state == AccessState.block_inactive.value) and (ent.nick == login):
				ent.access_state = AccessState.ok.value
				sess.delete(link)
				did_fail = False
				break
	tpldef = {
		'failed'         : did_fail,
		'comb_js'        : comb_js,
		'cur_loc'        : cur_locale
	}
	request.run_hook('access.cl.tpldef.activate', tpldef, request)
	return tpldef
开发者ID:baloon11,项目名称:npui,代码行数:36,代码来源:views.py

示例2: client_upload

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import delete [as 别名]
def client_upload(request):
	csrf = request.POST.get('csrf', '')
	mode = request.POST.get('mode', '')
	if not mode:
		raise HTTPForbidden('Invalid upload use')
	if csrf != request.get_csrf():
		raise HTTPForbidden('Error uploading file')
	sess = DBSession()
	# FIXME: add folder cfg
	tpldef = []
	for fo in request.POST.getall('files'):
		obj = File()
		if fo.filename:
			obj.name = obj.filename = fo.filename
		sess.add(obj)
		obj.set_from_file(fo.file, None, sess)
		signal = request.run_hook('access.cl.upload', obj, mode, request, sess, tpldef)
		if True not in signal:
			tpldef.append({
				'name'  : obj.filename,
				'size'  : obj.size,
				'error' : _('Error uploading file')
			})
			sess.delete(obj)
	tpldef = { 'files' : tpldef }
	request.run_hook('access.cl.tpldef.upload', tpldef, request)
	return tpldef
开发者ID:baloon11,项目名称:npui,代码行数:29,代码来源:views.py

示例3: ff_tree_delete

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import delete [as 别名]
def ff_tree_delete(params, request):
	sess = DBSession()
	user = request.user
	root_ff = user.group.effective_root_folder
	total = 0
	for rec in params.get('records', ()):
		ff_id = rec.get('id')
		if ff_id == 'root':
			continue
		ff_id = int(ff_id)
		ff = sess.query(FileFolder).get(ff_id)
		if ff is None:
			raise KeyError('Unknown folder ID %d' % ff_id)

		if root_ff and (not ff.is_inside(root_ff)):
			raise ValueError('Folder access denied')
		cur_parent = ff.parent
		if cur_parent and ((not cur_parent.can_write(user)) or (not cur_parent.can_traverse_path(user))):
			raise ValueError('Folder access denied')
		if (not cur_parent) and (not user.root_writable):
			raise ValueError('Folder access denied')

		# Extra precaution
		if ff.user != user:
			raise ValueError('Folder access denied')

		sess.delete(ff)
		total += 1
	return {
		'success' : True,
		'total'   : total
	}
开发者ID:hermes-jr,项目名称:npui,代码行数:34,代码来源:views.py

示例4: deleteMailBox

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

示例5: delete

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

示例6: dyn_usersettings_submit

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import delete [as 别名]
def dyn_usersettings_submit(param, request):
	"""
	ExtDirect method for submitting user settings form.
	"""

	sess = DBSession()
	mmgr = request.registry.getUtility(IModuleManager)
	cached = None
	if 'auth.settings' in request.session:
		cached = request.session['auth.settings']

	all_settings = mmgr.get_settings('user')
	values = dict(
		(s.name, s)
		for s
		in sess.query(UserSetting).filter(UserSetting.user == request.user)
	)

	for moddef, sections in all_settings.items():
		for sname, section in sections.items():
			if section.read_cap and not request.has_permission(section.read_cap):
				continue
			for setting_name, setting in section.items():
				if setting.read_cap and not request.has_permission(setting.read_cap):
					continue
				if setting.write_cap and not request.has_permission(setting.write_cap):
					continue
				fullname = '%s.%s.%s' % (moddef, sname, setting_name)
				old_value = setting.default
				if fullname in values:
					old_value = setting.parse_param(values[fullname].value)
				new_value = old_value
				if fullname in param:
					new_value = setting.parse_param(param[fullname])

				if new_value == setting.default:
					if fullname in values:
						sess.delete(values[fullname])
						del values[fullname]
					if cached:
						cached[fullname] = setting.default
					continue
				if new_value != old_value:
					if fullname in values:
						values[fullname].value = setting.format_param(new_value)
					else:
						values[fullname] = UserSetting(
							user=request.user,
							name=fullname,
							value=setting.format_param(new_value)
						)
						sess.add(values[fullname])
					if cached:
						cached[fullname] = new_value

	if cached:
		request.session['auth.settings'] = cached
	return { 'success' : True }
开发者ID:annndrey,项目名称:npui,代码行数:60,代码来源:views.py

示例7: client_delete

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import delete [as 别名]
def client_delete(request):
	if ('mode' not in request.matchdict) or ('id' not in request.matchdict):
		return False
	mode = request.matchdict['mode']
	try:
		objid = int(request.matchdict['id'])
	except ValueError:
		return False
	sess = DBSession()
	ret = request.run_hook('access.cl.download', mode, objid, request, sess)
	for r in ret:
		if isinstance(r, File):
			sess.delete(r)
			return True
	return False
开发者ID:baloon11,项目名称:npui,代码行数:17,代码来源:views.py

示例8: _cal_events_delete

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import delete [as 别名]
def _cal_events_delete(params, req):
	if 'EventId' not in params:
		return
	evtype, evid = params['EventId'].split('-')
	if evtype != 'event':
		return
	evid = int(evid)
	sess = DBSession()
	ev = sess.query(Event).get(evid)
	if ev is None:
		return False
	if (not ev.calendar) or (not ev.calendar.can_write(req.user)):
		return False
	sess.delete(ev)
	return True
开发者ID:hermes-jr,项目名称:npui,代码行数:17,代码来源:views.py

示例9: unlock

# 需要导入模块: from netprofile.db.connection import DBSession [as 别名]
# 或者: from netprofile.db.connection.DBSession import delete [as 别名]
	def unlock(self):
		req = self.req
		ctx = req.context
		req.dav.user_acl(req, ctx, dprops.ACL_WRITE_CONTENT)

		token = req.headers.get('Lock-Token')
		if not token:
			raise dav.DAVBadRequestError('UNLOCK request must be accompanied by a valid lock token header.')
		path = req.dav.ctx_path(ctx)
		if token[0] != '<':
			token = '<%s>' % (token,)
		locks = req.dav.get_locks(path)
		for lock in locks:
			token_str = '<opaquelocktoken:%s>' % (lock.token,)
			if token == token_str:
				sess = DBSession()
				sess.delete(lock)
				return dav.DAVUnlockResponse(request=req)
		raise dav.DAVLockTokenMatchError('Invalid lock token supplied.')
开发者ID:annndrey,项目名称:npui,代码行数:21,代码来源:dav.py


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